Skip to content

Commit 9bc35b1

Browse files
committed
refactor(@angular/build): lazy load sourcemap remapping in i18n inliner worker
Previously, `@ampproject/remapping` was statically imported at the top level of `i18n-inliner-worker.ts`, eagerly pulling in 5 packages (`@ampproject/remapping` and 4 sub-dependencies) upon worker initialization. In typical workflows or when sourcemaps are not requested for inlining, remapping is never executed. This changes the import of `@ampproject/remapping` to be dynamic so that it is only loaded when a file actually requires sourcemap remapping.
1 parent 36bdd84 commit 9bc35b1

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎packages/angular/build/src/tools/i18n/i18n-inliner-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 SourceMapInput } from '@ampproject/remapping';
9+
import type { DecodedSourceMap, SourceMapInput } from '@ampproject/remapping';
1010
import type { ɵParsedTranslation } from '@angular/localize';
1111
import { MagicString } from 'magic-string';
1212
import { deserialize } from 'node:v8';
@@ -151,6 +151,8 @@ const deserializedTranslations = new Map<string, Promise<Record<string, ɵParsed
151151
*/
152152
let currentGeneration: number | undefined;
153153

154+
let remapping: typeof import('@ampproject/remapping').default | undefined;
155+
154156
/**
155157
* Retrieves the file data for a filename, loading and extracting localization metadata.
156158
* If `cache` is true, the result is cached in `fileDataCache` across requests in this Worker.
@@ -542,6 +544,7 @@ async function inlineLocalize(
542544
includeContent: true,
543545
hires: 'boundary',
544546
});
547+
remapping ??= (await import('@ampproject/remapping')).default;
545548
outputMap = remapping([{ ...rawMap, version: 3 } satisfies DecodedSourceMap, map], () => null);
546549
}
547550

0 commit comments

Comments
 (0)