@@ -23,15 +23,16 @@ import * as fs from 'fs';
2323import * as path from 'path' ;
2424import { RawSourceMap , SourceMapConsumer , SourceMapGenerator } from 'source-map' ;
2525import { minify } from 'terser' ;
26- import { sources } from 'webpack' ;
2726import { workerData } from 'worker_threads' ;
2827import { allowMangle , allowMinify , shouldBeautify } from './environment-options' ;
2928import { I18nOptions } from './i18n-options' ;
3029
31- const { ConcatSource, OriginalSource, ReplaceSource, SourceMapSource } = sources ;
32-
3330type LocalizeUtilities = typeof import ( '@angular/localize/src/tools/src/source_file_utils' ) ;
3431
32+ // Lazy loaded webpack-sources object
33+ // Webpack is only imported if needed during the processing
34+ let webpackSources : typeof import ( 'webpack' ) . sources | undefined ;
35+
3536// If code size is larger than 500KB, consider lower fidelity but faster sourcemap merge
3637const FAST_SOURCEMAP_THRESHOLD = 500 * 1024 ;
3738
@@ -215,9 +216,14 @@ async function mergeSourceMaps(
215216 return mergeSourceMapsFast ( inputSourceMap , resultSourceMap ) ;
216217 }
217218
219+ // Load Webpack only when needed
220+ if ( webpackSources === undefined ) {
221+ webpackSources = ( await import ( 'webpack' ) ) . sources ;
222+ }
223+
218224 // SourceMapSource produces high-quality sourcemaps
219225 // Final sourcemap will always be available when providing the input sourcemaps
220- const finalSourceMap = new SourceMapSource (
226+ const finalSourceMap = new webpackSources . SourceMapSource (
221227 resultCode ,
222228 filename ,
223229 resultSourceMap ,
@@ -726,6 +732,12 @@ async function inlineLocalesDirect(ast: ParseResult, options: InlineOptions) {
726732 delete inputMap . sourceRoot ;
727733 }
728734
735+ // Load Webpack only when needed
736+ if ( webpackSources === undefined ) {
737+ webpackSources = ( await import ( 'webpack' ) ) . sources ;
738+ }
739+ const { ConcatSource, OriginalSource, ReplaceSource, SourceMapSource } = webpackSources ;
740+
729741 for ( const locale of i18n . inlineLocales ) {
730742 const content = new ReplaceSource (
731743 inputMap
@@ -752,12 +764,12 @@ async function inlineLocalesDirect(ast: ParseResult, options: InlineOptions) {
752764 content . replace ( position . start , position . end - 1 , code ) ;
753765 }
754766
755- let outputSource : sources . Source = content ;
767+ let outputSource : import ( 'webpack' ) . sources . Source = content ;
756768 if ( options . setLocale ) {
757769 const setLocaleText = `var $localize=Object.assign(void 0===$localize?{}:$localize,{locale:"${ locale } "});\n` ;
758770
759771 // If locale data is provided, load it and prepend to file
760- let localeDataSource : sources . Source | null = null ;
772+ let localeDataSource ;
761773 const localeDataPath = i18n . locales [ locale ] && i18n . locales [ locale ] . dataPath ;
762774 if ( localeDataPath ) {
763775 const localeDataContent = await loadLocaleData ( localeDataPath , true , options . es5 ) ;
0 commit comments