【问题标题】:Angular2 hosting on FirebaseFirebase 上的 Angular2 托管
【发布时间】:2018-07-19 07:57:30
【问题描述】:

按照所有必要的步骤,我在 Firebase 上托管了我的 Angular2 网站

firebase login

firebase init (single page app replace index.html file YES)(folder public)

firebase deploy

但我的网站只包含欢迎模板(欢迎 Firebase 托管设置完成等...)

我尝试删除/替换/自定义公用文件夹中的 index.html 文件,但欢迎模板仍然存在...

如何用我自己的网站替换这个模板??

我的 firebase.json 的内容:

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

【问题讨论】:

  • 可以添加firebase.json的内容吗?你构建的输出路径是什么?
  • 我添加了 firebase.json 的内容,但是如何在构建时看到我的输出路径?

标签: angular firebase hosting


【解决方案1】:

firebase.json 中的 hosting 指向错误的目录。 如果您进行构建,并且目标是location/of/dist/folder 目录,则需要将firebase.json 更改为

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

您可以在.angular-cli.json(或angular.json for V6)中检查构建目标 "outDir": "location/of/dist/folder"(或 V6 的 "outputPath": "location/of/dist/folder"

另外,如果您在firebase init 之前构建了您的项目。如果必须覆盖 index.html,应该会提示您。

您可以重新运行firebase init,而不是编辑firebase.json

【讨论】:

  • 感谢您的帮助,我尝试了所有方法(更改 firebase.json,重新运行 firebase init),但仍然没有...还是一样的欢迎模板
  • 你找到你的输出目录了吗?如果你做ng build,firebase 创建的index.html 会被覆盖吗?
  • 我找到了我的输出目录,还是什么都没有。当我进行构建时,我得到了这个错误:(节点:15328)实验警告:fs.promises API 是实验性的 无法读取属性'config'空类型错误:无法读取空属性“配置”
  • 您需要能够构建您的项目。它是部署到 Firebase 的构建版本。如果构建失败,则不会替换/创建 index.html 文件,而是部署由 firebase init 创建的默认 index.html 文件
猜你喜欢
  • 2020-06-17
  • 2021-04-10
  • 2018-11-12
  • 2018-12-26
  • 2016-09-17
  • 1970-01-01
  • 1970-01-01
  • 2021-10-09
  • 2018-09-17
相关资源
最近更新 更多