Skip to content

Commit b07ba1a

Browse files
clydinalan-agius4
authored andcommitted
refactor(@angular-devkit/build-angular): remove usage of terser constants in esbuild
The terser build time constant import from the `@angular/compiler-cli` package is no longer used in the esbuild-based builder. The constants present are already defined and conditionally added within the build configuration itself. This not only provides more flexibility but also removes the need to import the package early in the process. The import is also an expensive import due to it needing TypeScript and being ESM that needs to be dynamically imported via a function helper to work around current ESM/TypeScript/CommonJS limitations.
1 parent c9ce423 commit b07ba1a

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

packages/angular_devkit/build_angular/src/tools/esbuild/angular/compiler-plugin.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,9 @@ export function createCompilerPlugin(
114114
// Initialize a worker pool for JavaScript transformations
115115
const javascriptTransformer = new JavaScriptTransformer(pluginOptions, maxWorkers);
116116

117-
// Setup defines based on the values provided by the Angular compiler-cli
118-
const { GLOBAL_DEFS_FOR_TERSER_WITH_AOT } = await AngularCompilation.loadCompilerCli();
117+
// Setup defines based on the values used by the Angular compiler-cli
119118
build.initialOptions.define ??= {};
120-
for (const [key, value] of Object.entries(GLOBAL_DEFS_FOR_TERSER_WITH_AOT)) {
121-
if (key in build.initialOptions.define) {
122-
// Skip keys that have been manually provided
123-
continue;
124-
}
125-
if (key === 'ngDevMode') {
126-
// ngDevMode is already set based on the builder's script optimization option
127-
continue;
128-
}
129-
// esbuild requires values to be a string (actual strings need to be quoted).
130-
// In this case, all provided values are booleans.
131-
build.initialOptions.define[key] = value.toString();
132-
}
119+
build.initialOptions.define['ngI18nClosureMode'] ??= 'false';
133120

134121
// The in-memory cache of TypeScript file outputs will be used during the build in `onLoad` callbacks for TS files.
135122
// A string value indicates direct TS/NG output and a Uint8Array indicates fully transformed code.

0 commit comments

Comments
 (0)