Firebase deploy to another site

I am using Firebase Hosting to deploy my app

enter image description here

As you can see, I have 2 apps: clone-a50db and clone-eeb88 and the app clone-eeb88 is already in use, so now I want to deploy my app to the other which is clone-a50db.

This is how I did:

firebase init
? Are you ready to proceed? Yes
? Which Firebase CLI features do you want to set up for this folder? Press Space to select features, then Enter to confirm your choices. Hosting: Configure and deploy Firebase Hosting sites` 

=== Project Setup

First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add,
but for now we'll just set up a default project.

i  .firebaserc already has a default project, using clone-eeb88.

=== Hosting Setup

Your public directory is the folder (relative to your project directory) that
will contain Hosting assets to be uploaded with firebase deploy. If you
have a build process for your assets, use your build's output directory.`

? What do you want to use as your public directory? build
? Configure as a single-page app (rewrite all urls to /index.html)? Yes
? Set up automatic builds and deploys with GitHub? No
+  Wrote build/index.html

i  Writing configuration info to firebase.json...
i  Writing project information to .firebaserc...

+  Firebase initialization complete!`
npm run build
firebase deploy --only hosting` (because I already deployed function in advanced)

It worked but instead of deploy to clone-a50db, it deployed to clone-eeb88, it is feasible because it is using default project which is clone-eeb88 as it told in the setup, please tell me how to switch my site, thank you so much and happy new year

firebase.json

{
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint"
    ],
    "source": "functions"
  }
}

Upvotes: 3

Views: 2949

Answers (1)

aspirinemaga
aspirinemaga

Reputation: 3937

** UPDATED ** What you actually want is "Multihosting".
To manage two different versions of the same sites, you have to separate them by the targets in your firebase.json -> hosting file, something like this:

Here is the example template project on GitHub where I'm using a Firebase Multihosting support.

{
  "hosting": [
    {
      "target": "alpha",
      "public": "build",
      "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
      ],
      "rewrites": [
        {
          "source": "**",
          "destination": "/index.html"
        }
      ]
    },
    {
      "target": "beta",
      "public": "build",
      "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
      ],
      "rewrites": [
        {
          "source": "**",
          "destination": "/index.html"
        }
      ]
    }
  ],
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint"
    ],
    "source": "functions"
  }
}

Instead of using "site" property inside your firebase.json like before, now you have to set it manually first like so:

firebase target:apply hosting alpha clone-eeb88
firebase target:apply hosting beta clone-a50db

Afterwards, you will be able to use your Firebase CLI commands like so:

firebase deploy --only hosting:alpha
firebase deploy --only hosting:beta

Upvotes: 11

Related Questions