Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng serve with service worker #9869

Closed
StephenFluin opened this issue Mar 5, 2018 · 23 comments · Fixed by #23679
Closed

ng serve with service worker #9869

StephenFluin opened this issue Mar 5, 2018 · 23 comments · Fixed by #23679
Labels
area: @angular-devkit/build-angular devkit/build-angular:dev-server feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature
Milestone

Comments

@StephenFluin
Copy link
Contributor

As a user, I would like to be able to test my service worker generation / scripts.

I can do this today with ng build --prod, but then I have to spin up my own server and manually rebuild each time. If I try running ng build --prod today, I get runtime errors because the service worker can't be found.

If ng build --prod would generate a service worker, this would risk breaking developer expectations (due to normal Service Worker behavior), but it would better match what a developer might expect from debugging a "production" build of their application, even through the refresh cycle would be at the mercy of their service worker.

@mackelito
Copy link

This is just what I'm looking for.. of course we can use something like http-serve or alike but then we have configure our proxy in yet another location and different ways...

@anubees
Copy link

anubees commented Jun 11, 2018

Exactly, I like the hot reload capabilities of ng serve and would love the service workers to work with it.

@mackelito
Copy link

@filipesilva I know that the stated way of running SW on local is to use httpd and serve from /dist.. but we also have a proxy config setup so running from dist will show me the login bit that's it ;)

Perhaps you have some recommendations?

@fazpu
Copy link

fazpu commented Jul 3, 2018

This feature is especially important when you want to test push notifications.

@cyraid
Copy link

cyraid commented Jul 4, 2018

This would be a handy feature, especially when creating new projects with PWA in mind. You want to know if it all works smoothly with push features.

@Gaiidenn
Copy link

+1 Since one of the greatest features of PWA are Push Notifications, we'd love to be able to test all this with the comfort provided by the classic "ng serve" command !

@mackelito
Copy link

Is there any one who has a solution for this when using ng serve?

@christianliebel
Copy link
Contributor

christianliebel commented Nov 12, 2018

@StephenFluin (congratulations and all the best, btw—have a nice vacation) @webmaxru @alxhub: following-up this discussion from https://twitter.com/christianliebel/status/1050789670412521472

@SteffenJahr and I held a couple of workshops at AngularConnect, Angular Days, WDC and other conferences. The fact that service worker generation is not enabled when using ng serve --prod leads to confusion every time. (It’s not even part of our workshop schedule, developers try that themselves.)

One of the crucial downsides when using ng build --prod and a custom HTTP server is that developers can’t make use of incremental TypeScript builds and thus have to wait for 30 seconds or more (depending on project size and performance) for each build. This way, testing simple functionality such as push noted above gets a tedious task.

Proposal:

  • ng serve --prod --generateSW should serve a prod build with SW generation enabled.
  • ng serve --prod should not include a service worker, but issue a developer warning when SW generation is enabled in that project (e.g. Service worker generation is intentionally disabled when serving productive builds to prevent stale resources from being shown. Please use the --generateSW flag in order to enable it.)

What do you think? Is this something PR-worthy?

@alexroldan
Copy link

ng serve --prod --generateSW=config.js
with config file

this is how i do it
"sw": "ng build --prod --aot=true --optimization=true --buildOptimizer=true --deleteOutputPath=true && workbox generateSW workbox-config.js"

I'm force to use http-server to serve the files.
but this does not solve my problem
i still need to use ssl so that pwa will work in mobile as standalone

@ngbot ngbot bot added this to the Backlog milestone Jan 24, 2019
@cnscorpions
Copy link

@christianliebel hi, i type ng serve --prod --generateSW, but Unknown option: '--generateSW' returned. could you please provide a demo link or any other details?

@christianliebel
Copy link
Contributor

@cnscorpions This is my proposal, and it’s not implemented yet.

@balteo
Copy link

balteo commented May 29, 2019

I think this is an important feature for developers. Is there any schedule as to when this will be implemented?

@glemiere
Copy link

glemiere commented May 31, 2019

100% agree this is vital to a healthy dev workflow. It's been a year since this has been open, and it's should be considered more urgently.

@fergalmoran
Copy link

OMG just do it already!!!

@r-holland
Copy link

Yes please

@Kimeiga
Copy link

Kimeiga commented Nov 23, 2019

please please

@domenichelfenstein
Copy link

May 2020 and still open.
I agree with everyone stating this is vital for developing WPAs.

@txone
Copy link

txone commented Jun 12, 2020

June 2020 and still open.
I agree with everyone stating this is vital for developing WPAs.

@donbowman
Copy link

donbowman commented Jun 29, 2020

https://blog.donbowman.ca/2020/06/29/using-ng-serve-with-angular-service-workers/ this workaround works for me, YMMV.
Its not perfect, i'm not sure it works other than for --prod, but it does get further.

@alan-agius4 alan-agius4 changed the title Feature Request: ng serve --prod with service worker Feature Request: ng serve with service worker Dec 1, 2020
@ilyakonrad
Copy link

Tried to update PWA configuration yesterday using ng serve and it seemed to work fine for a few hours (I was mostly changing app shortcut images and splashscreen images) and then I got into this problem that ngsw-worker.js can't load (infinite "pending" status) so I couldn't configure my PWA stuff seeing changes on localhost real-time.

Not sure why I seemed being able to do that earlier that day but then hours later I got here...
Any ideas/explanations would be appreciated 😄

And yes, this feature would make a lot of sense.

@hdsysdev
Copy link

Would be great, shame its been this long with no implementation

@angular-robot angular-robot bot added the feature: under consideration Feature request for which voting has completed and the request is now under consideration label Feb 1, 2022
@ngbot ngbot bot modified the milestones: Backlog, needsTriage Feb 1, 2022
@dgp1130 dgp1130 changed the title Feature Request: ng serve with service worker ng serve with service worker Mar 3, 2022
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Aug 3, 2022
…ker when using dev-server

With this change we add the ability for the dev-server to serve service workers when configured in the browser builder.

Closes angular#9869
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Aug 3, 2022
…ker when using dev-server

With this change we add the ability for the dev-server to serve service workers when configured in the browser builder.

Closes angular#9869
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Aug 3, 2022
…ker when using dev-server

With this change we add the ability for the dev-server to serve service workers when configured in the browser builder.

Closes angular#9869
dgp1130 pushed a commit that referenced this issue Aug 4, 2022
…ker when using dev-server

With this change we add the ability for the dev-server to serve service workers when configured in the browser builder.

Closes #9869
@domenichelfenstein
Copy link

domenichelfenstein commented Aug 5, 2022

I'm really excited about that commit pushed by @dgp1130 and @alan-agius4

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @angular-devkit/build-angular devkit/build-angular:dev-server feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature
Projects
None yet