Remove console log statements in react production

2020-07-18 10:53发布

I have a basic react app (created using create react app)
I have gone through a few links related such as babel plugin installation npm i babel-plugin-transform-remove-console --save Guide to remove console log using babel plugin

 {
  "env": {
    "production": {
      "plugins": ["transform-remove-console"]
    }
  }
}

I have included the above config to babel.rc file but still, it doesn't solve my problem. I am able to see the logs in the production build. Kindly let me know where I am going wrong.

1条回答
走好不送
2楼-- · 2020-07-18 11:52

You could try this, in src/App.js, the root component of your app:

if (process.env.REACT_APP_STAGE === 'PROD')
  console.log = function no_console() {};

Just before the return.

查看更多
登录 后发表回答