Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nuxi): reload nuxt when restart hook is called #19084

Merged
merged 7 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/3.api/4.advanced/1.hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Hook | Arguments | Description
`kit:compatibility` | `compatibility, issues` | Allows extending compatibility checks.
`ready` | `nuxt` | Called after Nuxt initialization, when the Nuxt instance is ready to work.
`close` | `nuxt` | Called when Nuxt instance is gracefully closing.
`restart` | - | Called when Nuxt instance is restarting.
danielroe marked this conversation as resolved.
Show resolved Hide resolved
`modules:before` | - | Called during Nuxt initialization, before installing user modules.
`modules:done` | - | Called during Nuxt initialization, after installing user modules.
`app:resolve` | `app` | Called after resolving the `app` instance.
Expand Down
2 changes: 2 additions & 0 deletions packages/nuxi/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export default defineNuxtCommand({
await currentNuxt.close()
}
currentNuxt = await loadNuxt({ rootDir, dev: true, ready: false })
currentNuxt.hook('restart', () => load(true))
Baroshem marked this conversation as resolved.
Show resolved Hide resolved

if (!isRestart) {
showURL()
}
Expand Down
7 changes: 6 additions & 1 deletion packages/schema/src/types/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface NuxtHooks {
'kit:compatibility': (compatibility: NuxtCompatibility, issues: NuxtCompatibilityIssues) => HookResult

// Nuxt
/**
/**
* Called after Nuxt initialization, when the Nuxt instance is ready to work.
* @param nuxt The configured Nuxt object
* @returns Promise
Expand All @@ -73,6 +73,11 @@ export interface NuxtHooks {
* @returns Promise
*/
'close': (nuxt: Nuxt) => HookResult
/**
* Called when Nuxt instance is restarting.
* @returns Promise
*/
'restart': () => HookResult
danielroe marked this conversation as resolved.
Show resolved Hide resolved

/**
* Called during Nuxt initialization, before installing user modules.
Expand Down