【问题标题】:Deploying React project to Firebase leads to window that says "Firebase Hosting Setup Complete"将 React 项目部署到 Firebase 会导致显示“Firebase Hosting Setup Complete”的窗口
【发布时间】:2022-12-25 03:45:06
【问题描述】:

我已按照所有步骤初始化我的项目,我运行npm run build,然后我运行firebase deploy,它给我的 URL 将我带到一个默认的 firebase 网页,上面写着“Firebase 托管设置完成”

谢谢您的帮助!

索引.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
    <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
    <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <title>React App</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  </body>
</html>

【问题讨论】:

    标签: reactjs firebase-hosting


    【解决方案1】:

    完整演练

    在开始任何事情之前,请确保您已经在 FireBase 中创建了您的项目,并且您已经在本地 React 项目文件夹中的 firebase.js 文件中使用了相同的 Firebase 配置

    1. 使用以下命令创建构建文件夹:

      npm 运行构建

      这反过来将在项目文件夹的根目录中创建一个构建文件夹。 基本上,构建文件针对生产进行了优化,代码不会时不时地发生变化。

      1. 使用以下命令安装 Firebase CLI 工具:

        npm 安装 -g firebase-tools

      -g 标志在这里用于全局安装它,因此可以从任何项目轻松访问它。

      1. 登录并初始化

        登录

      登录时,您将被重定向到浏览器窗口,在那里您只需使用您的 FireBase 凭据登录即可。

      firebase init
      

      firebase init 时,您会被问到很多问题,但别担心,我会在这里指导您:

      你准备好继续了吗?

      输入y,因为我们要继续。

      您要为此目录设置哪些 Firebase 功能?按 Space 选择功能,然后按 Enter 确认您的选择。

      在这里,您需要选择项目中包含的所有功能,您可能不需要任何功能,只是将其用于免费托管。 :) 就我而言,我在我的项目中使用了 Firestore 和 Storage 并且还需要托管,所以我使用空格选择这 3 个,然后按回车键。

      确保选择 Firebase 托管,其中 Github 操作是可选的。(请参阅上图中的绿色星星)。

      当提示输入 Firebase 规则和其他类似内容时,请使用默认选项。

      要选择公共目录,请确保选择建造文件夹

      选择这些选项。确保你不覆盖构建/index.html.

      1. 部署我们的网络应用程序

        火力基地部署

      就这样我们完成了

      已部署应用程序的链接将位于终端中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-18
      • 2017-09-01
      • 2022-07-27
      • 2020-07-09
      • 2020-10-18
      • 2020-10-06
      • 1970-01-01
      相关资源
      最近更新 更多