- 下载uglifyjs-webpack-plugin插件
- 在vue.config文件中进行配置
publicPath: process.env.NODE_ENV === 'production' ? './' : '/',outputDir: 'n-sim-ipc-manage-build',productionSourceMap: false,configureWebpack: config => {//打包文件增加hashconfig.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,},//生产环境自动删除consolecompress: {// warnings: false, // 若打包错误,则注释这行drop_debugger: true, //清除 debugger 语句drop_console: true, //清除console语句pure_funcs: ['console.log'],},},sourceMap: false,parallel: true,}))}},