Overview
Angular Bases uses the Angular CLI to build optimized production bundles with advanced optimization techniques including tree-shaking, minification, and dead code elimination.Building the Application
Production Build
dist/ directory.
The default build configuration is production as specified in
angular.json. Production builds include all optimizations by default.Build Configurations
The project supports two build configurations:Production Configuration
Optimized for deployment with:- Output hashing enabled for cache busting
- Bundle size budgets enforced
- Full optimization enabled
- License extraction enabled
- Source maps disabled
Development Configuration
Faster builds for development:- No optimization for faster builds
- Source maps enabled for debugging
- No license extraction
- No output hashing
Build Output
Output Directory
Builds are output to thedist/ directory with the following structure:
Output Hashing
Production builds include content hashes in filenames (e.g.,main-ABC123.js). This ensures:
- Browsers don’t cache old versions after deployments
- Unchanged files can remain cached
- Optimal cache performance
Bundle Size Budgets
The project enforces bundle size limits to prevent performance degradation:Initial Bundle Budget
- Warning: 500 kB
- Error: 1 MB
Component Style Budget
- Warning: 4 kB per component
- Error: 8 kB per component
Budgets are enforced only in production builds. If your build fails due to budget limits, consider:
- Lazy loading routes
- Splitting large components
- Optimizing images and assets
- Removing unused dependencies
Build Optimizations
Production builds automatically apply:Tree Shaking
Removes unused code from the final bundle. Only imports that are actually used are included.Minification
Compresses JavaScript and CSS:- Removes whitespace and comments
- Shortens variable names
- Optimizes syntax
Dead Code Elimination
Removes code that cannot be reached or executed.Ahead-of-Time (AOT) Compilation
Templates are compiled during the build process:- Faster rendering at runtime
- Smaller framework footprint
- Early detection of template errors
Build Process
Asset Processing
Static assets from
public/ are copied to the output directory.
Styles from src/styles.css are processed and bundled.Advanced Build Options
Source Maps
Generate source maps for production debugging:Source maps increase bundle size and expose your source code. Only use for debugging production issues.
Base Href
Set the base URL for the application:Stats JSON
Generate bundle statistics:stats.json for analysis with tools like webpack-bundle-analyzer.
Deployment Preparation
After building:Build Configuration Details
Fromangular.json, the build is configured with:
Assets Configuration
Files from thepublic/ directory are copied to the build output. Add additional assets by updating the assets array in angular.json.
Styles Configuration
Global styles fromsrc/styles.css are processed and bundled. Component-specific styles are automatically included from their respective component files.
Angular Bases uses the new
@angular/build:application builder (esbuild-based), which provides:- Faster build times
- Smaller bundle sizes
- Better tree-shaking
- Modern JavaScript output
Troubleshooting
Build Fails with Budget Errors
Reduce bundle size by:- Implementing lazy loading for routes
- Removing unused dependencies
- Optimizing images and assets
- Code splitting large features
TypeScript Errors
Check:tsconfig.app.jsonfor correct configuration- All imports are valid
- Type definitions are installed for third-party libraries
Missing Assets
Ensure assets are:- Located in the
public/directory - Referenced correctly in your code
- Listed in
angular.jsonassets array if from other locations
Next Steps
- Set up automated testing
- Learn about the project structure
- Configure development environment