-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
67 lines (64 loc) · 1.75 KB
/
webpack.config.babel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { HotModuleReplacementPlugin, NamedModulesPlugin } from 'webpack';
import { join, relative } from 'path';
import nodeExternals from 'webpack-node-externals';
import WriteFilePlugin from 'write-file-webpack-plugin';
const webpackHotModule = 'webpack/hot/poll?1000';
export default (env, argv) => {
const DEVELOPMENT = argv.mode === 'development';
return ['web', 'node'].map(target => ({
target,
mode: argv.mode,
entry: {
[target]: {
node: [
...(DEVELOPMENT ? [webpackHotModule] : []),
join(__dirname, './src/server/index'),
],
web: join(__dirname, './src/client'),
}[target],
},
output: {
path: join(__dirname, 'dist', target),
filename: '[name].js',
publicPath: '/',
libraryTarget: target === 'node' ? 'commonjs' : 'var',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
},
},
],
},
plugins: [
...(DEVELOPMENT ? [
new NamedModulesPlugin(),
new HotModuleReplacementPlugin(),
] : []),
// If target node then write to disk
...(target === 'node' ? [new WriteFilePlugin()] : []),
],
externals: [
...(target === 'node' ? [nodeExternals({ whitelist: [webpackHotModule] })] : []),
],
devServer: {
contentBase: false,
hot: true,
after: (app) => {
let once = true;
app.use((req, res, next) => {
if (once) {
// Wait until first build and then use ssr middleware
app.use(require('./dist/node/node').default)
once = false;
}
next();
});
},
},
}));
};