NodeJS项目安装包
npm install babel-plugin-transform-remove-console --save-dev
配置Babel
const plugins = []
//如果不是开发环境则启用
if (process.env.NODE_ENV !== 'development') {
//禁用console功能,但允许console.error
plugins.push(["transform-remove-console", { "exclude": [ "error"] }])
}
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
],
plugins: plugins
}
参考链接
https://babeljs.io/docs/en/babel-plugin-transform-remove-console/
https://www.npmjs.com/package/babel-plugin-transform-remove-console