@@ -186,6 +186,7 @@ ExtractTextPlugin.prototype.loader = function(options) {
186
186
return ExtractTextPlugin . loader ( mergeOptions ( { id : this . id } , options ) ) ;
187
187
} ;
188
188
189
+
189
190
ExtractTextPlugin . prototype . extract = function ( options ) {
190
191
if ( arguments . length > 1 ) {
191
192
throw new Error ( "Breaking change: extract now only takes a single argument. Either an options " +
@@ -265,6 +266,11 @@ ExtractTextPlugin.prototype.apply = function(compiler) {
265
266
filename ( getPath ( module . source ( ) , chunk ) ) :
266
267
getPath ( module . source ( ) , chunk ) ( filename ) ;
267
268
269
+ var replaceTemplate = ( module , chunk , toModifyModule ) => {
270
+ var file = getFile ( module , chunk ) ;
271
+ toModifyModule . _source . _value = toModifyModule . _source . _value . replace ( "%%extracted-file%%" , file ) ;
272
+ } ;
273
+
268
274
compilation . plugin ( "optimize-tree" , function ( chunks , modules , callback ) {
269
275
extractedChunks = chunks . map ( function ( ) {
270
276
return new Chunk ( ) ;
@@ -360,6 +366,19 @@ ExtractTextPlugin.prototype.apply = function(compiler) {
360
366
} . bind ( this ) ) ;
361
367
} . bind ( this ) ) ;
362
368
compilation . plugin ( "optimize-module-ids" , function ( modules ) {
369
+
370
+ // HMR: inject file name into corresponding javascript modules in order to trigger
371
+ // appropriate hot module reloading of CSS
372
+ extractedChunks . forEach ( function ( extractedChunk ) {
373
+ extractedChunk . modules . forEach ( function ( module ) {
374
+ if ( module . __fileInjected ) {
375
+ return ;
376
+ }
377
+ module . __fileInjected = true ;
378
+ var originalModule = module . getOriginalModule ( ) ;
379
+ replaceTemplate ( module , extractedChunk , originalModule ) ;
380
+ } ) ;
381
+ } ) ;
363
382
modules . forEach ( function ( module ) {
364
383
var data = toRemoveModules [ module . identifier ( ) ] ;
365
384
if ( data ) {
@@ -379,24 +398,12 @@ ExtractTextPlugin.prototype.apply = function(compiler) {
379
398
data . moduleToRemove . dependencies . forEach ( d => {
380
399
chunk . removeModule ( d . module ) ;
381
400
} ) ;
401
+ replaceTemplate ( newModule , chunk , newModule ) ;
382
402
chunk . addModule ( newModule ) ;
383
403
} ) ;
384
404
}
385
405
} ) ;
386
406
387
- // HMR: inject file name into corresponding javascript modules in order to trigger
388
- // appropriate hot module reloading of CSS
389
- extractedChunks . forEach ( function ( extractedChunk ) {
390
- extractedChunk . modules . forEach ( function ( module ) {
391
- if ( module . __fileInjected ) {
392
- return ;
393
- }
394
- module . __fileInjected = true ;
395
- var file = getFile ( module , extractedChunk ) ;
396
- var originalModule = module . getOriginalModule ( ) ;
397
- originalModule . _source . _value = originalModule . _source . _value . replace ( "%%extracted-file%%" , file ) ;
398
- } ) ;
399
- } )
400
407
} ) ;
401
408
402
409
compilation . plugin ( "additional-assets" , function ( callback ) {
0 commit comments