简体   繁体   English

Angular Service Worker 未在开发模式下注册

[英]Angular service worker not register in development mode

I would like to know if it' s possible to test pwa and register the serviceworker during the dev mode ( not production)我想知道是否可以在开发模式(非生产)期间测试 pwa 并注册 serviceworker

As when i make the ng build --prod then launchhttp-server in the dist folder it works fine, but then when i do ng serve without the build it gives me the chrome error: Service Worker failed to register当我进行 ng build --prod 然后在 dist 文件夹中启动http-server时它工作正常,但是当我在没有构建的情况下进行服务时,它给了我chrome错误:Service Worker failed to register

Are the procedures same on prod and dev ? prod 和 dev 上的程序是否相同? as with lighthouse, the audit gives me ok on serviceworker on prod but not in dev for the same project与灯塔一样,审计让我在 prod 上对 serviceworker 没问题,但在同一个项目的 dev 中不行

Any helps or links would be appreciate任何帮助或链接将不胜感激

Thanks谢谢

This question is 2 years old but I see it wasn't answered.这个问题已经 2 年了,但我看到它没有得到回答。

You cannot run service worker with ng server.你不能用 ng server 运行 service worker。 As you mentioned, it works using http-server.正如您所提到的,它使用 http-server 工作。 This is by design.这是设计使然。 See Angular documentation here .请参阅此处的Angular 文档。

However, if you are not testing specific service worker functionality, such as retrieving data from cache if offline, your application will still function using ng serve, including retrieving data via http.但是,如果您没有测试特定的 Service Worker 功能,例如离线时从缓存中检索数据,您的应用程序仍将使用 ng serve 运行,包括通过 http 检索数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM