简体   繁体   中英

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. Managing .env variables for dev, staging, prod is very time saving and safe. 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. I am using react-native-config package.

When I run with this config it always picks from .env file.

PhpStorm运行/调试配置

Then I tried to run with package.json scripts like

"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.

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.

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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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