- 需求: 生产环境去除console.log
-1. 安装插件
npm i babel-plugin-transform-remove-console
-2.在babel.config.js中配置plugin
// exclude - 除去哪类报警信息以外
// log:普通的日志信息。
// info:信息性日志
// debug:调试信息
// table:表格格式的输出
// trace:保留栈跟踪信息
// assert:保留断言信息
// error: 错误
// warn: 警告
const consolePlugins = [];
if(process.env.NODE_ENV == 'production'){
consolePlugins.push(['transform-remove-console', {exclude: ['error']}]);
};
module.exports = {
plugins: [
...consolePlugins,
]
}
- 你越轻松,越不在乎结果,结果反而越好 -