@@ -166,12 +166,6 @@ export class LocalizationPlugin implements Webpack.Plugin {
166166 return ;
167167 }
168168
169- function tryInstallPreprocessor ( ) : void {
170- if ( typingsPreprocessor ) {
171- compiler . hooks . beforeRun . tap ( PLUGIN_NAME , ( ) => typingsPreprocessor ! . generateTypings ( ) ) ;
172- }
173- }
174-
175169 if ( isWebpackDevServer ) {
176170 if ( typingsPreprocessor ) {
177171 compiler . hooks . watchRun . tap ( PLUGIN_NAME , ( ) => typingsPreprocessor ! . runWatcher ( ) ) ;
@@ -185,7 +179,9 @@ export class LocalizationPlugin implements Webpack.Plugin {
185179
186180 WebpackConfigurationUpdater . amendWebpackConfigurationForInPlaceLocFiles ( webpackConfigurationUpdaterOptions ) ;
187181 } else {
188- tryInstallPreprocessor ( ) ;
182+ if ( typingsPreprocessor ) {
183+ compiler . hooks . beforeRun . tap ( PLUGIN_NAME , ( ) => typingsPreprocessor ! . generateTypings ( ) ) ;
184+ }
189185
190186 WebpackConfigurationUpdater . amendWebpackConfigurationForMultiLocale ( webpackConfigurationUpdaterOptions ) ;
191187
@@ -235,10 +231,9 @@ export class LocalizationPlugin implements Webpack.Plugin {
235231 return ;
236232 }
237233
234+ // First pass - see if the chunk directly contains any loc modules
238235 for ( const chunk of chunks ) {
239- let chunkHasAnyLocModules : boolean = Array . from ( chunk . getAllAsyncChunks ( ) ) . some (
240- ( asyncChunk ) => EntityMarker . getMark ( asyncChunk )
241- ) ;
236+ let chunkHasAnyLocModules : boolean = false ;
242237 if ( ! chunkHasAnyLocModules ) {
243238 for ( const module of chunk . getModules ( ) ) {
244239 if ( EntityMarker . getMark ( module ) ) {
@@ -248,10 +243,24 @@ export class LocalizationPlugin implements Webpack.Plugin {
248243 }
249244 }
250245
251- const replacementValue : string = chunkHasAnyLocModules
246+ EntityMarker . markEntity ( chunk , chunkHasAnyLocModules ) ;
247+ }
248+
249+ // Second pass - see if the chunk loads any localized chunks
250+ for ( const chunk of chunks ) {
251+ let localizedChunk : boolean = EntityMarker . getMark ( chunk ) ;
252+ if (
253+ ! localizedChunk &&
254+ Array . from ( chunk . getAllAsyncChunks ( ) ) . some ( ( asyncChunk ) => EntityMarker . getMark ( asyncChunk ) )
255+ ) {
256+ localizedChunk = true ;
257+ EntityMarker . markEntity ( chunk , true ) ;
258+ }
259+
260+ const replacementValue : string = localizedChunk
252261 ? Constants . LOCALE_NAME_PLACEHOLDER
253262 : this . _noStringsLocaleName ;
254- EntityMarker . markEntity ( chunk , chunkHasAnyLocModules ) ;
263+ EntityMarker . markEntity ( chunk , localizedChunk ) ;
255264 if ( chunk . hasRuntime ( ) ) {
256265 chunk . filenameTemplate = ( compilation . options . output ! . filename as string ) . replace (
257266 Constants . LOCALE_FILENAME_PLACEHOLDER_REGEX ,
0 commit comments