1. vue3.0打包去掉console.log
下载插件
cnpm install terser-webpack-plugin --save-dev
在src同级目录下创建vue.config.js,内容如下
module.exports = {
publicPath: './',
configureWebpack: (config)=>{
if(process.env.NODE_ENV === 'production'){
config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
}
}
}
npm run build打包后就没有console.log了
2.vue webpack打包时如何去掉console.log?
在webpack.prod.conf.js 文件中(35行左右)将设置修改为
new UglifyJsPlugin({
uglifyOptions: {
compress: {
warnings: false,
// 打包的时候移除console、debugger
drop_debugger: true, // 移除debugger
drop_console: true, // 移除console
pure_funcs: ['console.log','console.info']
}
},
sourceMap: config.build.productionSourceMap,
parallel: true
}),
3.uniapp 微信小程序 vue 生产环境去除console.log 日志
直接在main.js中引入以下代码
//...
if (uni.getSystemInfoSync().platform !== "devtools") {
console.log = () => {}
}
/*
const app = new Vue({
store,
...App
})
app.$mount()
*/
判断当前是否是运行在开发者工具中,如果不是,则让log变成一个空函数。这样log就不会打印出内容了,基本上没有什么耗时操作。