-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.prod.js
More file actions
71 lines (68 loc) · 2.01 KB
/
webpack.prod.js
File metadata and controls
71 lines (68 loc) · 2.01 KB
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
// the following 2 lines is to merge common webpack configurations with this file
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const autoprefixer = require('autoprefixer');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const { cssSubDirectory } = require('./constants');
module.exports = (env, options) => {
return merge(common(env, options), {
// will return the original source code (build speed: medium, rebuild speed: pretty slow)
// source mappings are very useful for debugging
devtool: 'cheap-module-source-map',
optimization: {
// minify the bundled js files
minimizer: [new TerserJSPlugin(), new OptimizeCSSAssetsPlugin()],
},
module: {
rules: [
{
test: /\.s?[ac]ss$/,
exclude: /node_modules/,
use: [
// extract styles to a file
{ loader: MiniCssExtractPlugin.loader },
{
loader: 'css-loader',
options: {
// Number of loaders applied before CSS loader (which is postcss-loader)
importLoaders: 2,
// the following is used to enable CSS modules
// modules: true,
// unique name of generated selectors
localIdentName: '[name]__[local]__[hash:base64:5]',
},
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: [
autoprefixer({
browsers: ['ie >= 11', 'last 2 versions'],
}),
],
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
],
},
],
},
plugins: [
// used to extract styles into separated stylesheet
new MiniCssExtractPlugin({
// used for main styles file
filename: cssSubDirectory + '[name].[hash:8].css',
// used for the lazy loaded component
chunkFilename: cssSubDirectory + '[id].[hash:8].css',
}),
],
});
};