fix(nuxt): apply ignore rules to nitro devStorage (#31233)

This commit is contained in:
Connor Pearson 2025-03-07 12:32:08 +01:00 committed by GitHub
parent 1a6db8ce74
commit 0ebaa51465
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,7 +6,7 @@ import { createRouter as createRadixRouter, exportMatcher, toRouteMatcher } from
import { joinURL, withTrailingSlash } from 'ufo'
import { build, copyPublicAssets, createDevServer, createNitro, prepare, prerender, scanHandlers, writeTypes } from 'nitropack'
import type { Nitro, NitroConfig, NitroOptions } from 'nitropack'
import { findPath, logger, resolveAlias, resolveIgnorePatterns, resolveNuxtModule } from '@nuxt/kit'
import { createIsIgnored, findPath, logger, resolveAlias, resolveIgnorePatterns, resolveNuxtModule } from '@nuxt/kit'
import escapeRE from 'escape-string-regexp'
import { defu } from 'defu'
import { dynamicEventHandler } from 'h3'
@ -428,6 +428,28 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
}),
)
// Apply Nuxt's ignore configuration to the root and src unstorage mounts
// created by Nitro. This ensures that the unstorage watcher will use the
// same ignore list as Nuxt's watcher and can reduce unneccesary file handles.
const isIgnored = createIsIgnored(nuxt)
nitroConfig.devStorage ??= {}
nitroConfig.devStorage.root ??= {
driver: 'fs',
readOnly: true,
base: nitroConfig.rootDir,
watchOptions: {
ignored: [isIgnored],
},
}
nitroConfig.devStorage.src ??= {
driver: 'fs',
readOnly: true,
base: nitroConfig.srcDir,
watchOptions: {
ignored: [isIgnored],
},
}
// Extend nitro config with hook
await nuxt.callHook('nitro:config', nitroConfig)