From c4956cbf322bdc77535e2394d6bf5b22279ff789 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 27 Jun 2024 18:41:46 +0200 Subject: [PATCH] perf(schema): use `chokidar` when a custom `srcDir` is provided (#27871) --- packages/schema/src/config/experimental.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/schema/src/config/experimental.ts b/packages/schema/src/config/experimental.ts index ce19e97781..c00a4de820 100644 --- a/packages/schema/src/config/experimental.ts +++ b/packages/schema/src/config/experimental.ts @@ -238,8 +238,9 @@ export default defineUntypedSchema({ /** * Set an alternative watcher that will be used as the watching service for Nuxt. * - * Nuxt uses 'chokidar-granular' by default, which will ignore top-level directories - * (like `node_modules` and `.git`) that are excluded from watching. + * Nuxt uses 'chokidar-granular' if your source directory is the same as your root + * directory . This will ignore top-level directories (like `node_modules` and `.git`) + * that are excluded from watching. * * You can set this instead to `parcel` to use `@parcel/watcher`, which may improve * performance in large projects or on Windows platforms. @@ -249,7 +250,18 @@ export default defineUntypedSchema({ * @see [Parcel watcher](https://github.com/parcel-bundler/watcher) * @type {'chokidar' | 'parcel' | 'chokidar-granular'} */ - watcher: 'chokidar-granular', + watcher: { + $resolve: async (val, get) => { + if (val) { + return val + } + const [srcDir, rootDir] = await Promise.all([get('srcDir'), get('rootDir')]) as [string, string] + if (srcDir === rootDir) { + return 'chokidar-granular' + } + return 'chokidar' + }, + }, /** * Enable native async context to be accessible for nested composables