How do I switch apps from the firebase cli?

后端 未结 8 625
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-23 09:12

This seems like something which should be pretty easy to do, but for whatever reason, I\'m being defeated.

I\'m trying to use the firebase-tools CLI to interact with

相关标签:
8条回答
  • 2020-12-23 09:16

    I rather use scripts. Consider a project structure like this:

    your-project
    ├── .firebaserc
    └── functions
       ├── package.json
       └── index.js
    

    Go to .firebaserc and follow the next example

    {
      "projects": {
        "default": "project-name",
        "prod": "other-name"
      }
    }
    

    Then go to package.json and add the following scripts (changeToProd, and changeToDev).

    {
      ...
      "scripts": {
        ...
        "changeToProd": "firebase use prod",
        "changeToDev": "firebase use default"
      },
      "dependencies": {
        ...
      },
      ...
    }
    

    If your IDE support npm scripts you can run them using the IDE UI, otherwise it can be run using the command console. Make sure you are inside the functions folder.

    npm run-script changeToProd
    

    You can verify your current project by running the following command from the terminal or added to the scripts as we just did

    firebase use
    
    0 讨论(0)
  • 2020-12-23 09:18

    Addition @cutiko's answer

    In package.json

    "scripts": {
    ...
    "prod": "echo \"Switch to Production environment\" && firebase use prod && npm run runtimeconfig",
    "dev": "echo \"Switch to Development environment\" && firebase use default && npm run runtimeconfig"
    ...
    

    npm run runtimeconfig to get custom config environment

    In .firebaserc

    {
      "projects": {
        "default":"{project-dev-id}",
        "prod": "{project-prod-id}"
      }
    }
    
    0 讨论(0)
  • 2020-12-23 09:33

    In the directory where you run firebase list, there will be a file called firebase.json. If you open that in a text editor, you will see the app name in there. You can change it there or delete firebase.json to change the app.

    Or save yourself the hassle of editing a text file and do as Jason says: use firebase init.

    0 讨论(0)
  • 2020-12-23 09:36

    you can just use a command line switch

    --project=my-firebase-project
    
    0 讨论(0)
  • 2020-12-23 09:36

    to change firebase app destination project you can type "firebase use myProjectName" . i also used the above answeres "firebase list" to check what project i have ( work for me in firebase cli 7.4 with angular 7 app)

    0 讨论(0)
  • 2020-12-23 09:37

    If you are using Node.js on windows, your answer should be

    firebase use <project_id>
    

    but without the <> for example

    firebase use chat-app-2a150
    

    You can use the following code to view all your projects so as to pick the correct project ID to use

    firebase projects:list
    
    0 讨论(0)
提交回复
热议问题