Skip to content

Commit 2d9ee82

Browse files
clydinmgechev
authored andcommitted
fix(@angular-devkit/build-angular): ignore node modules when polling
The node modules directory contains a massive set of directories and files. When watching via polling, that set needs to be queried repeatedly to determine if any files have changed. Changes within node modules are quite rare while using `ng serve` or `ng build --watch`. As a result, polling the node modules directory is rarely useful. This change causes CPU usage to drop from a potential high of ~80% to a more manageable ~5-10%.
1 parent 6c2d956 commit 2d9ee82

File tree

2 files changed

+6
-1
lines changed
  • packages/angular_devkit/build_angular/src

2 files changed

+6
-1
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
479479
watch: buildOptions.watch,
480480
watchOptions: {
481481
poll: buildOptions.poll,
482+
ignored: buildOptions.poll === undefined ? undefined : /[\\\/]node_modules[\\\/]/,
482483
},
483484
performance: {
484485
hints: false,

packages/angular_devkit/build_angular/src/dev-server/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,11 @@ export function buildServerConfig(
427427
stats: false,
428428
compress: styles || scripts,
429429
watchOptions: {
430-
poll: browserOptions.poll,
430+
// Using just `--poll` will result in a value of 0 which is very likely not the intention
431+
// A value of 0 is falsy and will disable polling rather then enable
432+
// 500 ms is a sensible default in this case
433+
poll: serverOptions.poll === 0 ? 500 : serverOptions.poll,
434+
ignored: serverOptions.poll === undefined ? undefined : /[\\\/]node_modules[\\\/]/,
431435
},
432436
https: serverOptions.ssl,
433437
overlay: {

0 commit comments

Comments
 (0)