Skip to content

Commit 6526701

Browse files
Install @angular/pwa
Ran: ng add @angular/pwa@13 as the latest version (14) was giving errors due to this bug: angular/angular-cli#23343
1 parent 6a5c33b commit 6526701

15 files changed

+117
-4
lines changed

angular.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@
2828
"aot": true,
2929
"assets": [
3030
"src/favicon.ico",
31-
"src/assets"
31+
"src/assets",
32+
"src/manifest.webmanifest"
3233
],
3334
"styles": [
3435
"src/styles.scss"
3536
],
36-
"scripts": []
37+
"scripts": [],
38+
"serviceWorker": true,
39+
"ngswConfigPath": "ngsw-config.json"
3740
},
3841
"configurations": {
3942
"production": {
@@ -91,7 +94,8 @@
9194
"karmaConfig": "karma.conf.js",
9295
"assets": [
9396
"src/favicon.ico",
94-
"src/assets"
97+
"src/assets",
98+
"src/manifest.webmanifest"
9599
],
96100
"styles": [
97101
"src/styles.scss"

ngsw-config.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
{
19+
"name": "assets",
20+
"installMode": "lazy",
21+
"updateMode": "prefetch",
22+
"resources": {
23+
"files": [
24+
"/assets/**",
25+
"/*.(svg|cur|jpg|jpeg|png|apng|webp|avif|gif|otf|ttf|woff|woff2)"
26+
]
27+
}
28+
}
29+
]
30+
}

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.

package.json

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

src/app/app.module.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@ import { BrowserModule } from '@angular/platform-browser';
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', {
17+
enabled: environment.production,
18+
// Register the ServiceWorker as soon as the application is stable
19+
// or after 30 seconds (whichever comes first).
20+
registrationStrategy: 'registerWhenStable:30000'
21+
})
1422
],
1523
providers: [],
1624
bootstrap: [AppComponent]

src/assets/icons/icon-128x128.png

1.22 KB
Loading

src/assets/icons/icon-144x144.png

1.36 KB
Loading

src/assets/icons/icon-152x152.png

1.39 KB
Loading

src/assets/icons/icon-192x192.png

1.75 KB
Loading

src/assets/icons/icon-384x384.png

3.47 KB
Loading

src/assets/icons/icon-512x512.png

4.89 KB
Loading

src/assets/icons/icon-72x72.png

792 Bytes
Loading

src/assets/icons/icon-96x96.png

958 Bytes
Loading

src/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
<base href="/">
77
<meta name="viewport" content="width=device-width, initial-scale=1">
88
<link rel="icon" type="image/x-icon" href="favicon.ico">
9+
<link rel="manifest" href="manifest.webmanifest">
10+
<meta name="theme-color" content="#1976d2">
911
</head>
1012
<body>
1113
<app-root></app-root>
14+
<noscript>Please enable JavaScript to continue using this application.</noscript>
1215
</body>
1316
</html>

src/manifest.webmanifest

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"name": "pwa-experiment-one",
3+
"short_name": "pwa-experiment-one",
4+
"theme_color": "#1976d2",
5+
"background_color": "#fafafa",
6+
"display": "standalone",
7+
"scope": "./",
8+
"start_url": "./",
9+
"icons": [
10+
{
11+
"src": "assets/icons/icon-72x72.png",
12+
"sizes": "72x72",
13+
"type": "image/png",
14+
"purpose": "maskable any"
15+
},
16+
{
17+
"src": "assets/icons/icon-96x96.png",
18+
"sizes": "96x96",
19+
"type": "image/png",
20+
"purpose": "maskable any"
21+
},
22+
{
23+
"src": "assets/icons/icon-128x128.png",
24+
"sizes": "128x128",
25+
"type": "image/png",
26+
"purpose": "maskable any"
27+
},
28+
{
29+
"src": "assets/icons/icon-144x144.png",
30+
"sizes": "144x144",
31+
"type": "image/png",
32+
"purpose": "maskable any"
33+
},
34+
{
35+
"src": "assets/icons/icon-152x152.png",
36+
"sizes": "152x152",
37+
"type": "image/png",
38+
"purpose": "maskable any"
39+
},
40+
{
41+
"src": "assets/icons/icon-192x192.png",
42+
"sizes": "192x192",
43+
"type": "image/png",
44+
"purpose": "maskable any"
45+
},
46+
{
47+
"src": "assets/icons/icon-384x384.png",
48+
"sizes": "384x384",
49+
"type": "image/png",
50+
"purpose": "maskable any"
51+
},
52+
{
53+
"src": "assets/icons/icon-512x512.png",
54+
"sizes": "512x512",
55+
"type": "image/png",
56+
"purpose": "maskable any"
57+
}
58+
]
59+
}

0 commit comments

Comments
 (0)