Skip to content

Commit

Permalink
fix(nuxi): restart nuxt when distDir is unlinked (#19131)
Browse files Browse the repository at this point in the history
  • Loading branch information
huang-julien committed Feb 20, 2023
1 parent b3ce956 commit eaeb4f0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/nuxi/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export default defineNuxtCommand({
})

let currentNuxt: Nuxt
let distWatcher: chokidar.FSWatcher

const showURL = () => {
listener.showURL({
// TODO: Normalize URL with trailing slash within schema
Expand All @@ -82,11 +84,20 @@ export default defineNuxtCommand({
if (currentNuxt) {
await currentNuxt.close()
}
if (distWatcher) {
await distWatcher.close()
}

currentNuxt = await loadNuxt({ rootDir, dev: true, ready: false })
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)
Expand Down

0 comments on commit eaeb4f0

Please sign in to comment.