webpack.prod.conf.js
2.02 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
const os = require('os');
const webpack = require('webpack');
const path = require('path');
const merge = require('webpack-merge')
const UglifyJsparallelPlugin = require('webpack-uglify-parallel');
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
let baseConfig = require('./webpack.base.conf.js');
let config = require('./config');
let utils = require('./utils');
let webpackConfig = merge(baseConfig, {
module: {
rules: utils.styleLoaders({
sourceMap: config.build.productionSourceMap,
extract: true
})
},
devtool: config.build.productionSourceMap ? '#source-map' : false,
output: {
filename: utils.assetsPath('js/[name].[chunkhash:7].js'),
chunkFilename: utils.assetsPath('js/[name].[chunkhash:7].js')
},
plugins: [
new webpack.DefinePlugin({
'process.env': config.build.env
}),
new UglifyJsparallelPlugin({
workers: os.cpus().length,
mangle: true,
compress: {
warnings: false
},
comments: false,
sourceMap: true
}),
new ExtractTextPlugin({
filename: utils.assetsPath('css/[name].[contenthash:7].css')
}),
new OptimizeCSSPlugin({
cssProcessorOptions: {
safe: true
}
}),
new HtmlWebpackPlugin({
filename: config.build.index,
template: './index.html',
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
}
})
]
});
if (config.build.bundleAnalyzerReport) {
let BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
webpackConfig.plugins.push(new BundleAnalyzerPlugin())
}
module.exports = webpackConfig;