-
Notifications
You must be signed in to change notification settings - Fork 229
/
webpack.config.server.js
60 lines (56 loc) · 1.67 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
50
51
52
53
54
55
56
57
58
59
60
/* eslint-disable global-require */
const nodeExternals = require('webpack-node-externals');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
module.exports = ({ resolvePath, START_DEV_SERVER }) => {
const serverConfig = {
target: 'node', // compile for server environment
entry: START_DEV_SERVER ? ['webpack/hot/poll?100', './src'] : ['./src'],
devtool: START_DEV_SERVER ? 'source-map' : false,
output: {
path: resolvePath('build'),
filename: 'server.js',
},
optimization: {
minimize: false,
},
externals: [
/**
* Prevents `node_modules` from being bundled into the server.js
* And therefore stops `node_modules` being watched for file changes
*/
nodeExternals({
allowlist: ['webpack/hot/poll?100'],
}),
],
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-nestjs-webpack-plugin');
serverConfig.plugins = [
new webpack.HotModuleReplacementPlugin(),
new StartServerPlugin('server.js'), // only start the server if we've run `yarn dev`
new CopyPlugin({
patterns: [
{ from: 'public/sw.js', to: 'public/sw.js' },
{ from: 'public/favicon.ico', to: 'public/favicon.ico' },
],
}),
];
}
return serverConfig;
};