Firebase 部署到另一个站点

160*_*Tâm 3 javascript web firebase reactjs firebase-hosting

我正在使用 Firebase 托管来部署我的应用程序

在此输入图像描述

如您所见,我有 2 个应用程序:clone-a50db并且clone-eeb88该应用程序clone-eeb88已在使用中,所以现在我想将我的应用程序部署到另一个应用程序,即clone-a50db.

我就是这样做的:

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!`
Run Code Online (Sandbox Code Playgroud)
npm run build
Run Code Online (Sandbox Code Playgroud)
firebase deploy --only hosting` (because I already deployed function in advanced)
Run Code Online (Sandbox Code Playgroud)

它有效,但不是部署到clone-a50db,而是部署到clone-eeb88,这是可行的,因为它使用的是默认项目,正如clone-eeb88设置中所述,请告诉我如何切换我的网站,非常感谢,新年快乐

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"
  }
}
Run Code Online (Sandbox Code Playgroud)

asp*_*aga 8

** 更新 ** 您真正想要的是“多主机”。
要管理同一站点的两个不同版本,您必须通过文件中的目标firebase.json -> hosting将它们分开,如下所示:

以下是 GitHub 上的示例模板项目,我在其中使用 Firebase 多主机支持

{
  "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"
  }
}
Run Code Online (Sandbox Code Playgroud)

firebase.json现在您必须先手动设置它,而不是像以前一样在内部使用“site”属性,如下所示:

firebase target:apply hosting alpha clone-eeb88
firebase target:apply hosting beta clone-a50db
Run Code Online (Sandbox Code Playgroud)

之后,您将能够使用 Firebase CLI 命令,如下所示:

firebase deploy --only hosting:alpha
firebase deploy --only hosting:beta
Run Code Online (Sandbox Code Playgroud)