-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.config.js
54 lines (50 loc) · 2.03 KB
/
webpack.prod.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
/*
In production it could include modification of assets, extracting CSS into a separate file
and outputting the chunks to a build directory.
*/
const webpack = require("webpack");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const merge = require("webpack-merge");
const TerserJSPlugin = require("terser-webpack-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const { baseConfig, SRC_DIR, DIST_DIR } = require('./webpack.base.config');
const prodConfig = merge(baseConfig, {
/* webpack v4+ will minify the code by default in production mode
Note that while the TerserPlugin is a great place to start for minification and being used by default,
there are other options out there. Here are a few more popular ones:
BabelMinifyWebpackPlugin
ClosureWebpackPlugin
If you decide to try another minification plugin, just make sure your new choice also drops dead code
as described in the tree shaking guide and provide it as the optimization.minimizer.
*/
mode: "production",
output: {
filename: '[name].bundle.[chunkhash].js',
path: DIST_DIR
},
optimization: {
/*
The SplitChunksPlugin allows us to extract common dependencies into an existing entry
chunk or an entirely new chunk. Let's use this to de-duplicate the lodash dependency
*/
splitChunks: {
chunks: "all"
},
// optimization.minimizer overrides the defaults provided by webpack which uses TerserJSPlugin
minimizer: [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin({})]
},
plugins: [
// This is a shorthand for using the DefinePlugin on process.env keys.
// process.env injected by node into app to give access to system environment variables
new webpack.EnvironmentPlugin({
DEBUG: false
}),
// regenerate html file and add automatically bundles to it
new HtmlWebpackPlugin({
template: SRC_DIR + '/index.ejs',
filename: DIST_DIR + '/index.html',
inject: 'body'
})
]
});
module.exports = prodConfig;