@@ -159,43 +159,51 @@ export class LocalizationPlugin implements Webpack.Plugin {
159159 return ;
160160 }
161161
162- const chunkFiles : string [ ] = chunkGroup . getFiles ( ) ;
163- for ( const chunkFileName of chunkFiles ) {
164- if (
165- chunkFileName . match ( Constants . LOCALE_FILENAME_PLACEHOLDER_REGEX ) && // Ensure this is expected to be localized
166- chunkFileName . endsWith ( '.js' ) && // Ensure this is a JS file
167- ! alreadyProcessedAssets . has ( chunkFileName ) // Ensure this isn't a vendor chunk we've already processed
168- ) {
169- alreadyProcessedAssets . add ( chunkFileName ) ;
170-
171- const asset : IAsset = compilation . assets [ chunkFileName ] ;
172- const resultingAssets : Map < string , IProcessAssetResult > = this . _processAsset (
173- compilation ,
174- chunkFileName ,
175- asset
176- ) ;
177-
178- // Delete the existing asset because it's been renamed
179- delete compilation . assets [ chunkFileName ] ;
180-
181- const localizedChunkAssets : { [ locale : string ] : string } = { } ;
182- for ( const [ locale , newAsset ] of resultingAssets ) {
183- compilation . assets [ newAsset . filename ] = newAsset . asset ;
184- localizedChunkAssets [ locale ] = newAsset . filename ;
185- }
162+ for ( const chunk of chunkGroup . chunks ) {
163+ // Clone the chunk files array because we're going to modify it
164+ const chunkFiles : string [ ] = [ ...chunk . files ] ;
165+ const chunkFilesSet : Set < string > = new Set ( chunkFiles ) ;
166+ for ( const chunkFileName of chunkFiles ) {
167+ if (
168+ chunkFileName . match ( Constants . LOCALE_FILENAME_PLACEHOLDER_REGEX ) && // Ensure this is expected to be localized
169+ chunkFileName . endsWith ( '.js' ) && // Ensure this is a JS file
170+ ! alreadyProcessedAssets . has ( chunkFileName ) // Ensure this isn't a vendor chunk we've already processed
171+ ) {
172+ alreadyProcessedAssets . add ( chunkFileName ) ;
173+
174+ const asset : IAsset = compilation . assets [ chunkFileName ] ;
175+ const resultingAssets : Map < string , IProcessAssetResult > = this . _processAsset (
176+ compilation ,
177+ chunkFileName ,
178+ asset
179+ ) ;
180+
181+ // Delete the existing asset because it's been renamed
182+ delete compilation . assets [ chunkFileName ] ;
183+ chunkFilesSet . delete ( chunkFileName ) ;
184+
185+ const localizedChunkAssets : { [ locale : string ] : string } = { } ;
186+ for ( const [ locale , newAsset ] of resultingAssets ) {
187+ compilation . assets [ newAsset . filename ] = newAsset . asset ;
188+ localizedChunkAssets [ locale ] = newAsset . filename ;
189+ chunkFilesSet . add ( newAsset . filename ) ;
190+ }
186191
187- if ( chunkGroup . getParents ( ) . length > 0 ) {
188- // This is a secondary chunk
189- localizationStats . namedChunkGroups [ chunkGroup . name ] = {
190- localizedAssets : localizedChunkAssets
191- } ;
192- } else {
193- // This is an entrypoint
194- localizationStats . entrypoints [ chunkGroup . name ] = {
195- localizedAssets : localizedChunkAssets
196- } ;
192+ if ( chunkGroup . getParents ( ) . length > 0 ) {
193+ // This is a secondary chunk
194+ localizationStats . namedChunkGroups [ chunkGroup . name ] = {
195+ localizedAssets : localizedChunkAssets
196+ } ;
197+ } else {
198+ // This is an entrypoint
199+ localizationStats . entrypoints [ chunkGroup . name ] = {
200+ localizedAssets : localizedChunkAssets
201+ } ;
202+ }
197203 }
198204 }
205+
206+ chunk . files = Array . from ( chunkFilesSet ) ;
199207 }
200208 }
201209
@@ -243,7 +251,7 @@ export class LocalizationPlugin implements Webpack.Plugin {
243251 const placeholderPrefix : string = Constants . STRING_PLACEHOLDER_PREFIX ;
244252 const placeholderRegex : RegExp = new RegExp (
245253 // The maximum length of quotemark escaping we can support is the length of the placeholder prefix
246- `${ lodash . escapeRegExp ( placeholderPrefix ) } _((?:.){1,${ placeholderPrefix . length } })_(\\d+)` ,
254+ `${ placeholderPrefix } _((?:.){1,${ placeholderPrefix . length } })_(\\d+)` ,
247255 'g'
248256 ) ;
249257 const result : Map < string , IProcessAssetResult > = new Map < string , IProcessAssetResult > ( ) ;
0 commit comments