9
9
10
10
'use strict' ;
11
11
12
+ const webpack = require ( 'webpack' ) ;
13
+
12
14
function DeleteUnusedEntriesJSPlugin ( entriesToDelete = [ ] ) {
13
15
this . entriesToDelete = entriesToDelete ;
14
16
}
15
17
DeleteUnusedEntriesJSPlugin . prototype . apply = function ( compiler ) {
16
- const emit = ( compilation , callback ) => {
17
-
18
+ const deleteEntries = ( compilation ) => {
18
19
// loop over output chunks
19
20
compilation . chunks . forEach ( ( chunk ) => {
20
21
// see of this chunk is one that needs its .js deleted
@@ -26,7 +27,7 @@ DeleteUnusedEntriesJSPlugin.prototype.apply = function(compiler) {
26
27
if ( / \. j s ? ( \? [ ^ . ] * ) ? $ / . test ( filename ) ) {
27
28
removedFiles . push ( filename ) ;
28
29
// remove the output file
29
- delete compilation . assets [ filename ] ;
30
+ compilation . deleteAsset ( filename ) ;
30
31
// remove the file, so that it does not dump in the manifest
31
32
chunk . files . delete ( filename ) ;
32
33
}
@@ -37,7 +38,7 @@ DeleteUnusedEntriesJSPlugin.prototype.apply = function(compiler) {
37
38
if ( removedFiles . map ( name => `${ name } .map` ) . includes ( `${ filename } ` ) ) {
38
39
removedFiles . push ( filename ) ;
39
40
// remove the output file
40
- delete compilation . assets [ filename ] ;
41
+ compilation . deleteAsset ( filename ) ;
41
42
// remove the file, so that it does not dump in the manifest
42
43
chunk . auxiliaryFiles . delete ( filename ) ;
43
44
}
@@ -51,14 +52,14 @@ DeleteUnusedEntriesJSPlugin.prototype.apply = function(compiler) {
51
52
}
52
53
}
53
54
} ) ;
54
-
55
- callback ( ) ;
56
55
} ;
57
56
58
- compiler . hooks . emit . tapAsync (
59
- { name : 'DeleteUnusedEntriesJsPlugin' } ,
60
- emit
61
- ) ;
57
+ compiler . hooks . compilation . tap ( 'DeleteUnusedEntriesJSPlugin' , function ( compilation ) {
58
+ compilation . hooks . additionalAssets . tap (
59
+ 'DeleteUnusedEntriesJsPlugin' ,
60
+ function ( ) { deleteEntries ( compilation ) }
61
+ ) ;
62
+ } ) ;
62
63
} ;
63
64
64
65
module . exports = DeleteUnusedEntriesJSPlugin ;
0 commit comments