-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.prod.js
76 lines (74 loc) · 2.89 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
const merge = require('webpack-merge');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyWebpackPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const common = require('./webpack.common.js');
const prodConfig = {
mode: 'production', // enable production optimizations
devtool: 'source-map', // enable highest quality source maps
optimization: {
minimizer: [
new UglifyWebpackPlugin({ sourceMap: true }), // uglify JS
new OptimizeCSSAssetsPlugin() // cssnano CSS
],
splitChunks: { // Split all packages required from node_modules in their own file
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'initial'
}
}
},
runtimeChunk: {
name: 'manifest' // split the webpack module resolution runtime in its own file
}
},
output: { // hash file names for predictable caching
chunkFilename: '[name].[chunkhash:4].js',
filename: '[name].[chunkhash:4].js'
},
module: {
rules: [
{
test: /\.scss$/, // look for .scss files and apply loaders in reverse order
use: [
{
loader: MiniCssExtractPlugin.loader, // extract css in its own file
options: { sourceMap: true }
},
{
loader: 'css-loader', // load css
options: { sourceMap: true }
},
{
loader: 'postcss-loader', // autoprefix css
options: {
ident: 'postcss',
plugins: (loader) => [
require('autoprefixer')()
]
}
},
{
loader: 'sass-loader', // convert sass syntax
options: { sourceMap: true }
}
]
}
]
},
plugins: [
new MiniCssExtractPlugin({ // hash css for predictable caching
filename: '[name].[contenthash:4].css',
chunkFilename: '[name].[contenthash:4].css'
}),
new DuplicatePackageCheckerPlugin({ // check for duplicated packages
verbose: true
}),
new BundleAnalyzerPlugin() // analyse bundle for more transparency of what goes in each bundle
]
};
module.exports = merge(common, prodConfig);