-
Notifications
You must be signed in to change notification settings - Fork 28
/
webpack.prod.js
104 lines (99 loc) · 2.39 KB
/
webpack.prod.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const path = require('path');
const { mergeWithRules } = require('webpack-merge');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const TerserJsPlugin = require('terser-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const pkg = require('./package.json');
const CommonConfig = require('./webpack.common');
const servedByCumulusAPI = process.env.SERVED_BY_CUMULUS_API;
const publicPath = servedByCumulusAPI ? './' : '/';
const MainConfig = mergeWithRules({
devtool: 'replace',
module: {
rules: {
test: 'match',
use: 'prepend',
},
},
})(CommonConfig, {
mode: 'production',
devtool: 'source-map',
output: {
filename: '[name].[contenthash].bundle.js',
chunkFilename: '[name].[contenthash].bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath,
},
optimization: {
nodeEnv: 'production',
concatenateModules: true,
minimize: true,
minimizer: [
new TerserJsPlugin({
parallel: true,
include: /\.js$/,
terserOptions: {
sourceMap: true,
}
}),
new CssMinimizerPlugin({
minimizerOptions: {
preset: [
'default',
{
discardComments: {
removeAll: true,
},
},
],
},
}),
],
splitChunks: {
cacheGroups: {
vendor: {
name: 'vendor',
test: /[\\/]node_modules[\\/]/,
chunks: 'all',
maxSize: 500000,
},
styles: {
name: 'styles',
test: /\.css$/,
chunks: 'all',
},
},
},
runtimeChunk: true,
sideEffects: true,
},
module: {
rules: [
{
test: /\.(css|scss)$/,
use: [
{
// Creates `style` nodes from JS strings
loader: 'style-loader',
},
{
// Minifies CSS files
loader: MiniCssExtractPlugin.loader,
options: {
esModule: false,
},
},
],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: `[name].[chunkhash:8]-${pkg.version}.css`,
chunkFilename: `[id].[chunkhash:8]-${pkg.version}.css`,
}),
],
});
module.exports = MainConfig;