@@ -221,22 +221,6 @@ export class ModuleMinifierPlugin implements webpack.Plugin {
221
221
}
222
222
}
223
223
224
- /**
225
- * Callback to invoke for a chunk during render to replace the modules with CHUNK_MODULES_TOKEN
226
- */
227
- function dehydrateAsset ( modules : Source , chunk : webpack . compilation . Chunk ) : Source {
228
- for ( const mod of chunk . modulesIterable ) {
229
- if ( mod . id === null || ! submittedModules . has ( mod . id ) ) {
230
- console . error (
231
- `Chunk ${ chunk . id } failed to render module ${ mod . id } for ${ ( mod as IExtendedModule ) . resource } `
232
- ) ;
233
- }
234
- }
235
-
236
- // Discard the rendered modules
237
- return new RawSource ( CHUNK_MODULES_TOKEN ) ;
238
- }
239
-
240
224
const { minifier } = this ;
241
225
242
226
const cleanupMinifier : ( ( ) => Promise < void > ) | undefined = minifier . ref ?.( ) ;
@@ -467,7 +451,7 @@ export class ModuleMinifierPlugin implements webpack.Plugin {
467
451
}
468
452
) ;
469
453
} else {
470
- // Skip minification for all other assets , though the modules still are
454
+ // This isn't a JS asset. Don't try to minify the asset wrapper , though if it contains modules, those might still get replaced with minified versions.
471
455
minifiedAssets . set ( assetName , {
472
456
// Still need to restore ids
473
457
source : postProcessCode ( new ReplaceSource ( asset ) , assetName ) ,
@@ -509,9 +493,32 @@ export class ModuleMinifierPlugin implements webpack.Plugin {
509
493
}
510
494
) ;
511
495
512
- for ( const template of [ compilation . chunkTemplate , compilation . mainTemplate ] ) {
513
- ( template as unknown as IExtendedChunkTemplate ) . hooks . modules . tap ( TAP_AFTER , dehydrateAsset ) ;
514
- }
496
+ // This function is written twice because the parameter order is not the same between the two hooks
497
+ ( compilation . chunkTemplate as unknown as IExtendedChunkTemplate ) . hooks . modules . tap (
498
+ TAP_AFTER ,
499
+ ( source : Source , chunk : webpack . compilation . Chunk , moduleTemplate : unknown ) => {
500
+ if ( moduleTemplate !== compilation . moduleTemplates . javascript ) {
501
+ // This is not a JavaScript asset
502
+ return source ;
503
+ }
504
+
505
+ // Discard the rendered modules
506
+ return new RawSource ( CHUNK_MODULES_TOKEN ) ;
507
+ }
508
+ ) ;
509
+
510
+ ( compilation . mainTemplate as unknown as IExtendedChunkTemplate ) . hooks . modules . tap (
511
+ TAP_AFTER ,
512
+ ( source : Source , chunk : webpack . compilation . Chunk , hash : unknown , moduleTemplate : unknown ) => {
513
+ if ( moduleTemplate !== compilation . moduleTemplates . javascript ) {
514
+ // This is not a JavaScript asset
515
+ return source ;
516
+ }
517
+
518
+ // Discard the rendered modules
519
+ return new RawSource ( CHUNK_MODULES_TOKEN ) ;
520
+ }
521
+ ) ;
515
522
}
516
523
) ;
517
524
}
0 commit comments