Skip to content

Commit b955dc6

Browse files
committed
Add a service worker to the Angular app
1 parent a0bb718 commit b955dc6

15 files changed

+111
-4
lines changed

angular/angular.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"aot": true,
2626
"assets": [
2727
"src/favicon.ico",
28-
"src/assets"
28+
"src/assets",
29+
"src/manifest.webmanifest"
2930
],
3031
"styles": [
3132
"src/styles.scss"
@@ -59,7 +60,9 @@
5960
"maximumWarning": "6kb",
6061
"maximumError": "10kb"
6162
}
62-
]
63+
],
64+
"serviceWorker": true,
65+
"ngswConfigPath": "ngsw-config.json"
6366
}
6467
}
6568
},
@@ -89,7 +92,8 @@
8992
"karmaConfig": "karma.conf.js",
9093
"assets": [
9194
"src/favicon.ico",
92-
"src/assets"
95+
"src/assets",
96+
"src/manifest.webmanifest"
9397
],
9498
"styles": [
9599
"src/styles.scss"

angular/ngsw-config.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
3+
"index": "/index.html",
4+
"assetGroups": [
5+
{
6+
"name": "app",
7+
"installMode": "prefetch",
8+
"resources": {
9+
"files": [
10+
"/favicon.ico",
11+
"/index.html",
12+
"/manifest.webmanifest",
13+
"/*.css",
14+
"/*.js"
15+
]
16+
}
17+
}, {
18+
"name": "assets",
19+
"installMode": "lazy",
20+
"updateMode": "prefetch",
21+
"resources": {
22+
"files": [
23+
"/assets/**",
24+
"/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
25+
]
26+
}
27+
}
28+
]
29+
}

angular/package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angular/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@angular/platform-browser": "~10.0.0",
2020
"@angular/platform-browser-dynamic": "~10.0.0",
2121
"@angular/router": "~10.0.0",
22+
"@angular/service-worker": "~10.0.0",
2223
"rxjs": "~6.5.5",
2324
"tslib": "^2.0.0",
2425
"zone.js": "~0.10.3"

angular/src/app/app.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import { NgModule } from '@angular/core';
33

44
import { AppRoutingModule } from './app-routing.module';
55
import { AppComponent } from './app.component';
6+
import { ServiceWorkerModule } from '@angular/service-worker';
7+
import { environment } from '../environments/environment';
68

79
@NgModule({
810
declarations: [
911
AppComponent
1012
],
1113
imports: [
1214
BrowserModule,
13-
AppRoutingModule
15+
AppRoutingModule,
16+
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })
1417
],
1518
providers: [],
1619
bootstrap: [AppComponent]
1.22 KB
Loading
1.36 KB
Loading
1.39 KB
Loading
1.75 KB
Loading
3.47 KB
Loading

0 commit comments

Comments
 (0)