mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 17:07:22 +00:00
fix(nuxt): don't debounce watcher and include layers (#5002)
This commit is contained in:
parent
11a7340883
commit
fbcbac01d6
@ -13,11 +13,11 @@ export async function build (nuxt: Nuxt) {
|
|||||||
if (nuxt.options.dev) {
|
if (nuxt.options.dev) {
|
||||||
watch(nuxt)
|
watch(nuxt)
|
||||||
nuxt.hook('builder:watch', async (event, path) => {
|
nuxt.hook('builder:watch', async (event, path) => {
|
||||||
if (event !== 'change' && /app|error|plugins/i.test(path)) {
|
if (event !== 'change' && /^(app\.|error\.|plugins\/|layouts\/)/i.test(path)) {
|
||||||
if (path.match(/app/i)) {
|
if (path.startsWith('app')) {
|
||||||
app.mainComponent = null
|
app.mainComponent = null
|
||||||
}
|
}
|
||||||
if (path.match(/error/i)) {
|
if (path.startsWith('error')) {
|
||||||
app.errorComponent = null
|
app.errorComponent = null
|
||||||
}
|
}
|
||||||
await generateApp()
|
await generateApp()
|
||||||
@ -38,7 +38,7 @@ export async function build (nuxt: Nuxt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function watch (nuxt: Nuxt) {
|
function watch (nuxt: Nuxt) {
|
||||||
const watcher = chokidar.watch(nuxt.options.srcDir, {
|
const watcher = chokidar.watch(nuxt.options._layers.map(i => i.config.srcDir), {
|
||||||
...nuxt.options.watchers.chokidar,
|
...nuxt.options.watchers.chokidar,
|
||||||
cwd: nuxt.options.srcDir,
|
cwd: nuxt.options.srcDir,
|
||||||
ignoreInitial: true,
|
ignoreInitial: true,
|
||||||
@ -49,8 +49,7 @@ function watch (nuxt: Nuxt) {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const watchHook = debounce((event: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir', path: string) => nuxt.callHook('builder:watch', event, normalize(path)))
|
watcher.on('all', (event, path) => nuxt.callHook('builder:watch', event, normalize(path)))
|
||||||
watcher.on('all', watchHook)
|
|
||||||
nuxt.hook('close', () => watcher.close())
|
nuxt.hook('close', () => watcher.close())
|
||||||
return watcher
|
return watcher
|
||||||
}
|
}
|
||||||
|
@ -33,11 +33,10 @@ export default defineNuxtModule({
|
|||||||
nuxt.hook('builder:watch', async (event, path) => {
|
nuxt.hook('builder:watch', async (event, path) => {
|
||||||
const dirs = [
|
const dirs = [
|
||||||
nuxt.options.dir.pages,
|
nuxt.options.dir.pages,
|
||||||
nuxt.options.dir.layouts,
|
|
||||||
nuxt.options.dir.middleware
|
nuxt.options.dir.middleware
|
||||||
].filter(Boolean)
|
].filter(Boolean)
|
||||||
|
|
||||||
const pathPattern = new RegExp(`^(${dirs.map(escapeRE).join('|')})/`)
|
const pathPattern = new RegExp(`(^|\\/)(${dirs.map(escapeRE).join('|')})/`)
|
||||||
if (event !== 'change' && path.match(pathPattern)) {
|
if (event !== 'change' && path.match(pathPattern)) {
|
||||||
await nuxt.callHook('builder:generateApp')
|
await nuxt.callHook('builder:generateApp')
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user