@@ -84,13 +84,17 @@ export class LocalizationPlugin implements Webpack.Plugin {
8484 throw new Error ( 'The localization plugin requires webpack 4' ) ;
8585 }
8686
87+ // https://github.com/webpack/webpack-dev-server/pull/1929/files#diff-15fb51940da53816af13330d8ce69b4eR66
88+ const isWebpackDevServer : boolean = process . env . WEBPACK_DEV_SERVER === 'true' ;
89+
8790 const errors : Error [ ] = this . _initializeAndValidateOptions ( compiler . options ) ;
8891
8992 const webpackConfigurationUpdaterOptions : IWebpackConfigurationUpdaterOptions = {
93+ pluginInstance : this ,
9094 configuration : compiler . options ,
9195 locFiles : this . _locFiles ,
9296 filesToIgnore : this . _filesToIgnore ,
93- pluginInstance : this
97+ localeNameOrPlaceholder : this . _localeNamePlaceholder . value
9498 } ;
9599
96100 if ( errors . length > 0 ) {
@@ -103,8 +107,6 @@ export class LocalizationPlugin implements Webpack.Plugin {
103107 return ;
104108 }
105109
106- // https://github.com/webpack/webpack-dev-server/pull/1929/files#diff-15fb51940da53816af13330d8ce69b4eR66
107- const isWebpackDevServer : boolean = process . env . WEBPACK_DEV_SERVER === 'true' ;
108110 if ( isWebpackDevServer ) {
109111 WebpackConfigurationUpdater . amendWebpackConfigurationForInPlaceLocFiles ( compiler . options ) ;
110112 } else if ( this . _locales . size === 1 ) {
@@ -157,43 +159,51 @@ export class LocalizationPlugin implements Webpack.Plugin {
157159 return ;
158160 }
159161
160- const chunkFiles : string [ ] = chunkGroup . getFiles ( ) ;
161- for ( const chunkFileName of chunkFiles ) {
162- if (
163- chunkFileName . match ( Constants . LOCALE_FILENAME_PLACEHOLDER_REGEX ) && // Ensure this is expected to be localized
164- chunkFileName . endsWith ( '.js' ) && // Ensure this is a JS file
165- ! alreadyProcessedAssets . has ( chunkFileName ) // Ensure this isn't a vendor chunk we've already processed
166- ) {
167- alreadyProcessedAssets . add ( chunkFileName ) ;
168-
169- const asset : IAsset = compilation . assets [ chunkFileName ] ;
170- const resultingAssets : Map < string , IProcessAssetResult > = this . _processAsset (
171- compilation ,
172- chunkFileName ,
173- asset
174- ) ;
175-
176- // Delete the existing asset because it's been renamed
177- delete compilation . assets [ chunkFileName ] ;
178-
179- const localizedChunkAssets : { [ locale : string ] : string } = { } ;
180- for ( const [ locale , newAsset ] of resultingAssets ) {
181- compilation . assets [ newAsset . filename ] = newAsset . asset ;
182- localizedChunkAssets [ locale ] = newAsset . filename ;
183- }
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+ }
184191
185- if ( chunkGroup . getParents ( ) . length > 0 ) {
186- // This is a secondary chunk
187- localizationStats . namedChunkGroups [ chunkGroup . name ] = {
188- localizedAssets : localizedChunkAssets
189- } ;
190- } else {
191- // This is an entrypoint
192- localizationStats . entrypoints [ chunkGroup . name ] = {
193- localizedAssets : localizedChunkAssets
194- } ;
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+ }
195203 }
196204 }
205+
206+ chunk . files = Array . from ( chunkFilesSet ) ;
197207 }
198208 }
199209
@@ -241,7 +251,7 @@ export class LocalizationPlugin implements Webpack.Plugin {
241251 const placeholderPrefix : string = Constants . STRING_PLACEHOLDER_PREFIX ;
242252 const placeholderRegex : RegExp = new RegExp (
243253 // The maximum length of quotemark escaping we can support is the length of the placeholder prefix
244- `${ lodash . escapeRegExp ( placeholderPrefix ) } _((?:.){1,${ placeholderPrefix . length } })_(\\d+)` ,
254+ `${ placeholderPrefix } _((?:.){1,${ placeholderPrefix . length } })_(\\d+)` ,
245255 'g'
246256 ) ;
247257 const result : Map < string , IProcessAssetResult > = new Map < string , IProcessAssetResult > ( ) ;
0 commit comments