-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.production.js
61 lines (50 loc) · 1.5 KB
/
webpack.config.production.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
'use strict';
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const config = require('./webpack.config.base.js');
const publicPath = '/';
config.output.publicPath = publicPath;
if (!config.module) {
config.module = {};
}
// Use ExtractTextPlugin on any loader that uses style-loader
if (config.module.rules) {
for (const l of config.module.rules) {
if (l.use === 'style-loader') {
l.use = ExtractTextPlugin.extract({ loader: 'style-loader' });
} else if (l.use[0] === 'style-loader'
|| l.use[0].loader === 'style-loader') {
l.use = ExtractTextPlugin.extract({
use: l.use.slice(1),
fallback: 'style-loader'
});
}
if (l.use[0].loader === '>/public-loader') {
l.use[0].options.publicPath = publicPath;
}
}
}
if (!config.plugins) {
config.plugins = [];
}
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
},
};
config.plugins.push(
new CleanWebpackPlugin(['dist'], { verbose: true }),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new ExtractTextPlugin({
filename: '[name].[contenthash].min.css',
allChunks: true
})
);
module.exports = config;