Skip to content

Commit

Permalink
perf(@ngtools/webpack): rebuild Angular required files asynchronously
Browse files Browse the repository at this point in the history
This change adjusts the Angular required files rebuilding logic to not block on each individual file's Webpack module rebuild. Now all required Webpack modules are discovered then rebuilt asynchrounously and only blocked on the full list of rebuilds. The promise-based Webpack rebuild function is also now only created if a rebuild is required.

(cherry picked from commit f62b042)
  • Loading branch information
clydin committed May 3, 2021
1 parent 3a23130 commit 057ba0c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/ngtools/webpack/src/ivy/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,6 @@ export class AngularWebpackPlugin {
return;
}

const rebuild = (webpackModule: Module) =>
new Promise<void>((resolve) => compilation.rebuildModule(webpackModule, () => resolve()));

const filesToRebuild = new Set<string>();
for (const requiredFile of this.requiredFilesToEmit) {
const history = this.fileEmitHistory.get(requiredFile);
Expand All @@ -356,12 +353,17 @@ export class AngularWebpackPlugin {
}

if (filesToRebuild.size > 0) {
for (const webpackModule of [...modules]) {
const rebuild = (webpackModule: Module) =>
new Promise<void>((resolve) => compilation.rebuildModule(webpackModule, () => resolve()));

const modulesToRebuild = [];
for (const webpackModule of modules) {
const resource = (webpackModule as NormalModule).resource;
if (resource && filesToRebuild.has(normalizePath(resource))) {
await rebuild(webpackModule);
modulesToRebuild.push(webpackModule);
}
}
await Promise.all(modulesToRebuild.map((webpackModule) => rebuild(webpackModule)));
}

this.requiredFilesToEmit.clear();
Expand Down

0 comments on commit 057ba0c

Please sign in to comment.