經(jīng)常前端項目里面使用console.log去調(diào)用點東西來調(diào)試惋耙,但是正式環(huán)境里面不想打印出來文狱,一般有兩種辦法
1蝠咆、使用babel-plugin-transform-remove-console
1.1冰更、先安裝
npm install babel-plugin-transform-remove-console --save-dev
1.2啡邑、.babelrc里面增加配置
{
"plugins": ["transform-remove-console"]
}
https://www.npmjs.com/package/babel-plugin-transform-remove-console
2贱勃、簡單點的方式,把正式環(huán)境的console.log直接設(shè)置成空函數(shù)
if(process.env.ENV_NAME ==='prod') {
if(window){
window.console.log =function(){};
}
}