9
9
import { createHash } from 'crypto' ;
10
10
import * as path from 'path' ;
11
11
import * as vm from 'vm' ;
12
- import { Compilation , EntryPlugin , NormalModule , library , node , sources } from 'webpack' ;
12
+ import { Asset , Compilation , EntryPlugin , NormalModule , library , node , sources } from 'webpack' ;
13
13
import { normalizePath } from './ivy/paths' ;
14
14
15
15
interface CompilationOutput {
@@ -25,13 +25,16 @@ export class WebpackResourceLoader {
25
25
26
26
private fileCache ?: Map < string , CompilationOutput > ;
27
27
private inlineCache ?: Map < string , CompilationOutput > ;
28
+ private assetCache ?: Map < string , Asset > ;
29
+
28
30
private modifiedResources = new Set < string > ( ) ;
29
31
private outputPathCounter = 1 ;
30
32
31
33
constructor ( shouldCache : boolean ) {
32
34
if ( shouldCache ) {
33
35
this . fileCache = new Map ( ) ;
34
36
this . inlineCache = new Map ( ) ;
37
+ this . assetCache = new Map ( ) ;
35
38
}
36
39
}
37
40
@@ -40,15 +43,34 @@ export class WebpackResourceLoader {
40
43
41
44
// Update resource cache and modified resources
42
45
this . modifiedResources . clear ( ) ;
46
+
43
47
if ( changedFiles ) {
44
48
for ( const changedFile of changedFiles ) {
49
+ const changedFileNormalized = normalizePath ( changedFile ) ;
50
+ this . assetCache ?. delete ( changedFileNormalized ) ;
51
+
45
52
for ( const affectedResource of this . getAffectedResources ( changedFile ) ) {
46
- this . fileCache ?. delete ( normalizePath ( affectedResource ) ) ;
53
+ const affectedResourceNormalized = normalizePath ( affectedResource ) ;
54
+ this . fileCache ?. delete ( affectedResourceNormalized ) ;
47
55
this . modifiedResources . add ( affectedResource ) ;
56
+
57
+ for ( const effectedDependencies of this . getResourceDependencies (
58
+ affectedResourceNormalized ,
59
+ ) ) {
60
+ this . assetCache ?. delete ( normalizePath ( effectedDependencies ) ) ;
61
+ }
48
62
}
49
63
}
50
64
} else {
51
65
this . fileCache ?. clear ( ) ;
66
+ this . assetCache ?. clear ( ) ;
67
+ }
68
+
69
+ // Re-emit all assets for un-effected files
70
+ if ( this . assetCache ) {
71
+ for ( const [ , { name, source, info } ] of this . assetCache ) {
72
+ this . _parentCompilation . emitAsset ( name , source , info ) ;
73
+ }
52
74
}
53
75
}
54
76
@@ -200,6 +222,13 @@ export class WebpackResourceLoader {
200
222
201
223
parent . warnings . push ( ...childCompilation . warnings ) ;
202
224
parent . errors . push ( ...childCompilation . errors ) ;
225
+ for ( const { info, name, source } of childCompilation . getAssets ( ) ) {
226
+ if ( info . sourceFilename === undefined ) {
227
+ throw new Error ( `'${ name } ' asset info 'sourceFilename' is 'undefined'.` ) ;
228
+ }
229
+
230
+ this . assetCache ?. set ( info . sourceFilename , { info, name, source } ) ;
231
+ }
203
232
}
204
233
205
234
// Save the dependencies for this resource.
0 commit comments