Skip to content

Commit 19455d8

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 c51efda commit 19455d8

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, type SourceMapInput } from '@ampproject/remapping';
1010
import {
1111
type ɵParsedTranslation,
1212
ɵisMissingTranslationError,
@@ -156,6 +156,8 @@ const deserializedTranslations = new Map<string, Promise<Record<string, ɵParsed
156156
*/
157157
let currentGeneration: number | undefined;
158158

159+
let remapping: typeof import('@ampproject/remapping').default | undefined;
160+
159161
/**
160162
* Retrieves the file data for a filename, loading and extracting localization metadata.
161163
* If `cache` is true, the result is cached in `fileDataCache` across requests in this Worker.
@@ -557,6 +559,7 @@ async function inlineLocalize(
557559
includeContent: true,
558560
hires: 'boundary',
559561
});
562+
remapping ??= (await import('@ampproject/remapping')).default;
560563
outputMap = remapping([{ ...rawMap, version: 3 } satisfies DecodedSourceMap, map], () => null);
561564
}
562565

0 commit comments

Comments
 (0)