mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-20 05:24:57 +08:00
When optimizing a CommonJS exported enum, the build optimizer enum wrapping pass was previously dropping the `exports` object assignment from the enum wrapper function call expression. This would not occur with application code but is possible with library code that was built with TypeScript and shipped as CommonJS. Assuming the following TypeScript enum: ``` export enum ChangeDetectionStrategy { OnPush = 0, Default = 1, } ``` TypeScript 5.1 will emit an exported enum for CommonJS as follows: ``` exports.ChangeDetectionStrategy = void 0; var ChangeDetectionStrategy; (function (ChangeDetectionStrategy) { ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 0] = "OnPush"; ChangeDetectionStrategy[ChangeDetectionStrategy["Default"] = 1] = "Default"; })(ChangeDetectionStrategy || (exports.ChangeDetectionStrategy = ChangeDetectionStrategy = {})); ``` The build optimizer would previously transform this into: ``` exports.ChangeDetectionStrategy = void 0; var ChangeDetectionStrategy = /*#__PURE__*/ (() => { ChangeDetectionStrategy = ChangeDetectionStrategy || {}; ChangeDetectionStrategy[(ChangeDetectionStrategy["OnPush"] = 5)] = "OnPush"; ChangeDetectionStrategy[(ChangeDetectionStrategy["Default"] = 8)] = "Default"; return ChangeDetectionStrategy; })(); ``` But this has a defect wherein the `exports` assignment is dropped. To rectify this situation, the build optimizer will now transform the code into: ``` exports.ChangeDetectionStrategy = void 0; var ChangeDetectionStrategy = /*#__PURE__*/ (function (ChangeDetectionStrategy) { ChangeDetectionStrategy[(ChangeDetectionStrategy["OnPush"] = 0)] = "OnPush"; ChangeDetectionStrategy[(ChangeDetectionStrategy["Default"] = 1)] = "Default"; return ChangeDetectionStrategy; })(ChangeDetectionStrategy || (exports.ChangeDetectionStrategy = ChangeDetectionStrategy = {})) ``` This retains the `exports` assignment.
@angular-devkit/build-angular
This package contains Architect builders used to build and test Angular applications and libraries.
Builders
Name | Description |
---|---|
app-shell | Build an Angular App shell. |
browser | Build an Angular application targeting a browser environment. |
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. |
server | Build an Angular application targeting a Node.js environment. |
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.