forked from bbc/simorgh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.server.js
49 lines (46 loc) · 1.35 KB
/
webpack.config.server.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
/* eslint-disable global-require */
const nodeExternals = require('webpack-node-externals');
const webpack = require('webpack');
module.exports = ({ resolvePath, START_DEV_SERVER }) => {
const serverConfig = {
target: 'node', // compile for server environment
entry: START_DEV_SERVER ? ['webpack/hot/poll?100', './src'] : ['./src'],
output: {
path: resolvePath('build'),
filename: 'server.js',
},
externals: [
/**
* Prevents `node_modules` from being bundled into the server.js
* And therefore stops `node_modules` being watched for file changes
*/
nodeExternals({
whitelist: ['webpack/hot/poll?100'],
}),
],
watch: true,
node: {
/**
* Override webpacks default handling of __dirname
* which replaces it with '/'.
*/
__dirname: false,
},
plugins: [
/**
* Limit chunks to 1 to avoid unnecessary service bundle splitting
*/
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
],
};
if (START_DEV_SERVER) {
const StartServerPlugin = require('start-server-webpack-plugin');
serverConfig.plugins = [
new webpack.HotModuleReplacementPlugin(),
new StartServerPlugin('server.js'), // only start the server if we've run `npm run dev`
];
}
return serverConfig;
};