在Firebase上托管Angular2

时间:2018-07-19 07:57:30

标签: angular firebase hosting

我按照所有必要步骤将自己的Angular2网站托管在Firebase上

firebase login

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

firebase deploy

但是我的网站仅包含Welcome模板(Welcome Firebase托管设置完成...)

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

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

firebase.json的内容:

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

1 个答案:

答案 0 :(得分:0)

hosting中的firebase.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中检查构建目标(对于V6,则可以检查angular.json"outDir": "location/of/dist/folder"(或对于V6为"outputPath": "location/of/dist/folder"

此外,如果您在执行firebase init之前已经构建了项目。如果必须index.html被覆盖,应该会提示您。

您可以重新运行firebase.json来代替编辑firebase init