【问题标题】:Trying to deploy a ReactJS project using FirebaseCLI尝试使用 FirebaseCLI 部署 ReactJS 项目
【发布时间】:2020-09-09 03:53:36
【问题描述】:

我构建了一个可以在本地运行的 ReactJS 应用,我按照 Firebase 网站上的说明进行操作

https://medium.com/@devesu/host-a-react-based-website-free-of-cost-with-firebase-hosting-and-connect-with-your-own-domain-53146731807f

一切都按计划进行,但是当我点击提供的链接时没有错误

https://hydrometric-54ec0.web.app

https://hydrometric-54ec0.firebaseapp.com/

我得到一个默认的 Firebase 页面而不是我的应用程序,我认为我的 firebase.json 缺少一些东西,它在下面

{
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

【问题讨论】:

  • 您部署的构建目录中到底有什么?
  • 嘿,Doug,我有我的构建环境,但是我的 index html 被默认的 firebase 覆盖了……现在一切都好

标签: reactjs firebase firebase-hosting


【解决方案1】:

如果您在 Firebase 中部署任何 React 项目。查找以下步骤。

  • 通过npm run build 完成反应构建后
  • firebase init
  • 选择主机
  • 然后 CLI 将询问公共目录 - 写入 build 并按 Enter。
  • 将所有网址重写为 /index.html- 键入 Yes
  • 文件 build/index.html 已经存在。覆盖?- 输入 No 否则它将使用 firebase 默认索引覆盖您的索引文件。

firebase deploy 之前,请执行以下操作。 在firebase.json中替换这段代码

{
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

然后在你的反应package.jsonhomepage做空白路径

  • "homepage": ""

现在你可以选择firebase deploy

【讨论】:

  • 欢迎@R.Merritt
猜你喜欢
  • 1970-01-01
  • 2020-12-12
  • 1970-01-01
  • 1970-01-01
  • 2017-02-01
  • 2013-07-25
  • 1970-01-01
  • 2014-06-04
  • 2021-05-11
相关资源
最近更新 更多