-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwebpack.server.babel.js
73 lines (63 loc) · 1.81 KB
/
webpack.server.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
68
69
70
71
72
73
/* eslint import/no-extraneous-dependencies: ["error", {"peerDependencies": true}] */
import webpack from 'webpack';
import path from 'path';
import nodeExternals from 'webpack-node-externals';
import baseConfig, { eslintLoaderExtraRules } from './webpack.base';
export default function serverConfig(env) {
const config = baseConfig('server', env);
config.name = 'server';
// mode since webpack v4
config.mode = env === 'prod' ? 'production' : 'development';
config.output = {
path: path.join(__dirname, '/dist/server'),
publicPath: env === 'hot' ? '/' : '/assets/',
filename: 'index.js',
};
config.target = 'node';
config.externals = [nodeExternals()]; // in order to ignore all modules in node_modules folder
config.module.rules.push(
{
test: /\.js$/,
include: [
path.resolve(__dirname, 'src'),
],
use: [
{
loader: 'babel-loader',
options: {
plugins: [
'@babel/plugin-transform-runtime', // async/await
],
},
},
{
loader: 'eslint-loader',
options: {
// if env is 'hot'
// disable some eslint rules
rules: env === 'hot' ? eslintLoaderExtraRules : {},
},
},
],
},
);
if (env === 'hot') {
config.entry = {
server: path.resolve(__dirname, 'src/server/renderer'),
};
// webpack-hot-server-middleware needs this setting
config.output.libraryTarget = 'commonjs2';
} else {
config.entry = {
server: path.resolve(__dirname, 'src/server'),
};
}
if (env === 'prod') {
config.plugins.push(new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
}));
} else {
config.devtool = 'cheap-module-eval-source-map';
}
return config;
}