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 inangular.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
Thepackage.json includes several build and deployment scripts:
Development builds
Start the development server
Run the development server with live reload:The app will be available at
http://localhost:4200.Build in watch mode
For continuous builds during development:This rebuilds automatically when files change.
Production builds
Build for production
Create an optimized production build:This uses the production configuration by default.
Build configuration details
Theangular.json file configures production optimizations:
Production optimizations
Output hashing
Output hashing
All files get content-based hashes for cache busting:
main.a1b2c3d4.jsBundle budgets
Bundle budgets
Warnings trigger at 2MB, errors at 25MB for initial bundles to keep load times fast
Tree shaking
Tree shaking
Removes unused code to minimize bundle size
Minification
Minification
JavaScript and CSS are minified for smaller file sizes
Dead code elimination
Dead code elimination
Removes unreachable code paths
PWA configuration
The application includes Progressive Web App features configured inangular.json:
Service worker setup
The service worker enables offline functionality and caching:- Manifest file:
src/manifest.webmanifestdefines app metadata - Service worker config:
ngsw-config.jsoncontrols caching strategies - Assets: Static files are cached for offline use
Deployment to GitHub Pages
The project includes scripts for deploying to GitHub Pages usingangular-cli-ghpages.
Configure base href
The This builds with
_package script sets the correct base href for GitHub Pages:--base-href="/PWA_DEMO_ENV_PROD".Publish to GitHub Pages
Deploy the built application:This uses
angular-cli-ghpages to push the dist folder to the gh-pages branch.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
- Netlify
- Vercel
- Firebase
- Docker
Deploy to Netlify using drag-and-drop or CLI:netlify.toml configuration:
Environment configuration
For different environments, configure the base URLs insrc/assets/config/config.json:
Post-deployment verification
Test PWA features
- Open DevTools > Application > Service Workers
- Verify service worker is registered
- Test offline functionality
Troubleshooting
404 errors on route refresh
404 errors on route refresh
Configure server redirects to send all routes to
index.html. See platform-specific examples above.Assets not loading
Assets not loading
Verify the
base-href matches your deployment path. For GitHub Pages, it should match your repository name.Service worker not registering
Service worker not registering
Service workers require HTTPS in production. Check browser console for errors.
Bundle size too large
Bundle size too large
Review bundle budgets in
angular.json and consider lazy loading for large modules.Environment config not loading
Environment config not loading
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