-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
86 lines (79 loc) · 2.23 KB
/
webpack.config.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
74
75
76
77
78
79
80
81
82
83
84
85
86
const path = require('path');
const process = require('process');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const isProduction = process.env.NODE_ENV === 'production';
const sharedPlugins = [new ExtractTextPlugin('styles.css')];
const clientPlugins = sharedPlugins.concat(isProduction ? [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
new UglifyJsPlugin({
parallel: true,
}),
new BundleAnalyzerPlugin(),
] : []);
const serverPlugins = sharedPlugins;
const modulesRules = [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.css$/,
exclude: /node_modules/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader?modules&localIdentName=[name]-[local]_[hash:base64:3]',
}),
},
];
const client = {
mode: 'development',
target: 'web',
devtool: 'source-map',
entry: {
bundle: ['babel-polyfill', './src/client/index.js'],
serviceWorker: './src/client/serviceWorker.js',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
module: {
rules: modulesRules,
},
// Webpack 4 doesn't use commonChunksPlugin anymore:
// https://gist.github.com/sokra/1522d586b8e5c0f5072d7565c2bee693
optimization: {
splitChunks: {
cacheGroups: {
lib: {
test: /[\\/]node_modules[\\/]/,
name: 'lib',
chunks: 'all',
filename: '[name]-bundle.js',
},
},
},
},
plugins: clientPlugins,
};
const server = {
mode: 'development',
target: 'node',
entry: ['./src/server/index.js'],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'server.js',
libraryTarget: 'commonjs2',
},
module: {
rules: modulesRules,
},
plugins: serverPlugins,
};
module.exports = [client, server];