下载uglifyjs-webpack-plugin插件
在vue.config文件中进行配置
publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
outputDir: 'n-sim-ipc-manage-build',
productionSourceMap: false,
configureWebpack: config => {
//打包文件增加hash
config.output.filename = `js/[name].[hash].${timeStamp}.js`
config.output.chunkFilename = `js/[name].[hash].${timeStamp}.js`
if (process.env.NODE_ENV === 'production') {
config.plugins.push(
//开启gzip压缩
new CompressionWebpackPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: productionGzipExtensions,
threshold: 1024,
minRatio: 0.8,
}),
//build之后生成压缩包
new FileManagerPlugin({
events: {
onEnd: {
delete: [
'./*.zip', // 删除之前已经存在的压缩包
],
archive: [
{
source: './n-sim-ipc-manage-build',
destination: `./n-sim-ipc-manage-build-${dayjs().format(
'YYYYMMDDHHmmss'
)}.zip`,
},
],
},
},
})
)
//配置打包去除console等
config.optimization.minimizer.push(
new UglifyJsPlugin({
uglifyOptions: {
output: {
// 删除注释
comments: false,
},
//生产环境自动删除console
compress: {
// warnings: false, // 若打包错误,则注释这行
drop_debugger: true, //清除 debugger 语句
drop_console: true, //清除console语句
pure_funcs: ['console.log'],
},
},
sourceMap: false,
parallel: true,
})
)
}
},