ng-build
TLDR
Build an Angular application or library
Specify the output path relative to the workspace root
Enable Ahead-of-Time (AOT) compilation
Show build progress in the console
Display additional verbose output during the build
Automatically clear the terminal screen during rebuilds
Rebuild automatically when source files change
SYNOPSIS
ng build [options]
PARAMETERS
--aot
Builds using AOT compilation
--base-href <path>
Base URL for the application
--build-optimizer
Enables @angular-build-optimizer
--configuration <name>
Configuration name from angular.json (e.g., production)
--output-hashing <mode>
Hash bundles (none|all|media)
--output-path <path>
Output directory path
--optimization
Enables optimization (default: true in prod)
--poll <ms>
Enable polling for watch mode
--prod
Deprecated alias for --configuration production
--source-map
Output source maps
--stats-json
Generates webpack stats JSON
--verbose
Enable verbose logging
--watch
Rebuilds on file changes
DESCRIPTION
The ng build command compiles an Angular application into an output directory that can be served to end-users. By default, it generates a dist/ folder with optimized, production-ready files including HTML, CSS, JavaScript bundles, and assets.
It performs Ahead-of-Time (AOT) compilation, tree-shaking, minification, and other optimizations to minimize bundle sizes and improve load times. Development builds are faster but larger; production builds prioritize performance.
Supports multiple configurations via angular.json, such as 'production' for optimizations or 'development' for source maps. Use with CI/CD pipelines for automated deployments. Requires Angular CLI installed globally or via npx.
CAVEATS
Requires Node.js and Angular CLI installed. Large apps may take time to build. Deprecated options like --prod may be removed in future versions.
ANGULAR.JSON CONFIG
Primary configuration file for build options, targets, and environments.
Use ng build --configuration=production for optimized builds.
OUTPUT
Default: dist/project-name. Serve with any static server (e.g., nginx, Apache).
HISTORY
Introduced with Angular CLI v1.0 (2016). Evolved with Angular updates; v6+ deprecated --prod in favor of configurations. Supports modern ES builds and Ivy renderer since Angular 9.


