@@ -239,36 +239,14 @@ export class LocalizationPlugin implements Webpack.Plugin {
239
239
return ;
240
240
}
241
241
242
- // First pass - see if the chunk directly contains any loc modules
243
242
for ( const chunk of chunks ) {
244
- let chunkHasAnyLocModules : boolean = false ;
245
- if ( ! chunkHasAnyLocModules ) {
246
- for ( const module of chunk . getModules ( ) ) {
247
- if ( EntityMarker . getMark ( module ) ) {
248
- chunkHasAnyLocModules = true ;
249
- break ;
250
- }
251
- }
252
- }
253
-
254
- EntityMarker . markEntity ( chunk , chunkHasAnyLocModules ) ;
255
- }
256
-
257
- // Second pass - see if the chunk loads any localized chunks
258
- for ( const chunk of chunks ) {
259
- let localizedChunk : boolean = EntityMarker . getMark ( chunk ) ;
260
- if (
261
- ! localizedChunk &&
262
- Array . from ( chunk . getAllAsyncChunks ( ) ) . some ( ( asyncChunk ) => EntityMarker . getMark ( asyncChunk ) )
263
- ) {
264
- localizedChunk = true ;
265
- EntityMarker . markEntity ( chunk , true ) ;
266
- }
243
+ // See if the chunk contains any localized modules or loads any localized chunks
244
+ const localizedChunk : boolean = this . _chunkHasLocalizedModules ( chunk ) ;
267
245
246
+ // Change the chunk's name to include either the locale name or the locale name for chunks without strings
268
247
const replacementValue : string = localizedChunk
269
248
? Constants . LOCALE_NAME_PLACEHOLDER
270
249
: this . _noStringsLocaleName ;
271
- EntityMarker . markEntity ( chunk , localizedChunk ) ;
272
250
if ( chunk . hasRuntime ( ) ) {
273
251
chunk . filenameTemplate = ( compilation . options . output ! . filename as string ) . replace (
274
252
Constants . LOCALE_FILENAME_PLACEHOLDER_REGEX ,
@@ -314,7 +292,7 @@ export class LocalizationPlugin implements Webpack.Plugin {
314
292
}
315
293
}
316
294
317
- if ( EntityMarker . getMark ( chunk ) ) {
295
+ if ( this . _chunkHasLocalizedModules ( chunk ) ) {
318
296
processChunkJsFile ( ( chunkFilename ) => {
319
297
if ( chunkFilename . indexOf ( Constants . LOCALE_NAME_PLACEHOLDER ) === - 1 ) {
320
298
throw new Error ( `Asset ${ chunkFilename } is expected to be localized, but is missing a locale placeholder` ) ;
@@ -655,4 +633,31 @@ export class LocalizationPlugin implements Webpack.Plugin {
655
633
suffix : suffix
656
634
} ;
657
635
}
636
+
637
+ private _chunkHasLocalizedModules ( chunk : Webpack . compilation . Chunk ) : boolean {
638
+ if ( EntityMarker . getMark ( chunk ) === undefined ) {
639
+ let chunkHasAnyLocModules : boolean = false ;
640
+ if ( ! chunkHasAnyLocModules ) {
641
+ for ( const module of chunk . getModules ( ) ) {
642
+ if ( EntityMarker . getMark ( module ) ) {
643
+ chunkHasAnyLocModules = true ;
644
+ break ;
645
+ }
646
+ }
647
+ }
648
+
649
+ if ( ! chunkHasAnyLocModules ) {
650
+ for ( const asyncChunk of chunk . getAllAsyncChunks ( ) ) {
651
+ if ( this . _chunkHasLocalizedModules ( asyncChunk ) ) {
652
+ chunkHasAnyLocModules = true ;
653
+ break ;
654
+ }
655
+ }
656
+ }
657
+
658
+ EntityMarker . markEntity ( chunk , chunkHasAnyLocModules ) ;
659
+ }
660
+
661
+ return EntityMarker . getMark ( chunk ) ! ;
662
+ }
658
663
}
0 commit comments