如何确定我的 React Native 应用程序是基于 JavaScript 代码的调试版本还是发布版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34498970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I determine if my React Native app is a debug or release build from JavaScript code?
提问by escouten
I'd like to add some debug-only UI to my React Native app, but I can't find any equivalent of RCT_DEBUG
or RCT_DEV
compile-time flags in the JavaScript environment. Is there one?
我想向我的 React Native 应用程序添加一些仅用于调试的 UI,但在 JavaScript 环境中找不到任何等效的RCT_DEBUG
或RCT_DEV
编译时标志。有吗?
Use case: I want to add a status bar that shows the number of HTTP requests initiated by my app. Obviously this is not part of a shipping app, but it would help me check my work while in development and testing.
用例:我想添加一个状态栏,显示我的应用程序发起的 HTTP 请求数。显然,这不是发布应用程序的一部分,但它可以帮助我在开发和测试过程中检查我的工作。
回答by rmevans9
if (__DEV__) {
console.log('I am in debug');
}
You can see this approachis being used in React Native repository.