mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
fix(nuxi): watch dist and register restart hook after nuxt is ready (#19736)
This commit is contained in:
parent
2c642328c9
commit
9d0d4e207d
@ -101,27 +101,10 @@ export default defineNuxtCommand({
|
||||
}
|
||||
})
|
||||
|
||||
currentNuxt.hooks.hookOnce('restart', async (options) => {
|
||||
if (options?.hard && process.send) {
|
||||
await listener.close().catch(() => {})
|
||||
await currentNuxt.close().catch(() => {})
|
||||
await watcher.close().catch(() => {})
|
||||
await distWatcher.close().catch(() => {})
|
||||
process.send({ type: 'nuxt:restart' })
|
||||
} else {
|
||||
await load(true)
|
||||
}
|
||||
})
|
||||
|
||||
if (!isRestart) {
|
||||
showURL()
|
||||
}
|
||||
|
||||
distWatcher = chokidar.watch(resolve(currentNuxt.options.buildDir, 'dist'), { ignoreInitial: true, depth: 0 })
|
||||
distWatcher.on('unlinkDir', () => {
|
||||
dLoad(true, '.nuxt/dist directory has been removed')
|
||||
})
|
||||
|
||||
// Write manifest and also check if we need cache invalidation
|
||||
if (!isRestart) {
|
||||
const previousManifest = await loadNuxtManifest(currentNuxt.options.buildDir)
|
||||
@ -133,6 +116,24 @@ export default defineNuxtCommand({
|
||||
|
||||
await currentNuxt.ready()
|
||||
|
||||
distWatcher = chokidar.watch(resolve(currentNuxt.options.buildDir, 'dist'), { ignoreInitial: true, depth: 0 })
|
||||
distWatcher.on('unlinkDir', () => {
|
||||
dLoad(true, '.nuxt/dist directory has been removed')
|
||||
})
|
||||
|
||||
const unsub = currentNuxt.hooks.hook('restart', async (options) => {
|
||||
unsub() // we use this instead of `hookOnce` for Nuxt Bridge support
|
||||
if (options?.hard && process.send) {
|
||||
await listener.close().catch(() => {})
|
||||
await currentNuxt.close().catch(() => {})
|
||||
await watcher.close().catch(() => {})
|
||||
await distWatcher.close().catch(() => {})
|
||||
process.send({ type: 'nuxt:restart' })
|
||||
} else {
|
||||
await load(true)
|
||||
}
|
||||
})
|
||||
|
||||
await currentNuxt.hooks.callHook('listen', listener.server, listener)
|
||||
const address = (listener.server.address() || {}) as AddressInfo
|
||||
currentNuxt.options.devServer.url = listener.url
|
||||
|
Loading…
Reference in New Issue
Block a user