statping/frontend/config/webpack.config.prod.js

94 lines
3.0 KiB
JavaScript
Raw Normal View History

2020-01-17 04:55:50 +00:00
'use strict';
const webpack = require('webpack');
const merge = require('webpack-merge');
2020-02-19 04:07:22 +00:00
const HtmlPlugin = require('html-webpack-plugin');
2020-01-17 04:55:50 +00:00
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');
2020-02-21 19:38:21 +00:00
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
2020-01-17 04:55:50 +00:00
const helpers = require('./helpers');
const commonConfig = require('./webpack.config.common');
const isProd = process.env.NODE_ENV === 'production';
const environment = require('./prod.env');
2020-02-04 08:55:52 +00:00
const VERSION = process.env.VERSION;
2020-01-17 04:55:50 +00:00
const webpackConfig = merge(commonConfig, {
mode: 'production',
output: {
path: helpers.root('dist'),
2020-02-21 19:38:21 +00:00
publicPath: '',
filename: 'js/bundle.js',
chunkFilename: 'js/[name].chunk.js',
2020-01-17 04:55:50 +00:00
},
optimization: {
runtimeChunk: 'single',
2020-02-21 19:38:21 +00:00
minimize: true,
2020-01-17 04:55:50 +00:00
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[\\/]/,
2020-02-21 19:38:21 +00:00
chunks: "all",
name: "vendor",
enforce: true
2020-01-17 04:55:50 +00:00
},
styles: {
test: /\.css$/,
2020-02-19 04:07:22 +00:00
name: 'style',
2020-01-17 04:55:50 +00:00
chunks: 'all',
enforce: true
}
}
}
},
plugins: [
new webpack.EnvironmentPlugin(environment),
2020-02-21 19:38:21 +00:00
new CleanWebpackPlugin(),
2020-01-17 04:55:50 +00:00
new MiniCSSExtractPlugin({
2020-01-26 21:01:43 +00:00
filename: 'css/[name].css',
2020-02-19 04:07:22 +00:00
chunkFilename: 'css/[name].css'
2020-01-17 04:55:50 +00:00
}),
new CompressionPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp('\\.(js|css)$'),
threshold: 10240,
minRatio: 0.8
}),
2020-02-19 04:07:22 +00:00
new webpack.HashedModuleIdsPlugin(),
new HtmlPlugin({
template: 'public/base.gohtml',
filename: 'base.gohtml',
inject: false,
minify: false
})
2020-01-17 04:55:50 +00:00
]
});
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;