在React生产版本中删除控制台日志语句? [英] Remove console log statements in react production build?
问题描述
我有一个基本的React应用(使用 create react app 创建)
我已经浏览了一些相关的链接,例如babel插件安装
npm i babel-plugin-transform-remove-console-保存
使用以下命令删除控制台日志的指南babel插件
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"]
}
}
}
我已经将上面的配置包含到babel.rc文件中,但是仍然不能解决我的问题.我可以在生产版本中看到日志.请让我知道我要去哪里了.
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.
推荐答案
您可以在src/App.js
中尝试此应用的根组件:
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() {};
就在return
之前.
这篇关于在React生产版本中删除控制台日志语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!