Firebase 模拟器 - 提供自定义 name/path 到 runtimeconfig.json
Firebase emulator - provide custom name/path to runtimeconfig.json
有没有办法通过命令行提供 .runtimeconfig.json 位置?找不到任何相关信息。
像下面这样的东西?
firebase emulators:start --runtimeconfig ./path/to/.runtimeconfig-prod.json
我有两个 runtimeconfig.json:一个用于开发,另一个用于生产,我正在寻找一种切换模拟器环境的简单方法。
注意:我的开发和生产应用程序存储在两个单独的 firebase 项目下。
您可以通过CLOUD_RUNTIME_CONFIG
指定路径和名称,例如:
CLOUD_RUNTIME_CONFIG="../../.runtimeconfig.json" firebase emulators:start
路径可以是绝对路径,也可以是相对于默认位置的路径。
正如lilalinux所说,您可以使用配置文件的路径设置CLOUD_RUNTIME_CONFIG
。
我就是这样做的。
我在 functions/emulator-tests/config
中为两个环境(staging
和 prod
)创建了配置。
这是我的项目结构的一部分。
functions
emulator-tests
config
.runtimeconfig.staging.json // config for staging env
.runtimeconfig.prod.json // config for prod env
src
.runtimeconfig.json // default config I had
package.json
我安装了 cross-env 并在 package.json
中添加了两个脚本
"scripts": {
...
"emulate-staging": "cross-env CLOUD_RUNTIME_CONFIG=./emulator- tests/config/.runtimeconfig.staging.json firebase emulators:start",
"emulate-prod": "cross-env CLOUD_RUNTIME_CONFIG=./emulator-tests/config/.runtimeconfig.prod.json firebase emulators:start"
...
}
然后,在 functions
文件夹中,我可以通过 运行 相应的脚本使用这两个环境配置中的任何一个进行模拟:npm run emulate-staging
或 npm run emulate-prod
有没有办法通过命令行提供 .runtimeconfig.json 位置?找不到任何相关信息。
像下面这样的东西?
firebase emulators:start --runtimeconfig ./path/to/.runtimeconfig-prod.json
我有两个 runtimeconfig.json:一个用于开发,另一个用于生产,我正在寻找一种切换模拟器环境的简单方法。
注意:我的开发和生产应用程序存储在两个单独的 firebase 项目下。
您可以通过CLOUD_RUNTIME_CONFIG
指定路径和名称,例如:
CLOUD_RUNTIME_CONFIG="../../.runtimeconfig.json" firebase emulators:start
路径可以是绝对路径,也可以是相对于默认位置的路径。
正如lilalinux所说,您可以使用配置文件的路径设置CLOUD_RUNTIME_CONFIG
。
我就是这样做的。
我在 functions/emulator-tests/config
中为两个环境(staging
和 prod
)创建了配置。
这是我的项目结构的一部分。
functions
emulator-tests
config
.runtimeconfig.staging.json // config for staging env
.runtimeconfig.prod.json // config for prod env
src
.runtimeconfig.json // default config I had
package.json
我安装了 cross-env 并在 package.json
"scripts": {
...
"emulate-staging": "cross-env CLOUD_RUNTIME_CONFIG=./emulator- tests/config/.runtimeconfig.staging.json firebase emulators:start",
"emulate-prod": "cross-env CLOUD_RUNTIME_CONFIG=./emulator-tests/config/.runtimeconfig.prod.json firebase emulators:start"
...
}
然后,在 functions
文件夹中,我可以通过 运行 相应的脚本使用这两个环境配置中的任何一个进行模拟:npm run emulate-staging
或 npm run emulate-prod