@@ -37,35 +37,18 @@ interface ScriptOutput {
37
37
}
38
38
39
39
function addDependencies ( compilation : any , scripts : string [ ] ) : void {
40
- if ( compilation . fileDependencies . add ) {
41
- // Webpack 4+ uses a Set
42
- for ( const script of scripts ) {
43
- compilation . fileDependencies . add ( script ) ;
44
- }
45
- } else {
46
- // Webpack 3
47
- compilation . fileDependencies . push ( ...scripts ) ;
40
+ for ( const script of scripts ) {
41
+ compilation . fileDependencies . add ( script ) ;
48
42
}
49
43
}
50
44
51
45
function hook ( compiler : any , action : ( compilation : any , callback : ( err ?: Error ) => void ) => void ) {
52
- if ( compiler . hooks ) {
53
- // Webpack 4
54
- compiler . hooks . thisCompilation . tap ( 'scripts-webpack-plugin' , ( compilation : any ) => {
55
- compilation . hooks . additionalAssets . tapAsync (
56
- 'scripts-webpack-plugin' ,
57
- ( callback : ( err ?: Error ) => void ) => action ( compilation , callback ) ,
58
- ) ;
59
- } ) ;
60
- } else {
61
- // Webpack 3
62
- compiler . plugin ( 'this-compilation' , ( compilation : any ) => {
63
- compilation . plugin (
64
- 'additional-assets' ,
65
- ( callback : ( err ?: Error ) => void ) => action ( compilation , callback ) ,
66
- ) ;
67
- } ) ;
68
- }
46
+ compiler . hooks . thisCompilation . tap ( 'scripts-webpack-plugin' , ( compilation : any ) => {
47
+ compilation . hooks . additionalAssets . tapAsync (
48
+ 'scripts-webpack-plugin' ,
49
+ ( callback : ( err ?: Error ) => void ) => action ( compilation , callback ) ,
50
+ ) ;
51
+ } ) ;
69
52
}
70
53
71
54
export class ScriptsWebpackPlugin {
@@ -81,14 +64,7 @@ export class ScriptsWebpackPlugin {
81
64
}
82
65
83
66
for ( let i = 0 ; i < scripts . length ; i ++ ) {
84
- let scriptTime ;
85
- if ( compilation . fileTimestamps . get ) {
86
- // Webpack 4+ uses a Map
87
- scriptTime = compilation . fileTimestamps . get ( scripts [ i ] ) ;
88
- } else {
89
- // Webpack 3
90
- scriptTime = compilation . fileTimestamps [ scripts [ i ] ] ;
91
- }
67
+ const scriptTime = compilation . fileTimestamps . get ( scripts [ i ] ) ;
92
68
if ( ! scriptTime || scriptTime > this . _lastBuildTime ) {
93
69
this . _lastBuildTime = Date . now ( ) ;
94
70
return false ;
0 commit comments