Search code examples
firebasefirebase-tools

Firebase emulator - provide custom name/path to runtimeconfig.json


Is there a way to provide .runtimeconfig.json location though a command line? Can't find any info on that.

Something like below?

firebase emulators:start --runtimeconfig ./path/to/.runtimeconfig-prod.json

I have two runtimeconfig.json: one for development and another for production and I'm looking for an easy way to switch emulator environment.

Note: my dev and prod applications are stored under two separate firebase projects.


Solution

  • As lilalinux said, you can set CLOUD_RUNTIME_CONFIG with the path of your config file.

    This is how I did it.

    I created configurations for two environments (staging and prod) inside functions/emulator-tests/config. This is part of my project structure.

    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
    

    I installed cross-env and added two scripts in 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"
      ...
    }
    

    Then, from inside the functions folder I can emulate using any of those two environment configurations by running the respective script: npm run emulate-staging or npm run emulate-prod

    Source: https://github.com/firebase/firebase-tools/issues/629