【发布时间】:2019-08-28 12:20:45
【问题描述】:
我正在尝试从我的 react-native 应用程序的输出中删除 console.log 输出,但是当我运行时
ENVFILE=.env.production react-native run-android --variant=release
和
adb logcat
我仍然看到我的应用程序的数据正在记录到控制台。
我使用了以下文档:https://facebook.github.io/react-native/docs/performance.html#using-consolelog-statements。
这是我的 .babelrc 文件:
{
"presets": ["react-native"],
"env": {
"production": {
"plugins": ["transform-remove-console"]
}
}
}
我错过了什么? 我在 react-native 0.60.3 并使用 "babel-plugin-transform-remove-console": "^6.9.4",
【问题讨论】:
-
您找到解决方案了吗?我也得到了这个,但是我正在使用
babel.config.js -
对不起,伙计,不得不继续前进。我一直在使用以下方法作为解决方法。这是一个糟糕的解决方法,但我仍然有我的工作。函数 noop () {} if (process.env.NODE_ENV === 'production') { console.log = noop;控制台.warn = noop;控制台.error = noop; }
-
谢谢!我最终在我的 babel.config.js 中这样做了,因为它可以导出一个函数:module.exports = function(api) { api.cache(true); if (process.env.NODE_ENV === 'production' || process.env.BABEL_ENV === 'production') { return { "presets": ["module:metro-react-native-babel-preset"], "plugins": ["react-native-paper/babel", "transform-remove-console"] } } else { return { "presets": ["module:metro-react-native-babel-preset"], } } } 对不起单行,在评论哈哈。似乎工作正常
-
添加为答案
-
@ThembelaniM 您可能已经继续前进,但接受一个有效的答案仍然是个好主意! :) 谢谢
标签: reactjs react-native babeljs