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 build <project> [options]
    
ng b <project> [options]
      
      ng b <project> [options]
    

说明

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 --prod 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.

参数

参数说明
<project>

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

选项

选项说明
--aot=true|false

Build using Ahead of Time compilation.

默认值: 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.

默认值: false

--commonChunk=true|false

Use a separate bundle containing code used across multiple bundles.

默认值: 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.

别名: -c

--deleteOutputPath=true|false

Delete the output path before building.

默认值: true

--deployUrl=deployUrl

URL where files will be deployed.

--evalSourceMap=true|false

Output in-file eval sourcemaps.

默认值: false

--extractCss=true|false

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

默认值: false

--extractLicenses=true|false

Extract all licenses in a separate file.

默认值: false

--forkTypeChecker=true|false

Run the TypeScript type checker in a forked process.

默认值: true

--help=
true|false|json|JSON

Shows a help message for this command in the console.

默认值: 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

The name of the index HTML file.

--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.

默认值: true

--ngswConfigPath=ngswConfigPath

Path to ngsw-config.json.

--optimization=true|false

Enables optimization of the build output.

默认值: false

--outputHashing=
none|all|media|bundles

Define the output filename cache-busting hashing mode.

默认值: 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.

默认值: false

--prod=true|false

When true, sets the build configuration to the production target. All builds make use of bundling and limited tree-shaking. A production build also runs limited dead code elimination.

默认值: false

--profile=true|false

Output profile events for Chrome profiler.

默认值: false

--progress=true|false

Log progress to the console while building.

默认值: false

--resourcesOutputPath=
resourcesOutputPath

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

默认值:

--serviceWorker=true|false

Generates a service worker config for production builds.

默认值: false

--showCircularDependencies=true|false

Show circular dependency warnings on builds.

默认值: true

--skipAppShell=true|false

Flag to prevent building an app shell.

默认值: false

--sourceMap=true|false

Output sourcemaps.

默认值: true

--statsJson=true|false

Generates a 'stats.json' file which can be analyzed using tools such as: 'webpack-bundle-analyzer' or https://webpack.github.io/analyse.

默认值: false

--subresourceIntegrity=true|false

Enables the use of subresource integrity validation.

默认值: 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.

默认值: true

--vendorSourceMap=true|false

Resolve vendor packages sourcemaps.

默认值: false

--verbose=true|false

Adds more details to output logging.

默认值: false

--watch=true|false

Run build when files change.

默认值: false