【问题标题】:Firebase hosting not showing my app contentFirebase 托管未显示我的应用内容
【发布时间】:2020-02-06 11:51:45
【问题描述】:

我目前正在尝试将我的 Angular 应用程序部署到 Firebase。当我部署应用程序时,我的 index.html 不断被覆盖,并且显示欢迎模式而不是我的应用程序内容。我检查了与该主题相关的所有问题,但提供的答案都没有帮助我。

这是我迄今为止尝试过的:

  • 在询问File dist/index.html already exists. Overwrite? (y/N) N 时选择“否”
  • 用我自己的 index.html 替换 index.html
  • 在类似问题中,用户建议在 Chrome 中切换到隐身模式或清除缓存 - 也没有用
  • 在项目的 index.html 中配置我的基本 href 并添加我的 firebase 项目 < base href="https://["YOUR FIREBASE PROJECT NAME"].firebaseapp.com/">
  • 删除我的dist文件夹并重新运行ng build --prod然后firebase initfirebase deploy

此外,当我重做最后一步时,firebase 不会询问它是否应该替换 index.html,它只是替换它。

我做错了什么?我应该改用 Heroku 等其他托管服务提供商吗?

提前感谢您的帮助!

【问题讨论】:

  • 无需切换到其他托管服务提供商,Firebase 托管非常好。您能否在`firebase deploy --only hosting`之前验证在您运行命令的整个文件夹中不是任何其他index.html,只是您从角度获得的那个?
  • 我有两个 index.html。删除从 firebase 创建的后,我收到“找不到页面错误”和一条消息,显示找不到我的 index.html。我还检查了我的 firebase.json 以确保它引用了该文件。
  • 它现在工作了 :)

标签: angular firebase firebase-hosting


【解决方案1】:

你提到你是:

删除我的dist 文件夹并重新运行ng build --prod,然后firebase initfirebase deploy

您不应该多次运行firebase init。这是用于创建 Firebase 项目的命令,并且只能调用一次。

因此,要部署新版本的应用,您需要将构建结果 (ng build --prod) 放在 Firebase 项目的 dist 文件夹下,替换其中的任何文件/目录(在特别是firebase init创建的默认Firebase index.html文件),然后调用firebase deployfirebase deploy --only hosting

在每次部署之间,您无需删除dist 文件夹。只需删除其内容并将其替换为您的构建过程生成的文件/目录即可。


请注意,我之所以写“在您的 Firebase 项目的 dist 文件夹下”,是因为您对“您想使用什么作为公用文件夹?”的回答。问题是dist

【讨论】:

  • 感谢您的回答,现在可以使用了! :) 我还必须选择 dist 文件夹的 dist/ 文件夹。
猜你喜欢
  • 2019-07-21
  • 2017-10-31
  • 2021-09-21
  • 2020-10-01
  • 2015-04-09
  • 2019-03-16
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多