ng build --watch does not generate ngsw-worker.js, and siblings.
x)Not sure. Had the same problem with angular 8, figured out it was the watch flag only after i upgraded to 9.
ng build --watch --prod: no ngsw-worker & siblings under dist/project
ng build --watch --prod: ngsw-worker & siblings are generated under dist/project
new new foo
cd foo
ng add @angular/pwa
ng build --watch --prod
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 9.0.1
Node: 10.17.0
OS: linux x64
Angular: 9.0.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router, service-worker
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.900.1
@angular-devkit/build-angular 0.900.1
@angular-devkit/build-optimizer 0.900.1
@angular-devkit/build-webpack 0.900.1
@angular-devkit/core 9.0.1
@angular-devkit/schematics 9.0.1
@angular/cli 9.0.1
@ngtools/webpack 9.0.1
@schematics/angular 9.0.1
@schematics/update 0.900.1
rxjs 6.5.4
typescript 3.7.5
webpack 4.41.2
This is actually by design. Maybe @clydin would know the exactly details why under watch these are not generated though.
Well, I just pulled my remaining hairs out by design then...
At least a warning and an option to turn this off would be great, because I am usually working with ng build --watch running in the background, and spent hours trying to figure out why they don't get generated
Talked with @clydin today and it seems that ng build --watch currently does not build service workers because ng serve does not build service workers because we don't currently have a good means of running a PWA locally (there are a few requirements, such as SSL, that are hard to satisfy locally).
As a result, this seems to be mostly an oversight. We don't see any reason ng build --watch _shouldn't_ build a service worker, it's only ng serve where that doesn't work out. In fact, applications may want to use ng build --watch and then serve it with a custom stack to manually fulfill those PWA requirements.
Most likely somewhere in the CLI we are checking if (!buildOptions.watch) { buildServiceWorker(); } when we should be doing if (buildCommand !== 'serve') { buildServiceWorker(); }.
This is just a bug we'll need to look into more.
https://stackoverflow.com/a/34161385
"There's an exception to the HTTPS requirement in place to facilitate local development: if you access your page and service worker script via http://localhost[:port], or via http://127.x.y.z[:port], then service workers should be enabled without any further actions."
So serving a PWA locally shouldn't be a problem anymore, and also there may be more complicated setups where there is a valid certificate in place, for example I am using ng serve to serve PWA locally. I have an SSL certificate for a domain I own, and set up port forwarding for that host to my locally served application. I am using this for development only of course, and would benefit from ng serve --watch building the PWA files to be served.
Should also look into ng serve building the service worker as well as ng build --watch per #10483.
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._
Most helpful comment
Well, I just pulled my remaining hairs out by design then...
At least a warning and an option to turn this off would be great, because I am usually working with ng build --watch running in the background, and spent hours trying to figure out why they don't get generated