Adding PWA to an Angular Project

Rounded avatar

Ehsan Shahrestani

Jun 1, 2025
Header image

Description

This guide provides step-by-step instructions on how to integrate Progressive Web App (PWA) support into an Angular project. It covers installation, configuration, testing, and deployment.

label

http://example.com

Prerequisites

  • Ensure you have Angular CLI installed.
  • Your Angular project should be on Angular 6+.

Step 1: Install Angular PWA

Run the following command in your Angular project directory:

ng add @angular/pwa

This command:

  • Adds the @angular/service-worker package.
  • Updates angular.json.
  • Creates a manifest.webmanifest file.
  • Updates index.html with necessary meta tags.
  • Adds service worker configuration.

Step 2: Build and Serve PWA

To enable the service worker, build the project in production mode:

ng build --configuration=production

Then, serve the project using a local HTTP server (Angular CLI’s ng serve does not work with service workers):

npx http-server -p 8080 -c-1 dist/YOUR_PROJECT_NAME

Replace YOUR_PROJECT_NAME with your actual project name.

Step 3: Verify PWA Features

  1. Open Chrome DevTools (F12 or Ctrl + Shift + I).
  2. Navigate to the Application tab.
  3. Check for:
    • Service Workers (should be registered and running).
    • Manifest (contains PWA metadata).
    • Lighthouse Audit (test PWA score).

Step 4: Enable PWA in Production

Ensure that your ngsw-config.json file is correctly configured:

{
  "index": "/index.html",
  "assetGroups": [
    {
      "name": "app",
      "installMode": "prefetch",
      "resources": {
        "files": ["/*.css", "/*.js"]
      }
    },
    {
      "name": "assets",
      "installMode": "lazy",
      "resources": {
        "files": ["/assets/**"]
      }
    }
  ]
}

Step 5: Deploy Your PWA

Deploy your Angular PWA http://example.com using Firebase, Netlify, Vercel, or any static hosting provider.

Firebase Deployment Example

  1. Install Firebase CLI:

    npm install -g firebase-tools
    
  2. Login to Firebase:

    firebase login
    
  3. Initialize Firebase Hosting:

    firebase init
    
  4. Deploy your PWA:

    firebase deploy
    

Conclusion

Your Angular app is now a PWA! It can work offline, be installed on devices, and provide a better user experience. 🎉