Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/nuxt/src/core/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
Expand All @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions packages/nuxt/src/pages/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down