//一键开启、关闭log true开启 false关闭
console.log = true?console.log: ()=> {};
放在app.js中App({...})外部
直接在main.js中引入以下代码 //... console.log = () => {} /* const app = new Vue({ store, ...App }) app.$mount() */
uni-app h5发行生产环境自动去除console.log和debugger
uni-app根目录默认没有vue.config.js,新建并添加以下代码
module.exports = {
productionSourceMap: false, // 生产打包时不输出map文件,增加打包速度
configureWebpack: config => {
if (process.env.NODE_ENV === 'production') {
config.optimization.minimizer[0].options.terserOptions.compress.warnings = false
config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true
config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs = ['console.log']
}
}
}