Skip to main content

Overview

This guide covers building, packaging, and deploying the Angular PWA Demo application. The project includes production-optimized build configurations and automated deployment scripts.

Build configurations

The application uses Angular’s build system configured in angular.json with optimizations for production.

Available build modes

Development

Unoptimized build with source maps and debugging enabled

Production

Optimized build with minification, tree-shaking, and output hashing

Build scripts

The package.json includes several build and deployment scripts:
{
  "scripts": {
    "start": "ng serve --disable-host-check",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "_package": "ng build --c=production --base-href=\"/PWA_DEMO_ENV_PROD\"",
    "_publish": "npx ngh --dir=dist\\PWA_DEMO_ENV_PROD\\browser",
    "package-and-publish": "ng build --c=production --base-href=\"/PWA_DEMO_ENV_PROD/\" && npx ngh --dir=dist\\PWA_DEMO_ENV_PROD\\browser"
  }
}

Development builds

1

Start the development server

Run the development server with live reload:
npm start
The app will be available at http://localhost:4200.
2

Build in watch mode

For continuous builds during development:
npm run watch
This rebuilds automatically when files change.
3

Build for development

Create a development build without watch mode:
npm run build -- --configuration development
The --disable-host-check flag in the start script allows access from different hostnames, useful for testing on mobile devices.

Production builds

1

Build for production

Create an optimized production build:
npm run build
This uses the production configuration by default.
2

Verify the build

Check the output in the dist/PWA_DEMO_ENV_PROD/browser directory:
ls -la dist/PWA_DEMO_ENV_PROD/browser
3

Test the production build locally

Serve the production build using a static server:
npx http-server dist/PWA_DEMO_ENV_PROD/browser -p 8080

Build configuration details

The angular.json file configures production optimizations:
{
  "configurations": {
    "production": {
      "budgets": [
        {
          "type": "initial",
          "maximumWarning": "2mb",
          "maximumError": "25mb"
        },
        {
          "type": "anyComponentStyle",
          "maximumWarning": "5mb",
          "maximumError": "5mb"
        }
      ],
      "outputHashing": "all"
    },
    "development": {
      "optimization": false,
      "extractLicenses": false,
      "sourceMap": true,
      "namedChunks": true
    }
  }
}

Production optimizations

All files get content-based hashes for cache busting: main.a1b2c3d4.js
Warnings trigger at 2MB, errors at 25MB for initial bundles to keep load times fast
Removes unused code to minimize bundle size
JavaScript and CSS are minified for smaller file sizes
Removes unreachable code paths
The bundle size limit is set to 25MB to accommodate Three.js and other large dependencies. Consider code splitting for larger applications.

PWA configuration

The application includes Progressive Web App features configured in angular.json:
{
  "assets": [
    "src/favicon.ico",
    "src/assets",
    "src/manifest.webmanifest"
  ],
  "serviceWorker": "ngsw-config.json"
}

Service worker setup

The service worker enables offline functionality and caching:
  1. Manifest file: src/manifest.webmanifest defines app metadata
  2. Service worker config: ngsw-config.json controls caching strategies
  3. Assets: Static files are cached for offline use
Service workers only work over HTTPS in production. Use localhost for development testing.

Deployment to GitHub Pages

The project includes scripts for deploying to GitHub Pages using angular-cli-ghpages.
1

Configure base href

The _package script sets the correct base href for GitHub Pages:
npm run _package
This builds with --base-href="/PWA_DEMO_ENV_PROD".
2

Publish to GitHub Pages

Deploy the built application:
npm run _publish
This uses angular-cli-ghpages to push the dist folder to the gh-pages branch.
3

One-command deployment

Build and deploy in a single command:
npm run package-and-publish

GitHub Pages configuration

The deployment uses the following settings:
  • Base href: /PWA_DEMO_ENV_PROD/ (matches repository name)
  • Output directory: dist/PWA_DEMO_ENV_PROD/browser
  • Branch: gh-pages (created automatically)

Deployment to other platforms

Deploy to Netlify using drag-and-drop or CLI:
# Build the app
npm run build

# Install Netlify CLI
npm install -g netlify-cli

# Deploy
netlify deploy --prod --dir=dist/PWA_DEMO_ENV_PROD/browser
netlify.toml configuration:
[build]
  publish = "dist/PWA_DEMO_ENV_PROD/browser"
  command = "npm run build"

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

Environment configuration

For different environments, configure the base URLs in src/assets/config/config.json:
{
  "appBrand": "Angular PWA Demo",
  "appVersion": "1.0.0",
  "baseUrlNetCore": "https://api.production.com/",
  "baseUrlNodeJs": "https://nodejs-api.production.com/",
  "baseUrlSpringBootJava": "https://java-api.production.com/",
  "baseUrlDjangoPython": "https://python-api.production.com/"
}
Never commit sensitive API keys or credentials to the repository. Use environment variables or secure secret management.

Post-deployment verification

1

Check application loads

Navigate to your deployment URL and verify the app loads correctly.
2

Test PWA features

  • Open DevTools > Application > Service Workers
  • Verify service worker is registered
  • Test offline functionality
3

Verify routing

Test navigation between routes and ensure deep links work.
4

Check performance

Run Lighthouse audit in Chrome DevTools for performance metrics.
5

Test on mobile

Verify the app works on mobile devices and can be installed as a PWA.

Troubleshooting

Configure server redirects to send all routes to index.html. See platform-specific examples above.
Verify the base-href matches your deployment path. For GitHub Pages, it should match your repository name.
Service workers require HTTPS in production. Check browser console for errors.
Review bundle budgets in angular.json and consider lazy loading for large modules.
Ensure config.json is included in the assets array in angular.json.

Next steps

Configuration guide

Learn about application configuration

Components guide

Build custom components

Build docs developers (and LLMs) love