简体   繁体   English

如何使用PhpStorm运行/调试配置管理react-native .env变量?

[英]How to manage react-native .env variables with PhpStorm Run/Debug Configuration?

I am using PhpStorm and trying to automate the run with specific env variable. 我正在使用PhpStorm并尝试使用特定的env变量自动运行。 Managing .env variables for dev, staging, prod is very time saving and safe. 为dev,staging和prod管理.env变量非常节省时间并且安全。 So when I run set ENVFILE=.env.staging && react-native run-android from terminal, it picks the .env.staging variables but then I am not able to debug react-native app from PhpStorm. 因此,当我从终端运行set ENVFILE=.env.staging && react-native run-android时,它将选择.env.staging变量,但随后我无法从PhpStorm调试react-native应用程序。 I am using react-native-config package. 我正在使用react-native-config软件包。

When I run with this config it always picks from .env file. 当我使用此配置运行时,它总是从.env文件中选择。

PhpStorm运行/调试配置

Then I tried to run with package.json scripts like 然后我尝试使用package.json脚本运行

"scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest",
    "android-dev": "set ENVFILE=.env.staging",
    "android-staging": "set ENVFILE=.env.staging && react-native run-android",
    "android-prod": "set ENVFILE=.env.prod && react-native run-android",
    "build-android-prod": "set ENVFILE=.env.prod && cd android && ./gradlew assembleRelease && cd .."
  }

Although it opens the debug tab when I run debug with PhpStorm debug, but it was not showing debug variables. 尽管使用PhpStorm调试运行调试时会打开调试选项卡,但未显示调试变量。

So what I want is that clicking the Run/Debug choose the correct .env file and I will able to debug React Native app from PhpStorm. 所以我想要的是单击“运行/调试”,选择正确的.env文件,我将能够从PhpStorm调试React Native应用程序。

You can create separate run configurations with appropriate names for dev , staging and prod , setting the corresponding environment variables ( ENVFILE=.env.staging , ENVFILE=.env.prod and ENVFILE=.env.dev ) in Environmentvariables: field of each of them, like: 您可以使用devstagingprod适当名称创建单独的运行配置,并在Environmentvariables:每个字段的字段中设置相应的环境变量( ENVFILE=.env.stagingENVFILE=.env.prodENVFILE=.env.dev )。他们,例如:

在此处输入图片说明

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

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