Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase CLI change hosting target

I have two Firebase hosting sites in >Firebase >Hosting >Main (https://console.firebase.google.com/u/0/project/example/hosting/main)

1. **foobar**.web.app (default project from setup process)
2. **example**.web.app (added as an additional web app under the main project and linked for hosting)

These are my .firebaserc settings:

 {
  "targets": {
    "foobar": {
      "hosting": {
        "foobar": [
          "foobarWebApp"
        ]
      }
    },
    "example": {
      "hosting": {
        "foobar": [
          "foobarWebApp"
        ],
        "example": [
          "foobar"
        ]
      }
    }
  },
  "projects": {
    "default": "foobar"
  }
}

After running firebase deploy from the Firebase CLI the files get deployed to foobar.web.app. How to change it to example.web.app?

I tried firebase deploy --only hosting:example but that always returns Error: An unexpected error has occurred.

like image 409
Tom Avatar asked Apr 20 '20 20:04

Tom


2 Answers

Have you set up the hosting target correctly?

In your CLI,

firebase target:apply type target-name resource-name

  • type — the relevant Firebase resource type. In your case, use hosting.
  • target-name — a unique identifier for the Hosting site that you're deploying to (can be anything)
  • resource-name — the name of the Hosting site as listed in your Firebase project, in your case foobar or example

After you've set up deploy targets for your Firebase resources, reference the applied target names in your firebase.json configuration file.

See https://firebase.google.com/docs/cli/targets

EDIT:

Your .firebaserc should look something like this, (although running that command line statement above should change this already for you, and all you need to update is the package.json):

"projects": {
    "default": "project-name"
},
"targets": {
    "project-name": {
        "hosting": {
            "example": [ // target-name
                "example-website" // resource-name
            ],
            "foobar": [ // target-name
                "foobar-website" // resource-name
            ]
        }
    }
}
like image 157
Ryan Avatar answered Nov 16 '22 04:11

Ryan


made sense to me to break it down into "definitive descriptive variables"

ex .firebaserc file

{
  "targets": {
    "firebaseProjectID": {
      "hosting": {
        "targetValueInFirebase.json": [
          "yourFirebaseHostingDomain"
        ]
      }
    }
  },
  "projects": {
    "cli_alias": "firebaseProjectID"
  }
}
like image 33
Joe Code Avatar answered Nov 16 '22 05:11

Joe Code