Skip to content

Commit 7536338

Browse files
clydinfilipesilva
authored andcommitted
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: #21290
1 parent 1b5e18e commit 7536338

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
@@ -275,12 +275,15 @@ export class WebpackResourceLoader {
275275

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

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

0 commit comments

Comments
 (0)