From 06763bb09fffd8947c09185fa5fabb7c8c84ee87 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Mon, 11 Nov 2019 18:04:24 -0500 Subject: [PATCH] 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%. --- .../src/angular-cli-files/models/webpack-configs/common.ts | 1 + .../angular_devkit/build_angular/src/dev-server/index.ts | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts b/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts index 1a497d706efa..81bf729cd789 100644 --- a/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts +++ b/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts @@ -479,6 +479,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration { watch: buildOptions.watch, watchOptions: { poll: buildOptions.poll, + ignored: buildOptions.poll === undefined ? undefined : /[\\\/]node_modules[\\\/]/, }, performance: { hints: false, diff --git a/packages/angular_devkit/build_angular/src/dev-server/index.ts b/packages/angular_devkit/build_angular/src/dev-server/index.ts index 875e883ca1f4..780ff62e13b5 100644 --- a/packages/angular_devkit/build_angular/src/dev-server/index.ts +++ b/packages/angular_devkit/build_angular/src/dev-server/index.ts @@ -423,7 +423,11 @@ export function buildServerConfig( stats: false, compress: styles || scripts, watchOptions: { - poll: browserOptions.poll, + // Using just `--poll` will result in a value of 0 which is very likely not the intention + // A value of 0 is falsy and will disable polling rather then enable + // 500 ms is a sensible default in this case + poll: serverOptions.poll === 0 ? 500 : serverOptions.poll, + ignored: serverOptions.poll === undefined ? undefined : /[\\\/]node_modules[\\\/]/, }, https: serverOptions.ssl, overlay: {