【问题标题】:How to manage react-native .env variables with PhpStorm Run/Debug Configuration?如何使用 PhpStorm 运行/调试配置管理 react-native .env 变量?
【发布时间】:2019-04-13 04:36:56
【问题描述】:

我正在使用 PhpStorm 并尝试使用特定的 env 变量自动运行。为 dev、staging、prod 管理 .env 变量非常省时且安全。因此,当我从终端运行 set ENVFILE=.env.staging && react-native run-android 时,它会选择 .env.staging 变量,但是我无法从 PhpStorm 调试 react-native 应用程序。我正在使用 react-native-config 包。

当我使用此配置运行时,它总是从 .env 文件中选择。

然后我尝试使用 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 .."
  }

虽然当我使用 PhpStorm 调试运行调试时它会打开调试选项卡,但它没有显示调试变量。

所以我想要的是单击 Run/Debug 选择正确的 .env 文件,我将能够从 PhpStorm 调试 React Native 应用程序。

【问题讨论】:

    标签: react-native environment-variables phpstorm webstorm react-native-config


    【解决方案1】:

    您可以为devstagingprod 创建单独的运行配置,并在Environmentvariables 中设置相应的环境变量(ENVFILE=.env.stagingENVFILE=.env.prodENVFILE=.env.dev): 他们每个人的字段,例如:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-12
      • 1970-01-01
      • 2019-12-02
      • 2023-03-28
      • 2015-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多