@@ -18,6 +18,7 @@ export class WebpackResourceLoader {
18
18
private _context : string ;
19
19
private _uniqueId = 0 ;
20
20
private _resourceDependencies = new Map < string , string [ ] > ( ) ;
21
+ private _cachedResources = new Map < string , string > ( ) ;
21
22
22
23
constructor ( ) { }
23
24
@@ -69,6 +70,11 @@ export class WebpackResourceLoader {
69
70
70
71
childCompiler . plugin ( 'this-compilation' , ( compilation : any ) => {
71
72
compilation . plugin ( 'additional-assets' , ( callback : ( err ?: Error ) => void ) => {
73
+ if ( this . _cachedResources . has ( compilation . fullHash ) ) {
74
+ callback ( ) ;
75
+ return ;
76
+ }
77
+
72
78
const asset = compilation . assets [ filePath ] ;
73
79
if ( asset ) {
74
80
this . _evaluate ( { outputName : filePath , source : asset . source ( ) } )
@@ -104,12 +110,17 @@ export class WebpackResourceLoader {
104
110
// Save the dependencies for this resource.
105
111
this . _resourceDependencies . set ( filePath , childCompilation . fileDependencies ) ;
106
112
107
- resolve ( {
108
- // Output name.
109
- outputName : filePath ,
110
- // Compiled code.
111
- source : childCompilation . assets [ filePath ] . source ( )
112
- } ) ;
113
+ const compilationHash = childCompilation . fullHash ;
114
+ if ( this . _cachedResources . has ( compilationHash ) ) {
115
+ resolve ( {
116
+ outputName : filePath ,
117
+ source : this . _cachedResources . get ( compilationHash ) ,
118
+ } ) ;
119
+ } else {
120
+ const source = childCompilation . assets [ filePath ] . source ( ) ;
121
+ this . _cachedResources . set ( compilationHash , source ) ;
122
+ resolve ( { outputName : filePath , source } ) ;
123
+ }
113
124
}
114
125
} ) ;
115
126
} ) ;
0 commit comments