去除vue项目中的console

注:取消vue项目打包之后的 console.log() 在控制台的打印。

一、下载

npm install babel-plugin-transform-remove-console

二、在根路径下,创建babel.config.js

const plugins = ['@vue/babel-plugin-transform-vue-jsx']
// 生产环境移除console   
if (process.env.NODE_ENV === 'production') {  //在这判断 是否为 生产环境
    plugins.push('transform-remove-console')
}
module.exports = {
    plugins: plugins,
    presets: [
        '@vue/app'
    ]
}

这下,再去npm run build 就不会打印console.log()了。


版权声明:本文为qq_45669178原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。