← 返回命令列表

Linux command

ng-build 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Build for production

ng build --configuration production

Build with source maps

ng build --source-map

Build a specific project

ng build [project-name]

Watch mode

ng build --watch

Set output path

ng build --output-path [dist/custom]

Build with a custom base href

ng build --base-href [/my-app/]

Generate stats JSON

ng build --stats-json

Development build

ng build --configuration development

说明

ng build compiles an Angular application or library into an output directory. It handles TypeScript compilation, bundling, minification, tree-shaking, and other optimizations to produce deployment-ready artifacts. The application builder uses esbuild as the build tool. Default configuration options are specified in the workspace configuration file (angular.json) or can be overridden with a named alternative configuration. Command-line options override those set in angular.json. A "production" configuration with full optimizations is typically defined by default when creating a project with the CLI. A "development" configuration with faster builds and source maps is also available.

参数

-c, --configuration _name_
One or more named builder configurations (comma-separated), as defined in angular.json.
--source-map
Generate source maps for scripts and styles (default: false).
--watch
Rebuild on file changes (default: false).
--output-path _dir_
Output directory relative to workspace root.
--base-href _url_
Base URL for the application being built.
--aot
Build using Ahead of Time compilation (default: true).
--optimization
Enable optimization including minification, tree-shaking, and dead-code elimination (default: true).
--output-hashing _mode_
Cache-busting hashing mode: none, all, media, or bundles (default: none).
--delete-output-path
Delete the output path before building (default: true).
--stats-json
Generate a stats.json file for bundle analysis (default: false).
--progress
Log progress to the console while building (default: true).
--extract-licenses
Extract all licenses to a separate file (default: true).
--subresource-integrity
Enable subresource integrity validation (default: false).
--verbose
Add detailed output logging (default: false).
--named-chunks
Use file name for lazy loaded chunks (default: false).
--poll _ms_
File watching poll time period in milliseconds.
--ssr
Enable Server-Side Rendering at runtime (default: false).
--prerender
Enable Static Site Generation (prerendering) during build.
--help
Display help information.

FAQ

What is the ng-build command used for?

ng build compiles an Angular application or library into an output directory. It handles TypeScript compilation, bundling, minification, tree-shaking, and other optimizations to produce deployment-ready artifacts. The application builder uses esbuild as the build tool. Default configuration options are specified in the workspace configuration file (angular.json) or can be overridden with a named alternative configuration. Command-line options override those set in angular.json. A "production" configuration with full optimizations is typically defined by default when creating a project with the CLI. A "development" configuration with faster builds and source maps is also available.

How do I run a basic ng-build example?

Run `ng build --configuration production` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -c, --configuration _name_ do in ng-build?

One or more named builder configurations (comma-separated), as defined in angular.json.