首页 > 解决方案 > Firebase 上的 Angular2 托管

问题描述

我按照所有必要的步骤在 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"
      }
    ]
  }
}

标签: angularfirebasehosting

解决方案


hosting的 infirebase.json指向错误的目录。如果您进行构建,并且目标是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.jsonV6) "outDir": "location/of/dist/folder"(或"outputPath": "location/of/dist/folder"V6)中检查构建目标

此外,如果您在firebase init. 如果index.html必须被覆盖,应该会提示您。

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


推荐阅读