diff --git a/angular.json b/angular.json index b0083e5..92687b9 100644 --- a/angular.json +++ b/angular.json @@ -48,7 +48,8 @@ "maximumError": "8kB" } ], - "outputHashing": "all" + "outputHashing": "all", + "serviceWorker": "ngsw-config.json" }, "development": { "optimization": false, diff --git a/ngsw-config.json b/ngsw-config.json new file mode 100644 index 0000000..2160127 --- /dev/null +++ b/ngsw-config.json @@ -0,0 +1,28 @@ +{ + "$schema": "./node_modules/@angular/service-worker/config/schema.json", + "index": "/index.html", + "assetGroups": [ + { + "name": "app", + "installMode": "prefetch", + "resources": { + "files": [ + "/favicon.ico", + "/index.csr.html", + "/index.html", + "/manifest.webmanifest", + "/*.css", + "/*.js" + ] + } + }, + { + "name": "assets", + "installMode": "lazy", + "updateMode": "prefetch", + "resources": { + "files": ["/**/*.(svg|cur|jpg|jpeg|png|apng|webp|avif|gif|otf|ttf|woff|woff2)"] + } + } + ] +} diff --git a/package-lock.json b/package-lock.json index 30a8d86..c37bd97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "@angular/platform-browser": "^22.0.0-next.0", "@angular/platform-server": "^22.0.0-next.0", "@angular/router": "^22.0.0-next.0", + "@angular/service-worker": "^22.0.0-next.0", "@angular/ssr": "^22.0.0-next.5", "express": "^5.1.0", "rxjs": "~7.8.0", @@ -646,6 +647,25 @@ "rxjs": "^6.5.3 || ^7.4.0" } }, + "node_modules/@angular/service-worker": { + "version": "22.0.0-next.8", + "resolved": "https://registry.npmjs.org/@angular/service-worker/-/service-worker-22.0.0-next.8.tgz", + "integrity": "sha512-dqQkRBX3WFNg8wJ+5NTbXUST2k7r4kMk9X0uCxaN86ptxvvn61LIF9rBwr7FKJLeDIq47jnWzwiX3UrN766YSw==", + "license": "MIT", + "dependencies": { + "tslib": "^2.3.0" + }, + "bin": { + "ngsw-config": "ngsw-config.js" + }, + "engines": { + "node": "^22.22.0 || >=24.13.1" + }, + "peerDependencies": { + "@angular/core": "22.0.0-next.8", + "rxjs": "^6.5.3 || ^7.4.0" + } + }, "node_modules/@angular/ssr": { "version": "22.0.0-next.5", "resolved": "https://registry.npmjs.org/@angular/ssr/-/ssr-22.0.0-next.5.tgz", diff --git a/package.json b/package.json index 22e4657..8e8a586 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "@angular/platform-browser": "^22.0.0-next.0", "@angular/platform-server": "^22.0.0-next.0", "@angular/router": "^22.0.0-next.0", + "@angular/service-worker": "^22.0.0-next.0", "@angular/ssr": "^22.0.0-next.5", "express": "^5.1.0", "rxjs": "~7.8.0", diff --git a/public/icons/icon-128x128.png b/public/icons/icon-128x128.png new file mode 100644 index 0000000..5a9a2cc Binary files /dev/null and b/public/icons/icon-128x128.png differ diff --git a/public/icons/icon-144x144.png b/public/icons/icon-144x144.png new file mode 100644 index 0000000..11702cd Binary files /dev/null and b/public/icons/icon-144x144.png differ diff --git a/public/icons/icon-152x152.png b/public/icons/icon-152x152.png new file mode 100644 index 0000000..ff4e06b Binary files /dev/null and b/public/icons/icon-152x152.png differ diff --git a/public/icons/icon-192x192.png b/public/icons/icon-192x192.png new file mode 100644 index 0000000..afd36a4 Binary files /dev/null and b/public/icons/icon-192x192.png differ diff --git a/public/icons/icon-384x384.png b/public/icons/icon-384x384.png new file mode 100644 index 0000000..613ac79 Binary files /dev/null and b/public/icons/icon-384x384.png differ diff --git a/public/icons/icon-512x512.png b/public/icons/icon-512x512.png new file mode 100644 index 0000000..7574990 Binary files /dev/null and b/public/icons/icon-512x512.png differ diff --git a/public/icons/icon-72x72.png b/public/icons/icon-72x72.png new file mode 100644 index 0000000..033724e Binary files /dev/null and b/public/icons/icon-72x72.png differ diff --git a/public/icons/icon-96x96.png b/public/icons/icon-96x96.png new file mode 100644 index 0000000..3090dc2 Binary files /dev/null and b/public/icons/icon-96x96.png differ diff --git a/public/manifest.webmanifest b/public/manifest.webmanifest new file mode 100644 index 0000000..b77f982 --- /dev/null +++ b/public/manifest.webmanifest @@ -0,0 +1,57 @@ +{ + "name": "angular-22-ssr-pwa", + "short_name": "angular-22-ssr-pwa", + "display": "standalone", + "scope": "./", + "start_url": "./", + "icons": [ + { + "src": "icons/icon-72x72.png", + "sizes": "72x72", + "type": "image/png", + "purpose": "maskable any" + }, + { + "src": "icons/icon-96x96.png", + "sizes": "96x96", + "type": "image/png", + "purpose": "maskable any" + }, + { + "src": "icons/icon-128x128.png", + "sizes": "128x128", + "type": "image/png", + "purpose": "maskable any" + }, + { + "src": "icons/icon-144x144.png", + "sizes": "144x144", + "type": "image/png", + "purpose": "maskable any" + }, + { + "src": "icons/icon-152x152.png", + "sizes": "152x152", + "type": "image/png", + "purpose": "maskable any" + }, + { + "src": "icons/icon-192x192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "maskable any" + }, + { + "src": "icons/icon-384x384.png", + "sizes": "384x384", + "type": "image/png", + "purpose": "maskable any" + }, + { + "src": "icons/icon-512x512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable any" + } + ] +} diff --git a/src/app/app.config.ts b/src/app/app.config.ts index f669dde..27a00f1 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -1,13 +1,18 @@ -import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core'; +import { ApplicationConfig, provideBrowserGlobalErrorListeners, isDevMode } from '@angular/core'; import { provideRouter } from '@angular/router'; import { routes } from './app.routes'; import { provideClientHydration, withEventReplay } from '@angular/platform-browser'; +import { provideServiceWorker } from '@angular/service-worker'; export const appConfig: ApplicationConfig = { providers: [ provideBrowserGlobalErrorListeners(), provideRouter(routes), provideClientHydration(withEventReplay()), + provideServiceWorker('ngsw-worker.js', { + enabled: !isDevMode(), + registrationStrategy: 'registerWhenStable:30000', + }), ], }; diff --git a/src/index.html b/src/index.html index 5391fa8..29e3c5c 100644 --- a/src/index.html +++ b/src/index.html @@ -6,8 +6,10 @@ + +