Skip to content

Commit 834925d

Browse files
committed
refactor(@angular/build): only ignore watching node modules when watching root
The application builder performs fine-grained file watching now which removes the need to watch the project root by default as it did in early implementations. As a result, the need to ignore the `node_modules` directory is not longer necessary by default and is only needed when the `NG_BUILD_WATCH_ROOT` environment variable is enabled.
1 parent 6ce5c69 commit 834925d

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

packages/angular/build/src/builders/application/build-action.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,6 @@ export async function* runEsBuildBuildAction(
9898
`${workspaceRoot.replace(/\\/g, '/')}/**/.*/**`,
9999
];
100100

101-
if (!preserveSymlinks) {
102-
// Ignore all node modules directories to avoid excessive file watchers.
103-
// Package changes are handled below by watching manifest and lock files.
104-
// NOTE: this is not enable when preserveSymlinks is true as this would break `npm link` usages.
105-
ignored.push('**/node_modules/**');
106-
}
107-
108101
// Setup a watcher
109102
const { createWatcher } = await import('../../tools/esbuild/watcher');
110103
watcher = createWatcher({
@@ -119,15 +112,22 @@ export async function* runEsBuildBuildAction(
119112

120113
// Watch the entire project root if 'NG_BUILD_WATCH_ROOT' environment variable is set
121114
if (shouldWatchRoot) {
115+
if (!preserveSymlinks) {
116+
// Ignore all node modules directories to avoid excessive file watchers.
117+
// Package changes are handled below by watching manifest and lock files.
118+
// NOTE: this is not enable when preserveSymlinks is true as this would break `npm link` usages.
119+
ignored.push('**/node_modules/**');
120+
121+
watcher.add(
122+
packageWatchFiles
123+
.map((file) => path.join(workspaceRoot, file))
124+
.filter((file) => existsSync(file)),
125+
);
126+
}
127+
122128
watcher.add(projectRoot);
123129
}
124130

125-
watcher.add(
126-
packageWatchFiles
127-
.map((file) => path.join(workspaceRoot, file))
128-
.filter((file) => existsSync(file)),
129-
);
130-
131131
// Watch locations provided by the initial build result
132132
watcher.add(result.watchFiles);
133133
}

0 commit comments

Comments
 (0)