We have an Angular application that uses the angular service worker.
As we know, this service worker compares content hashes from cached files against the hashes in the ngsw.json
file.
Now, we have set-up continuous integration and delivery (with Azure DevOps, but shouldn't matter) and during the delivery phase, we're modifying some settings in an environment.json
file (like color scheme, API url... all related to the deployment target). The problem is, by modifying that json file, the hash no longer matches with the hash for that file in the ngsw.json
file.
We definitely don't want to rebuild for a dedicated target environment as that defeats the purpose in CI/CD. (You don't want to rebuild a package for a production environment once that package went to the QA process).
So the question is: is there a way to regenerate the hashes in the ngsw.json
file after we have modified our environment.json
(or any other) file? Or is there an other solution to this problem?
Are you talking about the following command:
node_modules/.bin/ngsw-config dist src/ngsw-config.json
You can place the command in your package.json:
"scripts": {
"ngsw-config": "node_modules/.bin/ngsw-config dist src/ngsw-config.json"
}
This redoes the config and hashes for you. Run it after your final command, this should be possible in your CI environment.
Note also it can take a base href parameter if you use one of those.
More explanation here: Angular doc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With