PWA workflow

Initialize the Service Worker and progressive web app capabilities.

Add the service worker package

In your app's package.json add the latest Angular service worker package:

    "@angular/service-worker": "^15.2.0",

Run npm i to install the package.

Update the application Index

path: apps\{{project}}\src\index.html

Add the following directly before the head closing tag

Add the web manifest file

Create a manifest.webmanifest file at the following location:

apps\{{project}}\src\manifest.webmanifest

Add the following code:

Add the web ngsw-config file

Create a ngsw-config.json file at the following location:

apps\{{project}}\src\ngsw-config.json

Add the following code:

Update the application project.json

  • Add the manifest.webmanifest to the project assets

  • Add the "serviceWorker": true, to the project options

  • Add the "ngswConfigPath": "apps/{{project}}/src/ngsw-config.json" to the project options

Update the application module

Update the app.module file to include the following:

Add required icon assets

Add the required icon assets to the following location:

apps\{{project}}\src\assets\icons

Required icons:

  • icon-72x72.png

  • icon-96x96.png

  • icon-128x128.png

  • icon-144x144.png

  • icon-152x152.png

  • icon-192x192.png

  • icon-384x384.png

  • icon-512x512.png

Angular service worker documenation

Officical Angular documentation: https://angular.io/guide/service-worker-intro

The steps in this guide are provided for easy service worker implementation in a NX monorepo architecture. The Angular guide does not document the required considerations and as a result cannot be added automatically with the ng add command.

Last updated