mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +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) {
|
||||
watch(nuxt)
|
||||
nuxt.hook('builder:watch', async (event, path) => {
|
||||
if (event !== 'change' && /app|error|plugins/i.test(path)) {
|
||||
if (path.match(/app/i)) {
|
||||
if (event !== 'change' && /^(app\.|error\.|plugins\/|layouts\/)/i.test(path)) {
|
||||
if (path.startsWith('app')) {
|
||||
app.mainComponent = null
|
||||
}
|
||||
if (path.match(/error/i)) {
|
||||
if (path.startsWith('error')) {
|
||||
app.errorComponent = null
|
||||
}
|
||||
await generateApp()
|
||||
@ -38,7 +38,7 @@ export async function build (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,
|
||||
cwd: nuxt.options.srcDir,
|
||||
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', watchHook)
|
||||
watcher.on('all', (event, path) => nuxt.callHook('builder:watch', event, normalize(path)))
|
||||
nuxt.hook('close', () => watcher.close())
|
||||
return watcher
|
||||
}
|
||||
|
@ -33,11 +33,10 @@ export default defineNuxtModule({
|
||||
nuxt.hook('builder:watch', async (event, path) => {
|
||||
const dirs = [
|
||||
nuxt.options.dir.pages,
|
||||
nuxt.options.dir.layouts,
|
||||
nuxt.options.dir.middleware
|
||||
].filter(Boolean)
|
||||
|
||||
const pathPattern = new RegExp(`^(${dirs.map(escapeRE).join('|')})/`)
|
||||
const pathPattern = new RegExp(`(^|\\/)(${dirs.map(escapeRE).join('|')})/`)
|
||||
if (event !== 'change' && path.match(pathPattern)) {
|
||||
await nuxt.callHook('builder:generateApp')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user