mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 11:03:53 +08:00
The `application` builder now supports a new option named `define`. This option allows global identifiers present in the code to be replaced with another value at build time. This is similar to the behavior of Webpack's `DefinePlugin` which was previously used with some custom Webpack configurations that used third-party builders. The option has similar capabilities to the `esbuild` option of the same name. The documentation for that option can be found here: https://esbuild.github.io/api/#define The command line capabilities of the Angular CLI option are not yet implemented and will added in a future change. The option within the `angular.json` configuration file is of the form of an object. The keys of the object represent the global identifier to replace and the values of the object represent the corresponding replacement value for the identifier. An example is as follows: ``` "define": { "SOME_CONSTANT": "5", "ANOTHER": "'this is a string literal'" } ``` All replacement values are defined as strings within the configuration file. If the replacement is intended to be an actual string literal, it should be enclosed in single quote marks. This allows the flexibility of using any valid JSON type as well as a different identifier as a replacement. Additionally, TypeScript needs to be aware of the module type for the import to prevent type-checking errors during the build. This can be accomplished with an additional type definition file within the application source code (`src/types.d.ts`, for example) with the following or similar content: ``` declare const SOME_CONSTANT: number; declare const ANOTHER: string; ``` The default project configuration is already setup to use any type definition files present in the project source directories. If the TypeScript configuration for the project has been altered, the tsconfig may need to be adjusted to reference this newly added type definition file. An important caveat to the option is that it does not function when used with values contained within Angular metadata such as a Component or Directive decorator. This limitation was present with previous third-party builder usage as well.
@angular-devkit/build-angular
This package contains Architect builders used to build and test Angular applications and libraries.
Builders
Name | Description |
---|---|
application | Build an Angular application targeting a browser and server environment using esbuild. |
app-shell | Build an Angular App shell. |
browser | Build an Angular application targeting a browser environment using Webpack. |
browser-esbuild | Build an Angular application targeting a browser environment using esbuild. |
dev-server | A development server that provides live reloading. |
extract-i18n | Extract i18n messages from an Angular application. |
karma | Execute unit tests using Karma test runner. |
ng-packagr | Build and package an Angular library in Angular Package Format (APF) format using ng-packagr. |
prerender | Prerender pages of your application. Prerendering is the process where a dynamic page is processed at build time generating static HTML. |
server | Build an Angular application targeting a Node.js environment. |
ssr-dev-server | A development server which offers live reload during development, but uses server-side rendering. |
protractor | Deprecated - Run end-to-end tests using Protractor framework. |
Disclaimer
While the builders when executed via the Angular CLI and their associated options are considered stable, the programmatic APIs are not considered officially supported and are not subject to the breaking change guarantees of SemVer.