一、安装插件 babel-plugin-transform-remove-console
npm install babel-plugin-transform-remove-console --save-dev
二、配置babel.config.js
module.exports = {
plugins: ["transform-remove-console"]
}
三、本地打包测试是否成功
npm 地址https://www.npmjs.com/package/babel-plugin-transform-remove-console
四、判断环境,生产环境再清除
let transformRemoveConsolePlugin = []
if (process.env.NODE_ENV === 'production') {
transformRemoveConsolePlugin = ['transform-remove-console']
}
module.exports = {
plugins: [...transformRemoveConsolePlugin]
};