@@ -25,6 +25,18 @@ interface ScriptOutput {
25
25
source : CachedSource ;
26
26
}
27
27
28
+ function addDependencies ( compilation : any , scripts : string [ ] ) : void {
29
+ if ( compilation . fileDependencies . add ) {
30
+ // Webpack 4+ uses a Set
31
+ for ( const script of scripts ) {
32
+ compilation . fileDependencies . add ( script ) ;
33
+ }
34
+ } else {
35
+ // Webpack 3
36
+ compilation . fileDependencies . push ( ...scripts ) ;
37
+ }
38
+ }
39
+
28
40
export class ScriptsWebpackPlugin {
29
41
private _lastBuildTime ?: number ;
30
42
private _cachedOutput ?: ScriptOutput ;
@@ -38,7 +50,14 @@ export class ScriptsWebpackPlugin {
38
50
}
39
51
40
52
for ( let i = 0 ; i < scripts . length ; i ++ ) {
41
- const scriptTime = compilation . fileTimestamps [ scripts [ i ] ] ;
53
+ let scriptTime ;
54
+ if ( compilation . fileTimestamps . get ) {
55
+ // Webpack 4+ uses a Map
56
+ scriptTime = compilation . fileTimestamps . get ( scripts [ i ] ) ;
57
+ } else {
58
+ // Webpack 3
59
+ scriptTime = compilation . fileTimestamps [ scripts [ i ] ] ;
60
+ }
42
61
if ( ! scriptTime || scriptTime > this . _lastBuildTime ) {
43
62
this . _lastBuildTime = Date . now ( ) ;
44
63
return false ;
@@ -76,8 +95,8 @@ export class ScriptsWebpackPlugin {
76
95
if ( this . _cachedOutput ) {
77
96
this . _insertOutput ( compilation , this . _cachedOutput , true ) ;
78
97
}
79
- compilation . fileDependencies . push ( ...scripts ) ;
80
98
99
+ addDependencies ( compilation , scripts ) ;
81
100
callback ( ) ;
82
101
83
102
return ;
@@ -129,7 +148,7 @@ export class ScriptsWebpackPlugin {
129
148
const output = { filename, source : combinedSource } ;
130
149
this . _insertOutput ( compilation , output ) ;
131
150
this . _cachedOutput = output ;
132
- compilation . fileDependencies . push ( ... scripts ) ;
151
+ addDependencies ( compilation , scripts ) ;
133
152
134
153
callback ( ) ;
135
154
} )
0 commit comments