问题描述
我开发一个反应过来,本机应用程序,其中一些API调用应。
I develop a react-native app where some API calls should be made.
如果我在生产模式下为我的应用程序应该调用,例如,这台主机:
If I'm in production mode my app should call, for example, this host :
https://example.com/
但如果我在开发模式是,它应该叫我的本地主机的不同端口上,例如:
but if I'm in dev mode, it should call my local host machine on a different port, for example :
http://192.168.0.10:8080/
如何应对外来code可以知道它的环境?
How the react-native code can be aware of its environment ?
.dotenv
似乎不与反应母语。工作
.dotenv
seems to not work with react-native.
在Chrome的调试中,我们可以看到,应用程序与一些PARAMS启动:
In the Chrome debug, we can see that the application is launched with some params :
Running application "AppName" with appParams: {"initialProps":{},"rootTag":1}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
我们可以得到在应用此 __ __ DEV
价值?
Can we get this __DEV__
value in the application ?
感谢
推荐答案
恒 __ __ DEV
自动设置。
通过构建bundle - 开发=假
应该取消设置 __ __ DEV
Building the bundle via --dev=false
should unset __DEV__
.
if (__DEV__) {
console.log('Development');
} else {
console.log('Production');
}
这篇关于不动产资产信托母语:检测开发或生产ENV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!