Skip to content

Commit f9657bc

Browse files
clydinfilipesilva
authored andcommitted
fix(@ngtools/webpack): remove redundant inline style cache
The size of the cache could grow quite large over long active development periods. Webpack 5 memory caching will also allow for caching of the data.
1 parent ee5a7d7 commit f9657bc

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

packages/ngtools/webpack/src/resource_loader.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export class WebpackResourceLoader {
2828
private _reverseDependencies = new Map<string, Set<string>>();
2929

3030
private fileCache?: Map<string, CompilationOutput>;
31-
private inlineCache?: Map<string, CompilationOutput>;
3231
private assetCache?: Map<string, Asset>;
3332

3433
private modifiedResources = new Set<string>();
@@ -39,7 +38,6 @@ export class WebpackResourceLoader {
3938
constructor(shouldCache: boolean) {
4039
if (shouldCache) {
4140
this.fileCache = new Map();
42-
this.inlineCache = new Map();
4341
this.assetCache = new Map();
4442
}
4543
}
@@ -106,7 +104,6 @@ export class WebpackResourceLoader {
106104
mimeType?: string,
107105
fileExtension?: string,
108106
resourceType?: 'style' | 'template',
109-
hash?: string,
110107
containingFile?: string,
111108
): Promise<CompilationOutput> {
112109
if (!this._parentCompilation) {
@@ -118,7 +115,8 @@ export class WebpackResourceLoader {
118115
filePath ||
119116
(resourceType
120117
? `${containingFile}-${this.outputPathCounter}.${fileExtension}!=!${this.inlineDataLoaderPath}!${containingFile}`
121-
: `angular-resource:${resourceType},${hash}`);
118+
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
119+
`angular-resource:${resourceType},${createHash('md5').update(data!).digest('hex')}`);
122120

123121
if (!entry) {
124122
throw new Error(`"filePath" or "data" must be specified.`);
@@ -337,24 +335,14 @@ export class WebpackResourceLoader {
337335
return '';
338336
}
339337

340-
const cacheKey = createHash('md5').update(data).digest('hex');
341-
let compilationResult = this.inlineCache?.get(cacheKey);
342-
343-
if (compilationResult === undefined) {
344-
compilationResult = await this._compile(
345-
undefined,
346-
data,
347-
mimeType,
348-
fileExtension,
349-
resourceType,
350-
cacheKey,
351-
containingFile,
352-
);
353-
354-
if (this.inlineCache && compilationResult.success) {
355-
this.inlineCache.set(cacheKey, compilationResult);
356-
}
357-
}
338+
const compilationResult = await this._compile(
339+
undefined,
340+
data,
341+
mimeType,
342+
fileExtension,
343+
resourceType,
344+
containingFile,
345+
);
358346

359347
return compilationResult.content;
360348
}

0 commit comments

Comments
 (0)