From cbce777addb3dd118232a9f28db9d425d4c937b2 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 10 Aug 2021 18:53:46 +0200 Subject: [PATCH] fix(cli): only restart if pages directory itself is changed resolves #429 --- packages/cli/src/commands/dev.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/commands/dev.ts b/packages/cli/src/commands/dev.ts index 35d859ee3f..d6d91eddfa 100644 --- a/packages/cli/src/commands/dev.ts +++ b/packages/cli/src/commands/dev.ts @@ -1,4 +1,4 @@ -import { resolve } from 'upath' +import { resolve, relative } from 'upath' import chokidar from 'chokidar' import debounce from 'debounce-promise' import type { Nuxt } from '@nuxt/kit' @@ -27,9 +27,9 @@ export default defineNuxtCommand({ const { loadNuxt, buildNuxt } = requireModule('@nuxt/kit', rootDir) as typeof import('@nuxt/kit') let currentNuxt: Nuxt - const load = async (isRestart: boolean) => { + const load = async (isRestart: boolean, reason?: string) => { try { - const message = `${isRestart ? 'Restarting' : 'Starting'} nuxt...` + const message = `${reason ? reason + '. ' : ''}${isRestart ? 'Restarting' : 'Starting'} nuxt...` server.setApp(createLoadingHandler(message)) if (isRestart) { console.log(message) @@ -59,12 +59,8 @@ export default defineNuxtCommand({ const dLoad = debounce(load, 250) const watcher = chokidar.watch([rootDir], { ignoreInitial: true, depth: 1 }) watcher.on('all', (_event, file) => { - // Ignore any changes to files within the Nuxt build directory - if (file.includes(currentNuxt.options.buildDir)) { - return - } - if (file.includes('nuxt.config') || file.includes('modules') || file.includes('pages')) { - dLoad(true) + if (file.match(/nuxt\.config\.(js|ts|mjs|cjs)$|pages$/)) { + dLoad(true, `${relative(rootDir, file)} updated`) } })