繁体   English   中英

将 React 项目部署到 Firebase 会导致显示“Firebase 托管设置完成”的窗口

[英]Deploying React project to Firebase leads to window that says "Firebase Hosting Setup Complete"

我已经按照所有步骤初始化我的项目,我运行npm run build然后我运行firebase deploy并且它给我的 URL 引导我到一个默认的 firebase 网页,上面写着“Firebase Hosting Setup Complete”

谢谢您的帮助!

索引.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>

完整演练

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

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

    npm 运行构建

在 react.js 中创建构建文件夹

建立文件夹层次结构

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

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

    npm 安装 -g firebase-tools

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

  1. 登录并初始化

    登录

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

Firebase 初始化

firebase init

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

你准备好继续了吗?

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

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

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

正确的选项集

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

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

Firebase 规则

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

在 firebase reactjs 中选择构建文件夹

选择这些选项。 确保您没有覆盖buid/index.html

firebase初始化完成

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

    火力基地部署

部署完成

就这样我们完成了

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

部署的网址

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM