-
In
package.json
:dependencies: { ... "@angular/service-worker": "6.0.3", ... }
-
In
angular.json
:"architect": { "build": { "configurations": { "production": { ... "serviceWorker": true, "ngswConfigPath": "/src/ngsw-config.json", ... } } } }
-
In
app.module.ts
imports: [ .... ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production }) .... ],
-
Create
ngsw-config.json
:{ "index": "/index.html", "assetGroups": [{ "name": "app", "installMode": "prefetch", "resources": { "files": [ "/favicon.ico", "/index.html" ], "versionedFiles": [ "/*.bundle.css", "/*.bundle.js", "/*.chunk.js" ] } }, { "name": "assets", "installMode": "lazy", "updateMode": "prefetch", "resources": { "files": [ "/assets/**" ] } }] }
And then npm install
or npm update