Description
With an Angular project using @ngx-env/builder:
- when using
@angular/service-worker to add service worker support, and
- replacing something in the index.html from an environment variable,
- a build generated a
ngsw.json file with incorrect hashes.
Example
Here is an minimal example
https://stackblitz.com/edit/ngx-env-dht6lfds
To reproduce the issue:
-
run npm run build
-
check the hash of the index.html file using:
shasum ./dist/demo/browser/index.html
(this command is not available in StackBlitz, so you will have to download the file locally)
- Compare this to the hash in
dist/demo/browser/ngsw.json
Cause
This was probably introduced in this PR #108. in packages/angular/src/builders/browser/index.ts the index.html file is changed after the build, which is probably after the service worker hashes where generated.
Workaround
As a workaround (if someone with the same problem happens finds this issue) you can re-calculate the hashes using something like this:
npx ngsw-config dist/demo/browser/ ngsw-config.json
Description
With an Angular project using @ngx-env/builder:
@angular/service-workerto add service worker support, andngsw.jsonfile with incorrect hashes.Example
Here is an minimal example
https://stackblitz.com/edit/ngx-env-dht6lfds
To reproduce the issue:
run
npm run buildcheck the hash of the index.html file using:
(this command is not available in StackBlitz, so you will have to download the file locally)
dist/demo/browser/ngsw.jsonCause
This was probably introduced in this PR #108. in
packages/angular/src/builders/browser/index.tstheindex.htmlfile is changed after the build, which is probably after the service worker hashes where generated.Workaround
As a workaround (if someone with the same problem happens finds this issue) you can re-calculate the hashes using something like this: