mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 09:25:54 +00:00
fix(cli): only restart if pages directory itself is changed
resolves #429
This commit is contained in:
parent
991a231018
commit
cbce777add
@ -1,4 +1,4 @@
|
|||||||
import { resolve } from 'upath'
|
import { resolve, relative } from 'upath'
|
||||||
import chokidar from 'chokidar'
|
import chokidar from 'chokidar'
|
||||||
import debounce from 'debounce-promise'
|
import debounce from 'debounce-promise'
|
||||||
import type { Nuxt } from '@nuxt/kit'
|
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')
|
const { loadNuxt, buildNuxt } = requireModule('@nuxt/kit', rootDir) as typeof import('@nuxt/kit')
|
||||||
|
|
||||||
let currentNuxt: Nuxt
|
let currentNuxt: Nuxt
|
||||||
const load = async (isRestart: boolean) => {
|
const load = async (isRestart: boolean, reason?: string) => {
|
||||||
try {
|
try {
|
||||||
const message = `${isRestart ? 'Restarting' : 'Starting'} nuxt...`
|
const message = `${reason ? reason + '. ' : ''}${isRestart ? 'Restarting' : 'Starting'} nuxt...`
|
||||||
server.setApp(createLoadingHandler(message))
|
server.setApp(createLoadingHandler(message))
|
||||||
if (isRestart) {
|
if (isRestart) {
|
||||||
console.log(message)
|
console.log(message)
|
||||||
@ -59,12 +59,8 @@ export default defineNuxtCommand({
|
|||||||
const dLoad = debounce(load, 250)
|
const dLoad = debounce(load, 250)
|
||||||
const watcher = chokidar.watch([rootDir], { ignoreInitial: true, depth: 1 })
|
const watcher = chokidar.watch([rootDir], { ignoreInitial: true, depth: 1 })
|
||||||
watcher.on('all', (_event, file) => {
|
watcher.on('all', (_event, file) => {
|
||||||
// Ignore any changes to files within the Nuxt build directory
|
if (file.match(/nuxt\.config\.(js|ts|mjs|cjs)$|pages$/)) {
|
||||||
if (file.includes(currentNuxt.options.buildDir)) {
|
dLoad(true, `${relative(rootDir, file)} updated`)
|
||||||
return
|
|
||||||
}
|
|
||||||
if (file.includes('nuxt.config') || file.includes('modules') || file.includes('pages')) {
|
|
||||||
dLoad(true)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user