LinuxCommandLibrary

ng-build

TLDR

Build an Angular application or library

$ ng [[b|build]]
copy

Specify the output path relative to the workspace root
$ ng [[b|build]] --output-path [path/to/directory]
copy

Enable Ahead-of-Time (AOT) compilation
$ ng [[b|build]] --aot
copy

Show build progress in the console
$ ng [[b|build]] --progress
copy

Display additional verbose output during the build
$ ng [[b|build]] --verbose
copy

Automatically clear the terminal screen during rebuilds
$ ng [[b|build]] --clear-screen
copy

Rebuild automatically when source files change
$ ng [[b|build]] --watch
copy

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.

SEE ALSO

ng serve(1), ng generate(1), npm(1)

Copied to clipboard