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