ng build

Compiles an Angular app into an output directory named dist/ at the given output path. Must be executed from within a workspace directory.

ng build <project> [options]

ng b <project> [options]

Description

The command can be used to build a project of type "application" or "library". When used to build a library, a different builder is invoked, and only the ts-config, configuration, and watch options are applied. All other options apply only to building applications.

The application builder uses the webpack build tool, with default configuration options specified in the workspace configuration file (angular.json) or with a named alternative configuration. A "production" configuration is created by default when you use the CLI to create the project, and you can use that configuration by specifying the --configuration="production" or the --prod="true" option.

The configuration options generally correspond to the command options. You can override individual configuration defaults by specifying the corresponding options on the command line. The command can accept option names given in either dash-case or camelCase. Note that in the configuration file, you must specify names in camelCase.

Some additional options can only be set through the configuration file, either by direct editing or with the ng config command. These include assets, styles, and scripts objects that provide runtime-global resources to include in the project. Resources in CSS, such as images and fonts, are automatically written and fingerprinted at the root of the output folder.

For further details, see Workspace Configuration.

Arguments

Argument Description
<project>

The name of the project to build. Can be an application or a library.

Options

Option Description
--aot=true|false

Build using Ahead of Time compilation.

Default: false

--baseHref=baseHref

Base url for the application being built.

--buildEventLog=buildEventLog

EXPERIMENTAL Output file path for Build Event Protocol events

--buildOptimizer=true|false

Enables '@angular-devkit/build-optimizer' optimizations when using the 'aot' option.

Default: false

--commonChunk=true|false

Use a separate bundle containing code used across multiple bundles.

Default: true

--configuration=configuration

A named build target, as specified in the "configurations" section of angular.json. Each named target is accompanied by a configuration of option defaults for that target. Setting this explicitly overrides the "--prod" flag

Aliases: -c

--crossOrigin= none|anonymous|use-credentials

Define the crossorigin attribute setting of elements that provide CORS support.

Default: none

--deleteOutputPath=true|false

Delete the output path before building.

Default: true

--deployUrl=deployUrl

URL where files will be deployed.

--es5BrowserSupport=true|false

Deprecated: This will be determined from the list of supported browsers specified in the 'browserslist' file.

Enables conditionally loaded ES2015 polyfills.

--evalSourceMap=true|false

Deprecated

Output in-file eval sourcemaps.

Default: false

--extractCss=true|false

Extract css from global styles into css files instead of js ones.

Default: false

--extractLicenses=true|false

Extract all licenses in a separate file.

Default: false

--forkTypeChecker=true|false

Run the TypeScript type checker in a forked process.

Default: true

--help= true|false|json|JSON

Shows a help message for this command in the console.

Default: false

--i18nFile=i18nFile

Localization file to use for i18n.

--i18nFormat=i18nFormat

Format of the localization file specified with --i18n-file.

--i18nLocale=i18nLocale

Locale to use for i18n.

--i18nMissingTranslation= i18nMissingTranslation

How to handle missing translations for i18n.

--index=index

Configures the generation of the application's HTML index.

--lazyModules

List of additional NgModule files that will be lazy loaded. Lazy router modules will be discovered automatically.

--main=main

The full path for the main entry point to the app, relative to the current workspace.

--namedChunks=true|false

Use file name for lazy loaded chunks.

Default: true

--ngswConfigPath=ngswConfigPath

Path to ngsw-config.json.

--optimization=true|false

Enables optimization of the build output.

--outputHashing= none|all|media|bundles

Define the output filename cache-busting hashing mode.

Default: none

--outputPath=outputPath

The full path for the new output directory, relative to the current workspace.

By default, writes output to a folder named dist/ in the current project.

--poll

Enable and define the file watching poll time period in milliseconds.

--polyfills=polyfills

The full path for the polyfills file, relative to the current workspace.

--preserveSymlinks=true|false

Do not use the real path when resolving modules.

Default: false

--prod=true|false

Shorthand for "--configuration=production". When true, sets the build configuration to the production target. By default, the production target is set up in the workspace configuration such that all builds make use of bundling, limited tree-shaking, and also limited dead code elimination.

--profile=true|false

Deprecated: Use "NG_BUILD_PROFILING" environment variable instead.

Output profile events for Chrome profiler.

Default: false

--progress=true|false

Log progress to the console while building.

--rebaseRootRelativeCssUrls=true|false

Deprecated

Change root relative URLs in stylesheets to include base HREF and deploy URL. Use only for compatibility and transition. The behavior of this option is non-standard and will be removed in the next major release.

Default: false

--resourcesOutputPath= resourcesOutputPath

The path where style resources will be placed, relative to outputPath.

Default:

--serviceWorker=true|false

Generates a service worker config for production builds.

Default: false

--showCircularDependencies=true|false

Show circular dependency warnings on builds.

Default: true

--skipAppShell=true|false

Deprecated

Flag to prevent building an app shell.

Default: false

--sourceMap=true|false

Output sourcemaps.

Default: true

--statsJson=true|false

Generates a 'stats.json' file which can be analyzed using tools such as 'webpack-bundle-analyzer'.

Default: false

--subresourceIntegrity=true|false

Enables the use of subresource integrity validation.

Default: false

--tsConfig=tsConfig

The full path for the TypeScript configuration file, relative to the current workspace.

--vendorChunk=true|false

Use a separate bundle containing only vendor libraries.

Default: true

--vendorSourceMap=true|false

Deprecated

Resolve vendor packages sourcemaps.

Default: false

--verbose=true|false

Adds more details to output logging.

Default: false

--watch=true|false

Run build when files change.

Default: false

--webWorkerTsConfig= webWorkerTsConfig

TypeScript configuration for Web Worker modules.

© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v8.angular.io/cli/build