在webpack.prod.conf.js 中添加
plugins: [ new webpack.DefinePlugin({ 'process.env': env }), new UglifyJsPlugin({ uglifyOptions: { compress: { warnings: false, drop_console: true, pure_funcs: ['console.log'] } }, sourceMap: config.build.productionSourceMap, parallel: true }) ]
如果你用的vue3:在vue.config.js中添加
module.exports = { lintOnSave: true, // 配置webpack打包 configureWebpack: (config) => { // 取消console打印 config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true },