Skip to content

Commit 59aa1cd

Browse files
alan-agius4clydin
authored andcommittedFeb 14, 2023
perf(@angular-devkit/build-angular): reduce rebuilt times when using the scripts option
In some cases, using the `scripts` option caused a lot of `DescriptionFileUtils.loadDescriptionFile` calls which caused a bottleneck during build times. The why to this is still unknown, but a workaround is to use the resolver from the Webpack compilation instead of the compiler. Closes #24634 (cherry picked from commit 1e52863)
1 parent 34a4a1b commit 59aa1cd

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed
 

‎packages/angular_devkit/build_angular/src/webpack/plugins/scripts-webpack-plugin.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,17 @@ export class ScriptsWebpackPlugin {
100100
return;
101101
}
102102

103-
const resolver = compiler.resolverFactory.get('normal', {
104-
preferRelative: true,
105-
useSyncFileSystemCalls: true,
106-
fileSystem: compiler.inputFileSystem,
107-
});
108-
109103
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
104+
// Use the resolver from the compilation instead of compiler.
105+
// Using the latter will causes a lot of `DescriptionFileUtils.loadDescriptionFile` calls.
106+
// See: https://github.com/angular/angular-cli/issues/24634#issuecomment-1425782668
107+
const resolver = compilation.resolverFactory.get('normal', {
108+
preferRelative: true,
109+
useSyncFileSystemCalls: true,
110+
// Caching must be disabled because it causes the resolver to become async after a rebuild.
111+
cache: false,
112+
});
113+
110114
const scripts: string[] = [];
111115

112116
for (const script of this.options.scripts) {

0 commit comments

Comments
 (0)
Please sign in to comment.