Remove console log statements in react production build?

可紊 提交于 2020-01-13 06:01:08

问题


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:


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.



来源:https://stackoverflow.com/questions/57224203/remove-console-log-statements-in-react-production-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!