From b5dea0046d2b9ced0c677923fd9ce90574f87001 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Wed, 5 Jul 2023 12:18:13 +0200 Subject: [PATCH] Optimize watch ignore (#52238) ## What? Uses a pre-created regex instead of having webpack run path-to-regexp on the list of patterns. Saves a few milliseconds. Adds `node_modules` to ignored in order to skip a lot of stat calls at the end of the compilation. This will likely have a big impact on applications using Yarn PnP as each stat call causes a lookup through `.pnp.cjs`. --- packages/next/src/build/webpack-config.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/next/src/build/webpack-config.ts b/packages/next/src/build/webpack-config.ts index 9e13fc77c1f34..a741221c661a7 100644 --- a/packages/next/src/build/webpack-config.ts +++ b/packages/next/src/build/webpack-config.ts @@ -152,7 +152,9 @@ const nodePathList = (process.env.NODE_PATH || '') const watchOptions = Object.freeze({ aggregateTimeout: 5, - ignored: ['**/.git/**', '**/.next/**'], + ignored: + // Matches **/node_modules/**, **/.git/** and **/.next/** + /^((?:[^/]*(?:\/|$))*)(\.(git|next)|node_modules)(\/((?:[^/]*(?:\/|$))*)(?:$|\/))?/, }) function isModuleCSS(module: { type: string }) {