forked from statping-ng/statping-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.prod.js
96 lines (91 loc) · 3.1 KB
/
webpack.config.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'use strict';
const webpack = require('webpack');
const merge = require('webpack-merge');
const HtmlPlugin = require('html-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const MiniCSSExtractPlugin = require('mini-css-extract-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const helpers = require('./helpers');
const commonConfig = require('./webpack.config.common');
const isProd = process.env.NODE_ENV === 'production';
const environment = require('./prod.env');
const VERSION = process.env.VERSION;
const webpackConfig = merge(commonConfig, {
mode: 'production',
output: {
path: helpers.root('dist'),
publicPath: '',
filename: 'js/bundle.js',
chunkFilename: 'js/[name].chunk.js',
},
optimization: {
runtimeChunk: 'single',
minimize: true,
minimizer: [
new OptimizeCSSAssetsPlugin({
cssProcessorPluginOptions: {
preset: [ 'default', { discardComments: { removeAll: true } } ],
}
}),
new UglifyJSPlugin({
cache: true,
parallel: true,
sourceMap: !isProd
})
],
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
chunks: "all",
name: "vendor",
enforce: true
},
styles: {
test: /\.css$/,
name: 'style',
chunks: 'all',
enforce: true
}
}
}
},
plugins: [
new webpack.EnvironmentPlugin(environment),
new CleanWebpackPlugin(),
// new webpack.optimize.LimitChunkCountPlugin({
// maxChunks: 1
// }),
new MiniCSSExtractPlugin({
filename: 'css/[name].css',
chunkFilename: 'css/[name].css'
}),
new CompressionPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp('\\.(js|css)$'),
threshold: 10240,
minRatio: 0.8
}),
// new webpack.HashedModuleIdsPlugin(),
new HtmlPlugin({
template: 'public/base.gohtml',
filename: 'base.gohtml',
inject: false,
minify: false
})
]
});
if (!isProd) {
webpackConfig.devtool = 'source-map';
if (process.env.npm_config_report) {
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
webpackConfig.plugins.push(new BundleAnalyzerPlugin());
}
}
module.exports = webpackConfig;