【问题标题】:Angular app deploy to firebase : 404 errorsAngular 应用部署到 Firebase:404 错误
【发布时间】:2018-11-05 19:05:19
【问题描述】:

我正在尝试将我的 Angular 应用部署到 Firebase。

当我执行此操作时,我会转到托管 URL,我收到大量 404 错误(runtime.js、build.js 等)和一个空白页面

我不明白为什么,我做到了:

firebase init

chose storage/firestore/hosting

ng build

firebase deploy

当我做火力服务时,它正在工作......这很奇怪

(ps:角度 6.0.3,firebase 5.0.4)

我的 firebase.json(我必须添加 /hello 我的项目名称,因为 ng build in dist/hello -> "outputPath": "dist/hello",)

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ],
    "source": "functions"
  },
  "hosting": {
    "public": "dist/hello",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  },
  "storage": {
    "rules": "storage.rules"
  }
}

【问题讨论】:

  • 分享你的firebase.json
  • 更新了我的帖子,我的 angular.json 输出路径是 "outputPath": "dist/hello",
  • 非常感谢它的工作原理!
  • 你能标记我的答案吗

标签: angular firebase deployment hosting google-cloud-firestore


【解决方案1】:

您应该设置rewrites 以确保它应该将所有url 重写为index.html。

 {
      "firestore": {
        "rules": "firestore.rules",
        "indexes": "firestore.indexes.json"
      },
      "functions": {
        "predeploy": [
          "npm --prefix \"$RESOURCE_DIR\" run lint",
          "npm --prefix \"$RESOURCE_DIR\" run build"
        ],
        "source": "functions"
      },
      "hosting": {
        "public": "dist/hello",
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ]
    "rewrites": [
          {
            "source": "**",
            "destination": "/index.html"
          }
        ]
      },
      "storage": {
        "rules": "storage.rules"
      }
    }

【讨论】:

    猜你喜欢
    • 2019-04-02
    • 2017-11-29
    • 1970-01-01
    • 2016-12-25
    • 2020-02-13
    • 1970-01-01
    • 1970-01-01
    • 2014-10-29
    • 1970-01-01
    相关资源
    最近更新 更多