Skip to content

Commit e1074eb

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 (cherry picked from commit 7536338)
1 parent 191dc49 commit e1074eb

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/ngtools/webpack/src/resource_loader.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,15 @@ export class WebpackResourceLoader {
276276

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

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

0 commit comments

Comments
 (0)