@@ -98,13 +98,16 @@ export class WebpackResourceLoader {
98
98
filePath ?: string ,
99
99
data ?: string ,
100
100
mimeType ?: string ,
101
+ resourceType ?: 'style' | 'template' ,
102
+ hash ?: string ,
103
+ containingFile ?: string ,
101
104
) : Promise < CompilationOutput > {
102
105
if ( ! this . _parentCompilation ) {
103
106
throw new Error ( 'WebpackResourceLoader cannot be used without parentCompilation' ) ;
104
107
}
105
108
106
109
// Create a special URL for reading the resource from memory
107
- const entry = data ? ' angular-resource://' : filePath ;
110
+ const entry = data ? ` angular-resource:${ resourceType } , ${ hash } ` : filePath ;
108
111
if ( ! entry ) {
109
112
throw new Error ( `"filePath" or "data" must be specified.` ) ;
110
113
}
@@ -116,7 +119,11 @@ export class WebpackResourceLoader {
116
119
) ;
117
120
}
118
121
119
- const outputFilePath = filePath || `angular-resource-output-${ this . outputPathCounter ++ } .css` ;
122
+ const outputFilePath =
123
+ filePath ||
124
+ `${ containingFile } -angular-inline--${ this . outputPathCounter ++ } .${
125
+ resourceType === 'template' ? 'html' : 'css'
126
+ } `;
120
127
const outputOptions = {
121
128
filename : outputFilePath ,
122
129
library : {
@@ -215,7 +222,14 @@ export class WebpackResourceLoader {
215
222
if ( parent ) {
216
223
parent . children = parent . children . filter ( ( child ) => child !== childCompilation ) ;
217
224
218
- parent . fileDependencies . addAll ( childCompilation . fileDependencies ) ;
225
+ for ( const fileDependency of childCompilation . fileDependencies ) {
226
+ if ( data && containingFile && fileDependency . endsWith ( entry ) ) {
227
+ // use containing file if the resource was inline
228
+ parent . fileDependencies . add ( containingFile ) ;
229
+ } else {
230
+ parent . fileDependencies . add ( fileDependency ) ;
231
+ }
232
+ }
219
233
parent . contextDependencies . addAll ( childCompilation . contextDependencies ) ;
220
234
parent . missingDependencies . addAll ( childCompilation . missingDependencies ) ;
221
235
parent . buildDependencies . addAll ( childCompilation . buildDependencies ) ;
@@ -298,7 +312,12 @@ export class WebpackResourceLoader {
298
312
return compilationResult . content ;
299
313
}
300
314
301
- async process ( data : string , mimeType : string ) : Promise < string > {
315
+ async process (
316
+ data : string ,
317
+ mimeType : string ,
318
+ resourceType : 'template' | 'style' ,
319
+ containingFile ?: string ,
320
+ ) : Promise < string > {
302
321
if ( data . trim ( ) . length === 0 ) {
303
322
return '' ;
304
323
}
@@ -307,7 +326,14 @@ export class WebpackResourceLoader {
307
326
let compilationResult = this . inlineCache ?. get ( cacheKey ) ;
308
327
309
328
if ( compilationResult === undefined ) {
310
- compilationResult = await this . _compile ( undefined , data , mimeType ) ;
329
+ compilationResult = await this . _compile (
330
+ undefined ,
331
+ data ,
332
+ mimeType ,
333
+ resourceType ,
334
+ cacheKey ,
335
+ containingFile ,
336
+ ) ;
311
337
312
338
if ( this . inlineCache && compilationResult . success ) {
313
339
this . inlineCache . set ( cacheKey , compilationResult ) ;
0 commit comments