React Native:process.env只有NODE_ENV

时间:2022-06-28 11:20:17

I'm setting an environment variable while building my react-native app (on windows):

我正在构建一个环境变量,同时构建我的react-native应用程序(在Windows上):

SET APP_ENV=dev & react-native run-android

echo %APP_ENV% returns 'dev'

echo%APP_ENV%返回'dev'

But when I log process.env object in my JS file, I only get:

但是当我在我的JS文件中记录process.env对象时,我只得到:

{
  NODE_ENV: "development"
}

Is there a different way to access environment variables set through command prompt?

是否有不同的方法来访问通过命令提示符设置的环境变量?

1 个解决方案

#1


4  

It's important to know that the React-Native app is running on a device (or emulator) in an environment more like a browser, not a Node.js process.

重要的是要知道React-Native应用程序在更像浏览器的环境中的设备(或模拟器)上运行,而不是Node.js进程。

For cross-compatibility with Node.js libraries that relies on process.env.NODE_ENV to perform optimizations, React-Native adds the process global variable with env.NODE_ENV.

为了与依赖于process.env.NODE_ENV执行优化的Node.js库的交叉兼容性,React-Native使用env.NODE_ENV添加进程全局变量。

If you want to pass custom constants to React-Native, you can use: https://github.com/luggit/react-native-config

如果要将自定义常量传递给React-Native,可以使用:https://github.com/luggit/react-native-config

#1


4  

It's important to know that the React-Native app is running on a device (or emulator) in an environment more like a browser, not a Node.js process.

重要的是要知道React-Native应用程序在更像浏览器的环境中的设备(或模拟器)上运行,而不是Node.js进程。

For cross-compatibility with Node.js libraries that relies on process.env.NODE_ENV to perform optimizations, React-Native adds the process global variable with env.NODE_ENV.

为了与依赖于process.env.NODE_ENV执行优化的Node.js库的交叉兼容性,React-Native使用env.NODE_ENV添加进程全局变量。

If you want to pass custom constants to React-Native, you can use: https://github.com/luggit/react-native-config

如果要将自定义常量传递给React-Native,可以使用:https://github.com/luggit/react-native-config