Firebase 托管在部署 Angular 6 应用程序后显示欢迎页面?

rah*_*aha 8 firebase firebase-hosting angular

我想开发 angular 6 应用程序,但在部署 firebase 后只显示欢迎页面。

以下是我为部署而采取的步骤。

  1. 安装了 firebase-tools
  2. ng build --prod(在我的应用中)
  3. 火力初始化
  4. 你准备好继续了吗?(是/否) 是
  5. (*) 托管:配置和部署 Firebase 托管站点
  6. 你想用什么作为你的公共目录?(公共)区
  7. 配置为单页应用程序(将所有 url 重写为 /index.html)?(y/N) 是
  8. 文件 dist/index.html 已经存在。覆盖?(y/N) 是
  9. Firebase 初始化完成!
  10. 在这一步中,我已经删除了 dist 文件夹并ng build --prod再次运行
  11. angular build app 在dist目录内的子文件夹中,因此我将包含 index.html 的子目录中的所有内容复制到dist/.
  12. 火力基地部署
  13. firebase 开放式主机:网站

但在完成所有这些之后,我仍然在链接中看到欢迎页面。

我究竟做错了什么!?

小智 13

尝试: 8. 文件 dist/index.html 已经存在。覆盖?(y/N) N 并在隐身模式下打开指向您的应用程序的链接。说真的,我坚持了几个小时,因为这个 firebase 索引在我的情况下被缓存了,所以这就是为什么我在部署后看不到我的应用程序的原因。


小智 5

问题是: firebase 正在寻找该index.html文件,有时它并不直接存在于dist目录中

解决方案: 更新topublic中的路径或文件夹中文件的路径firebase.json"public":"dist/ProjectName"index.htmldist

例子

{
  "hosting": {
    "public": "dist/<YourProjectName>",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/dist/index.html"
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

  • 对我来说,我必须将“public”值更改为“build/web”,但这有效!也许是因为我使用 Flutter 来构建我的应用程序? (3认同)