【问题标题】:React app gets blank page when emulates with Firebase使用 Firebase 进行模拟时,React 应用程序出现空白页
【发布时间】:2021-02-15 18:32:07
【问题描述】:

我的 Firebase 项目在 public 文件夹中有多个文件夹。其中一个初始化了 React 应用程序的文件夹。所以,我的项目树看起来像这样。

firebase-project
\---public
    |---folder1
    |---folder2
    \---react-app
        |---build
        |---public

我在根文件夹中没有 build 文件夹。 public 文件夹由 Firebase 生成。

这是我的firebase.json:

{
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

当我运行firebase serve 或firebase emulators:start 时,index.html 在folder1 和folder2 中显示正确,但react-app 不正确显示。 localhost:5000/react-app/build 和localhost:5000/react-app/public 显示空白页。

但如果你在public 键中提供react-app 应用程序的路径,它就可以工作。

"public": "public/react-app/build",

但在这种情况下,我无法导航到 folder1 和 folder2 路径

我尝试使用"rewrites" 重定向到build 路径,但这也不起作用。在 public 键中提供到 react-app 的直接路径时,它可以正常工作。

我错过了什么?

【问题讨论】:

  • 您可能放错了 google.json 文件
  • @Anee 是安卓相关的吗?该项目在网络上
  • 是的,和android有关

标签: reactjs firebase webpack deployment


【解决方案1】:

问题在于 Webpack 搜索资产的位置。这并没有错。

你看,当 Webpack 创建构建(在 React 中使用 npm run build)时,在 index.html 文件中它指向像 /static/js/%name%.chunk.js 这样的资产。因为在firebase.json 我的public 键指向public 文件夹,它在根目录中搜索static 文件夹。但是通过这种结构,资产位于/react-app/build/static/。

一旦您指向正确的位置,一切都会正常进行。

我肯定需要重新安排我的结构,因为很多不必要的文件会部署到 firebase。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-25
    • 2021-08-16
    • 2020-10-04
    • 2019-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多