Skip to content

Commit 255cb72

Browse files
committed
refactor(@angular/build): lazy load sourcemap remapping in js transform worker
Previously, `@ampproject/remapping` was statically imported at the top level of `javascript-transformer-worker.ts`, eagerly pulling in 5 packages (`@ampproject/remapping` and 4 sub-dependencies) upon worker initialization. In standard Angular CLI configurations (`ng build` and `ng serve`), vendor sourcemaps are disabled by default (`thirdPartySourcemaps = false`), causing `useInputSourcemap` to evaluate to false for all transformed `node_modules` files. As a result, sourcemap remapping is never executed in typical builds.
1 parent 999d84c commit 255cb72

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import remapping, { type DecodedSourceMap, type EncodedSourceMap } from '@ampproject/remapping';
9+
import type { DecodedSourceMap, EncodedSourceMap } from '@ampproject/remapping';
1010
import type { PluginItem } from '@babel/core';
1111
import { createRequire } from 'node:module';
1212
import { workerData } from 'node:worker_threads';
@@ -52,6 +52,8 @@ let babelLinkerDeps:
5252
>
5353
| undefined;
5454

55+
let remapping: typeof import('@ampproject/remapping').default | undefined;
56+
5557
const textDecoder = new TextDecoder();
5658
const textEncoder = new TextEncoder();
5759

@@ -253,6 +255,7 @@ async function transformJavaScriptImpl(
253255
}
254256

255257
if (remappingChain.length > 0) {
258+
remapping ??= (await import('@ampproject/remapping')).default;
256259
const finalMap = remapping(remappingChain, () => null).toString();
257260
const base64Map = Buffer.from(finalMap).toString('base64');
258261
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`;

0 commit comments

Comments
 (0)