Skip to content

Commit 998d09d

Browse files
committed
fix(@ngtools/webpack): allow generated assets of Angular component resources
The asset caching for Angular component resources previously required that all assets had an originating file. However, some Webpack plugins may generate assets that do not originate from on-disk files and are instead synthetic. These type of assets are now supported by generating a cache key based on the output name of the asset. These assets will persist within the cache due to the lack of knowledge on the dependencies of these assets which results in the inability to invalidate the assets. Updated assets of the same output name will, however, replace older versions of the asset on rebuilds. Fixes: angular#21290
1 parent 34e66ff commit 998d09d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/ngtools/webpack/src/resource_loader.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,15 @@ export class WebpackResourceLoader {
274274

275275
parent.warnings.push(...childCompilation.warnings);
276276
parent.errors.push(...childCompilation.errors);
277-
for (const { info, name, source } of childCompilation.getAssets()) {
278-
if (info.sourceFilename === undefined) {
279-
throw new Error(`'${name}' asset info 'sourceFilename' is 'undefined'.`);
280-
}
281277

282-
this.assetCache?.set(info.sourceFilename, { info, name, source });
278+
if (this.assetCache) {
279+
for (const { info, name, source } of childCompilation.getAssets()) {
280+
// Use the originating file as the cache key if present
281+
// Otherwise, generate a cache key based on the generated name
282+
const cacheKey = info.sourceFilename ?? `!![GENERATED]:${name}`;
283+
284+
this.assetCache.set(cacheKey, { info, name, source });
285+
}
283286
}
284287
}
285288

0 commit comments

Comments
 (0)