chainWebpack(config){
config
.when(process.env.NODE_ENV !== 'development',
config => {
/* 开启gzip压缩,需要后端配合 */
config
.plugin('compressionWebpackPlugin')
.use('compression-webpack-plugin', [{
filename: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp("\\.(" + productionGzipExtensions.join("|") + ")$"),
threshold: 10240,
minRatio: 0.8,
deleteOriginalAssets: false
}])
/* 配置打包后删除console.log和debugger */
config.optimization.minimizer('terser').tap((args) => {
args[0].terserOptions.compress.drop_debugger = true
args[0].terserOptions.compress.pure_funcs = ['console.log']
return args
})
}
)
}
更多优化配置可看该文:https://baijiahao.baidu.com/s?id=1699984653181499769&wfr=spider&for=pc