-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.prod.js
80 lines (72 loc) · 2.55 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
const paths = require('./paths')
const { merge } = require('webpack-merge')
const common = require('./webpack.common.js')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const TerserJSPlugin = require('terser-webpack-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
module.exports = merge(common,
{
mode: 'production',
devtool: false,
output: {
path: paths.build,
publicPath: './',
filename: '[name].[contenthash].bundle.js'
},
plugins: [
// will extract css into separate files. style-loader is for devel, MiniCssExtracPlugin is for production. They cannot be used together
new MiniCssExtractPlugin({
filename: 'styles/[name].[contenthash].css',
chunkFilename: '[id].css'
})
],
module: {
rules: [
{
test: /\.(scss|css)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: { importLoaders: 1 }
},
'postcss-loader',
'sass-loader'
]
}
]
},
// minifying javascript and css
optimization: {
minimizer: [
new TerserJSPlugin({}),
new OptimizeCSSAssetsPlugin({})
],
/**
* The build output will have several chunks, this option ensures the parts use
* the webpack runtime instead of having their own.
*
* It also gives long-term caching: the chunks will only change when actual code changes (not the webpack runtime)
*/
runtimeChunk: 'single',
/**
* Separates common dependencies in one shared bundle. Ex: react is not going to change as often as the app code,
* so we can cache its chunk separately
*/
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/](react|react-dom|lodash)[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
}
},
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000
}
}
)