Angular 20 PWA Setup
Goal
Set up or repair Angular 20 PWA support with @angular/pwa so the app has a valid manifest, service worker registration, generated icons, and verifiable install/offline behavior from a production build.
Inputs
projectRoot (string, default: current working directory)
projectName (string, optional in multi-project workspaces)
registrationStrategy (string, default: registerWhenStable:30000)
enabledInDev (boolean, default: false)
verifyRuntime (boolean, default: true)
Success Criteria
@angular/pwa is installed in dependencies.
- PWA scaffolding exists (
manifest.webmanifest, icons, ngsw-config.json).
- Angular registers
ngsw-worker.js correctly.
- Build output includes service worker artifacts (
ngsw.json, worker files).
- App passes basic manual checks for installability and offline behavior.
Workflow
- Validate workspace and Angular version
- Confirm
package.json and angular.json exist.
- Confirm
@angular/core major version is 20.
- Stop and report when the workspace is not Angular 20.
- Resolve target Angular project
- Read
angular.json projects.
- Use explicit
projectName when provided.
- If only one application project exists, use it automatically.
- If multiple app projects exist and no target is given, ask for the project name.
- Apply official PWA integration
- Run the schematic non-interactively:
ng add @angular/pwa --project <projectName> --skip-confirmation
- Keep generated files unless the user explicitly requests customization.
- Verify generated/updated files
- Confirm presence of:
<projectRoot>/ngsw-config.json
<sourceRoot>/manifest.webmanifest
- icon assets in
<sourceRoot>/icons or configured public assets path
<link rel="manifest" href="manifest.webmanifest"> in <sourceRoot>/index.html
theme-color meta tag in <sourceRoot>/index.html
- Verify service worker registration wiring
- For standalone bootstrap (preferred in Angular 20), ensure provider exists in
src/app/app.config.ts:
provideServiceWorker('ngsw-worker.js', {
enabled: !isDevMode(),
registrationStrategy: 'registerWhenStable:30000'
})
- For NgModule-based apps, ensure equivalent
ServiceWorkerModule.register(...) wiring exists.
- Keep production-safe default behavior: enabled only outside dev mode unless
enabledInDev=true.
- If
registrationStrategy input is provided, verify registration uses that exact value.
- Build and confirm artifacts
- Run project build for the selected app:
ng build <projectName>
- Confirm service-worker artifacts are present in output (for example
ngsw.json and ngsw-worker.js).
- Verify runtime behavior over HTTP server
- If
verifyRuntime=true, serve the production output from a static server (not file://).
- Open in Chrome and verify:
- Application tab shows active service worker
- Manifest is detected and installable
- Offline toggle still loads cached app shell/routes
- Apply minimal, safe customizations when requested
- Only customize
ngsw-config.json when user asks for explicit asset/data caching behavior.
- Keep broad defaults first, then add targeted
assetGroups/dataGroups rules.
- Avoid overcaching API calls unless TTL/versioning strategy is defined.
- Report deterministic completion output
- Include:
- selected
projectName
- files created or changed
- registration wiring location (
app.config.ts or module file)
- build command run and artifact paths found
- runtime verification result (or reason skipped)
Troubleshooting Rules
ng add fails
- Confirm Angular CLI and workspace dependencies are consistent.
- Re-run with explicit
--project in multi-project repos.
- Service worker never activates
- Confirm app is served from built output via HTTP(S), not
ng serve in normal dev mode.
- Confirm registration code exists and
enabled evaluates to true in production.
- Offline mode does not work
- Confirm
ngsw.json exists in build output.
- Inspect
ngsw-config.json patterns and ensure the tested routes/assets are covered.
- App not installable
- Confirm manifest fields/icons are valid and reachable.
- Confirm HTTPS (or localhost), and no critical PWA warnings in DevTools.
Guardrails
- Prefer schematic-generated defaults before manual edits.
- Merge config changes; do not overwrite unrelated workspace settings.
- Keep environment-aware service worker enablement (
!isDevMode()) by default.
- Validate with a real production build before declaring success.
- If runtime verification cannot be executed (for example CI-only environment), explicitly mark as pending manual verification.
Definition of Done
ng add @angular/pwa has been applied successfully for the target app.
- Manifest, icons, and service worker registration are present and valid.
- Production build emits service worker artifacts.
- Installability and basic offline behavior are verified.
References
1---2name: angular-pwa-setup3description: Add, repair, or validate Angular 20 Progressive Web App support with `@angular/pwa`, including deterministic `ng add` execution, service-worker registration verification, manifest/icon checks, production-build artifact validation, and manual install/offline checks. Use when users ask to set up PWA, fix broken service workers, troubleshoot installability/offline behavior, or review `ngsw-config.json`/`manifest.webmanifest`.4---5
6# Angular 20 PWA Setup
7
8## Goal
9
10Set up or repair Angular 20 PWA support with `@angular/pwa` so the app has a valid manifest, service worker registration, generated icons, and verifiable install/offline behavior from a production build.
11
12## Inputs
13
14- `projectRoot` (string, default: current working directory)
15- `projectName` (string, optional in multi-project workspaces)
16- `registrationStrategy` (string, default: `registerWhenStable:30000`)
17- `enabledInDev` (boolean, default: `false`)
18- `verifyRuntime` (boolean, default: `true`)
19
20## Success Criteria
21
22- `@angular/pwa` is installed in dependencies.
23- PWA scaffolding exists (`manifest.webmanifest`, icons, `ngsw-config.json`).
24- Angular registers `ngsw-worker.js` correctly.
25- Build output includes service worker artifacts (`ngsw.json`, worker files).
26- App passes basic manual checks for installability and offline behavior.
27
28## Workflow
29
301. Validate workspace and Angular version
31- Confirm `package.json` and `angular.json` exist.
32- Confirm `@angular/core` major version is `20`.
33- Stop and report when the workspace is not Angular 20.
34
352. Resolve target Angular project
36- Read `angular.json` projects.
37- Use explicit `projectName` when provided.
38- If only one application project exists, use it automatically.
39- If multiple app projects exist and no target is given, ask for the project name.
40
413. Apply official PWA integration
42- Run the schematic non-interactively:
43```bash
44ng add @angular/pwa --project <projectName> --skip-confirmation
45```
46- Keep generated files unless the user explicitly requests customization.
47
484. Verify generated/updated files
49- Confirm presence of:
50- `<projectRoot>/ngsw-config.json`
51- `<sourceRoot>/manifest.webmanifest`
52- icon assets in `<sourceRoot>/icons` or configured public assets path
53- `<link rel="manifest" href="manifest.webmanifest">` in `<sourceRoot>/index.html`
54- `theme-color` meta tag in `<sourceRoot>/index.html`
55
565. Verify service worker registration wiring
57- For standalone bootstrap (preferred in Angular 20), ensure provider exists in `src/app/app.config.ts`:
58```ts
59provideServiceWorker('ngsw-worker.js', {
60 enabled: !isDevMode(),
61 registrationStrategy: 'registerWhenStable:30000'
62})
63```
64- For NgModule-based apps, ensure equivalent `ServiceWorkerModule.register(...)` wiring exists.
65- Keep production-safe default behavior: enabled only outside dev mode unless `enabledInDev=true`.
66- If `registrationStrategy` input is provided, verify registration uses that exact value.
67
686. Build and confirm artifacts
69- Run project build for the selected app:
70```bash
71ng build <projectName>
72```
73- Confirm service-worker artifacts are present in output (for example `ngsw.json` and `ngsw-worker.js`).
74
757. Verify runtime behavior over HTTP server
76- If `verifyRuntime=true`, serve the production output from a static server (not `file://`).
77- Open in Chrome and verify:
78- Application tab shows active service worker
79- Manifest is detected and installable
80- Offline toggle still loads cached app shell/routes
81
828. Apply minimal, safe customizations when requested
83- Only customize `ngsw-config.json` when user asks for explicit asset/data caching behavior.
84- Keep broad defaults first, then add targeted `assetGroups`/`dataGroups` rules.
85- Avoid overcaching API calls unless TTL/versioning strategy is defined.
86
879. Report deterministic completion output
88- Include:
89- selected `projectName`
90- files created or changed
91- registration wiring location (`app.config.ts` or module file)
92- build command run and artifact paths found
93- runtime verification result (or reason skipped)
94
95## Troubleshooting Rules
96
971. `ng add` fails
98- Confirm Angular CLI and workspace dependencies are consistent.
99- Re-run with explicit `--project` in multi-project repos.
100
1012. Service worker never activates
102- Confirm app is served from built output via HTTP(S), not `ng serve` in normal dev mode.
103- Confirm registration code exists and `enabled` evaluates to `true` in production.
104
1053. Offline mode does not work
106- Confirm `ngsw.json` exists in build output.
107- Inspect `ngsw-config.json` patterns and ensure the tested routes/assets are covered.
108
1094. App not installable
110- Confirm manifest fields/icons are valid and reachable.
111- Confirm HTTPS (or localhost), and no critical PWA warnings in DevTools.
112
113## Guardrails
114
115- Prefer schematic-generated defaults before manual edits.
116- Merge config changes; do not overwrite unrelated workspace settings.
117- Keep environment-aware service worker enablement (`!isDevMode()`) by default.
118- Validate with a real production build before declaring success.
119- If runtime verification cannot be executed (for example CI-only environment), explicitly mark as pending manual verification.
120
121## Definition of Done
122
123- `ng add @angular/pwa` has been applied successfully for the target app.
124- Manifest, icons, and service worker registration are present and valid.
125- Production build emits service worker artifacts.
126- Installability and basic offline behavior are verified.
127
128## References
129
130[1]: https://angular.dev/ecosystem/service-workers/getting-started
131[2]: https://angular.dev/ecosystem/service-workers/devops
132[3]: https://angular.dev/cli/add
133[4]: https://www.npmjs.com/package/@angular/pwa