简体   繁体   English

如何确定我的React Native应用程序是否是JavaScript代码的调试或发布版本?

[英]How can I determine if my React Native app is a debug or release build from JavaScript code?

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. 我想在我的React Native应用程序中添加一些仅调试的UI,但我在JavaScript环境中找不到任何等效的RCT_DEBUGRCT_DEV编译时标志。 Is there one? 有吗?

Use case: I want to add a status bar that shows the number of HTTP requests initiated by my app. 使用案例:我想添加一个状态栏,显示我的应用程序发起的HTTP请求数。 Obviously this is not part of a shipping app, but it would help me check my work while in development and testing. 显然这不是一个发货应用程序的一部分,但它可以帮助我在开发和测试中检查我的工作。

if (__DEV__) {
    console.log('I am in debug');
}

You can see this approach is being used in React Native repository . 您可以在React Native存储库中 看到此方法正在使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM