@@ -23,15 +23,16 @@ import * as fs from 'fs';
23
23
import * as path from 'path' ;
24
24
import { RawSourceMap , SourceMapConsumer , SourceMapGenerator } from 'source-map' ;
25
25
import { minify } from 'terser' ;
26
- import { sources } from 'webpack' ;
27
26
import { workerData } from 'worker_threads' ;
28
27
import { allowMangle , allowMinify , shouldBeautify } from './environment-options' ;
29
28
import { I18nOptions } from './i18n-options' ;
30
29
31
- const { ConcatSource, OriginalSource, ReplaceSource, SourceMapSource } = sources ;
32
-
33
30
type LocalizeUtilities = typeof import ( '@angular/localize/src/tools/src/source_file_utils' ) ;
34
31
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
+
35
36
// If code size is larger than 500KB, consider lower fidelity but faster sourcemap merge
36
37
const FAST_SOURCEMAP_THRESHOLD = 500 * 1024 ;
37
38
@@ -215,9 +216,14 @@ async function mergeSourceMaps(
215
216
return mergeSourceMapsFast ( inputSourceMap , resultSourceMap ) ;
216
217
}
217
218
219
+ // Load Webpack only when needed
220
+ if ( webpackSources === undefined ) {
221
+ webpackSources = ( await import ( 'webpack' ) ) . sources ;
222
+ }
223
+
218
224
// SourceMapSource produces high-quality sourcemaps
219
225
// Final sourcemap will always be available when providing the input sourcemaps
220
- const finalSourceMap = new SourceMapSource (
226
+ const finalSourceMap = new webpackSources . SourceMapSource (
221
227
resultCode ,
222
228
filename ,
223
229
resultSourceMap ,
@@ -726,6 +732,12 @@ async function inlineLocalesDirect(ast: ParseResult, options: InlineOptions) {
726
732
delete inputMap . sourceRoot ;
727
733
}
728
734
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
+
729
741
for ( const locale of i18n . inlineLocales ) {
730
742
const content = new ReplaceSource (
731
743
inputMap
@@ -752,12 +764,12 @@ async function inlineLocalesDirect(ast: ParseResult, options: InlineOptions) {
752
764
content . replace ( position . start , position . end - 1 , code ) ;
753
765
}
754
766
755
- let outputSource : sources . Source = content ;
767
+ let outputSource : import ( 'webpack' ) . sources . Source = content ;
756
768
if ( options . setLocale ) {
757
769
const setLocaleText = `var $localize=Object.assign(void 0===$localize?{}:$localize,{locale:"${ locale } "});\n` ;
758
770
759
771
// If locale data is provided, load it and prepend to file
760
- let localeDataSource : sources . Source | null = null ;
772
+ let localeDataSource ;
761
773
const localeDataPath = i18n . locales [ locale ] && i18n . locales [ locale ] . dataPath ;
762
774
if ( localeDataPath ) {
763
775
const localeDataContent = await loadLocaleData ( localeDataPath , true , options . es5 ) ;
0 commit comments