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
})
}
)
}
更多優(yōu)化配置可看該文:https://baijiahao.baidu.com/s?id=1699984653181499769&wfr=spider&for=pc