【问题标题】:Service worker not working for custom domain on Azure Static Web AppService Worker 不适用于 Azure 静态 Web 应用上的自定义域
【发布时间】:2021-05-25 19:22:42
【问题描述】:

我目前正在尝试让 PWA 功能在托管在 Azure 静态 Web 应用程序上的 Angular 应用程序上运行。我遇到了一个问题,服务工作者注册了 xx.azurestaticapps.net,但没有注册我添加的自定义域。

清单

   {
  "name": "App Name",
  "short_name": "Name",
  "theme_color": "#09559D",
  "background_color": "#09559D",
  "display": "standalone",
  "scope": "./",
  "start_url": "./",
  "icons": [

    ..omitted
  ]
}

静态 Web 应用配置文件

{
    "navigationFallback": {
        "rewrite": "index.html",
        "exclude": ["/assets/*.{png,jpg,gif}", "*.css"]
    },
    "mimeTypes": {
        "json": "application/json",
        "webmanifest": "application/manifest+json"
    }
}

有人知道是什么原因造成的吗?

【问题讨论】:

  • 同样的情况。

标签: angular azure progressive-web-apps angular-pwa azure-static-web-app


【解决方案1】:

确保您的构建在“生产”模式下运行。

默认情况下,Angular 仅为生产站点注册 Service Worker。

我遇到了同样的问题。就我而言,Microsoft builder“Oryx”运行“yarn build”来构建应用程序,但该脚本没有“--prod”标志。

变化

package.json

来自

"scripts": {
   "start": "ng serve",
   "build": "ng build",
   [...]

},

"scripts": {
   "start": "ng serve",
   "build": "ng build --prod",
   [...]

},

为我解决了问题。

【讨论】:

    猜你喜欢
    • 2022-08-10
    • 2022-08-16
    • 2013-12-06
    • 2017-12-14
    • 2022-11-02
    • 1970-01-01
    • 1970-01-01
    • 2020-09-07
    • 1970-01-01
    相关资源
    最近更新 更多