mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-21 21:25:11 +00:00
perf(nuxt,schema): do not watch buildDir
and node_modules
(#22214)
This commit is contained in:
parent
61146aacaf
commit
0f16cd6124
@ -98,7 +98,7 @@ export default defineNuxtModule<ComponentsOptions>({
|
||||
pattern: dirOptions.pattern || `**/*.{${extensions.join(',')},}`,
|
||||
ignore: [
|
||||
'**/*{M,.m,-m}ixin.{js,ts,jsx,tsx}', // ignore mixins
|
||||
'**/*.d.ts', // .d.ts files
|
||||
'**/*.d.{cts,mts,ts}', // .d.ts files
|
||||
...(dirOptions.ignore || [])
|
||||
],
|
||||
transpile: (transpile === 'auto' ? dirPath.includes('node_modules') : transpile)
|
||||
|
@ -5,6 +5,7 @@ import { createUnimport } from 'unimport'
|
||||
import { createUnplugin } from 'unplugin'
|
||||
import { parseURL } from 'ufo'
|
||||
import { parseQuery } from 'vue-router'
|
||||
import { normalize } from 'pathe'
|
||||
import type { getComponentsT } from './module'
|
||||
|
||||
const COMPONENT_QUERY_RE = /[?&]nuxt_component=/
|
||||
@ -45,7 +46,8 @@ export function createTransformPlugin (nuxt: Nuxt, getComponents: getComponentsT
|
||||
return createUnplugin(() => ({
|
||||
name: 'nuxt:components:imports',
|
||||
transformInclude (id) {
|
||||
return !isIgnored(id)
|
||||
id = normalize(id)
|
||||
return id.startsWith('virtual:') || id.startsWith(nuxt.options.buildDir) || !isIgnored(id)
|
||||
},
|
||||
async transform (code, id) {
|
||||
// Virtual component wrapper
|
||||
|
@ -76,13 +76,12 @@ function createWatcher () {
|
||||
ignoreInitial: true,
|
||||
ignored: [
|
||||
isIgnored,
|
||||
'.nuxt',
|
||||
'node_modules'
|
||||
]
|
||||
})
|
||||
|
||||
watcher.on('all', (event, path) => nuxt.callHook('builder:watch', event, normalize(path)))
|
||||
nuxt.hook('close', () => watcher.close())
|
||||
nuxt.hook('close', () => watcher?.close())
|
||||
}
|
||||
|
||||
function createGranularWatcher () {
|
||||
@ -104,7 +103,7 @@ function createGranularWatcher () {
|
||||
}
|
||||
for (const dir of pathsToWatch) {
|
||||
pending++
|
||||
const watcher = chokidar.watch(dir, { ...nuxt.options.watchers.chokidar, ignoreInitial: false, depth: 0, ignored: [isIgnored] })
|
||||
const watcher = chokidar.watch(dir, { ...nuxt.options.watchers.chokidar, ignoreInitial: false, depth: 0, ignored: [isIgnored, '**/node_modules'] })
|
||||
const watchers: Record<string, FSWatcher> = {}
|
||||
|
||||
watcher.on('all', (event, path) => {
|
||||
@ -113,13 +112,13 @@ function createGranularWatcher () {
|
||||
nuxt.callHook('builder:watch', event, path)
|
||||
}
|
||||
if (event === 'unlinkDir' && path in watchers) {
|
||||
watchers[path].close()
|
||||
watchers[path]?.close()
|
||||
delete watchers[path]
|
||||
}
|
||||
if (event === 'addDir' && path !== dir && !ignoredDirs.has(path) && !pathsToWatch.includes(path) && !(path in watchers) && !isIgnored(path)) {
|
||||
watchers[path] = chokidar.watch(path, { ...nuxt.options.watchers.chokidar, ignored: [isIgnored] })
|
||||
watchers[path].on('all', (event, path) => nuxt.callHook('builder:watch', event, normalize(path)))
|
||||
nuxt.hook('close', () => watchers[path].close())
|
||||
nuxt.hook('close', () => watchers[path]?.close())
|
||||
}
|
||||
})
|
||||
watcher.on('ready', () => {
|
||||
@ -150,7 +149,6 @@ async function createParcelWatcher () {
|
||||
}, {
|
||||
ignore: [
|
||||
...nuxt.options.ignore,
|
||||
'.nuxt',
|
||||
'node_modules'
|
||||
]
|
||||
})
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { defineUntypedSchema } from 'untyped'
|
||||
import { join, resolve } from 'pathe'
|
||||
import { join, relative, resolve } from 'pathe'
|
||||
import { isDebug, isDevelopment } from 'std-env'
|
||||
import { defu } from 'defu'
|
||||
import { findWorkspaceDir } from 'pkg-types'
|
||||
@ -352,14 +352,13 @@ export default defineUntypedSchema({
|
||||
*/
|
||||
ignore: {
|
||||
$resolve: async (val, get) => [
|
||||
'**/*.stories.{js,ts,jsx,tsx}', // ignore storybook files
|
||||
'**/*.{spec,test}.{js,ts,jsx,tsx}', // ignore tests
|
||||
'**/*.d.ts', // ignore type declarations
|
||||
'.output',
|
||||
'.git',
|
||||
'.cache',
|
||||
await get('analyzeDir'),
|
||||
await get('buildDir'),
|
||||
'**/*.stories.{js,cts,mts,ts,jsx,tsx}', // ignore storybook files
|
||||
'**/*.{spec,test}.{js,cts,mts,ts,jsx,tsx}', // ignore tests
|
||||
'**/*.d.{cts,mts,ts}', // ignore type declarations
|
||||
'**/.{vercel,netlify,output,git,cache,data}',
|
||||
'**/dist',
|
||||
relative(await get('rootDir'), await get('analyzeDir')),
|
||||
relative(await get('rootDir'), await get('buildDir')),
|
||||
await get('ignorePrefix') && `**/${await get('ignorePrefix')}*.*`
|
||||
].concat(val).filter(Boolean)
|
||||
},
|
||||
|
@ -10,7 +10,9 @@ export async function setup () {
|
||||
if (fs.existsSync(tempDir)) {
|
||||
await fs.remove(tempDir)
|
||||
}
|
||||
await fs.copy(fixtureDir, tempDir)
|
||||
await fs.copy(fixtureDir, tempDir, {
|
||||
filter: src => !src.includes('.cache')
|
||||
})
|
||||
}
|
||||
|
||||
export async function teardown () {
|
||||
|
Loading…
Reference in New Issue
Block a user