Skip to content

Commit 41dec41

Browse files
committed
refactor(@angular/build): dynamically load @babel/core in transformer worker
By default, JavaScript transformations use the native OXC engine for Angular linking and advanced optimizations. The Babel-based linker is only utilized when the NG_BUILD_BABEL_LINKER environment variable is explicitly enabled. Previously, transformAsync was imported statically at the top level of javascript-transformer-worker.ts, causing Node.js to eagerly evaluate @babel/core and all its transitive dependencies on startup across every Piscina worker thread. Importing @babel/core dynamically only when the Babel linker fallback is active reduces worker thread startup latency and eliminates unnecessary worker idle memory overhead on standard builds.
1 parent ce83ac0 commit 41dec41

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

packages/angular/build/src/tools/esbuild/javascript-transformer-worker.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import remapping, { type DecodedSourceMap, type EncodedSourceMap } from '@ampproject/remapping';
10-
import { type PluginItem, transformAsync } from '@babel/core';
10+
import type { PluginItem } from '@babel/core';
1111
import { createRequire } from 'node:module';
1212
import { workerData } from 'node:worker_threads';
1313
import Piscina from 'piscina';
@@ -170,8 +170,12 @@ async function transformJavaScriptImpl(
170170
}
171171

172172
if (shouldLink && useBabelLinker) {
173-
const { createEs2015LinkerPlugin } = await import('@angular/compiler-cli/linker/babel');
174-
const { ConsoleLogger, LogLevel } = await import('@angular/compiler-cli');
173+
const [{ createEs2015LinkerPlugin }, { ConsoleLogger, LogLevel }, { transformAsync }] =
174+
await Promise.all([
175+
import('@angular/compiler-cli/linker/babel'),
176+
import('@angular/compiler-cli'),
177+
import('@babel/core'),
178+
]);
175179

176180
const result = await transformAsync(code, {
177181
filename,

0 commit comments

Comments
 (0)