Skip to content

Commit

Permalink
fix(nuxi): support build:error hook (nuxt#1298)
Browse files Browse the repository at this point in the history
  • Loading branch information
huynl-96 authored Oct 20, 2021
1 parent bfa4a02 commit 7f77947
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/kit/src/types/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ export interface NuxtHooks {
'nitro:context': (context: any) => HookResult

// @nuxt/cli
'cli:buildError': (error: unknown) => HookResult
'generate:cache:ignore': (ignore: string[]) => HookResult
'config': (options: NuxtConfig) => HookResult
'run:before': (options: { argv: string[], cmd: { name: string, usage: string, description: string, options: Record<string, any> }, rootDir: string }) => HookResult

// nuxi
'build:error': (error: Error) => HookResult
'prepare:types': (options: { references: TSReference[], declarations: string[], tsConfig: TSConfig }) => HookResult

// @nuxt/core
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxi/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default defineNuxtCommand({

await writeTypes(nuxt)

nuxt.hook('error', (err) => {
nuxt.hook('build:error', (err) => {
consola.error('Nuxt Build Error:', err)
process.exit(1)
})
Expand Down
7 changes: 6 additions & 1 deletion packages/nuxt3/src/core/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@ function watch (nuxt: Nuxt) {
async function bundle (nuxt: Nuxt) {
const useVite = nuxt.options.vite !== false
const { bundle } = await (useVite ? import('@nuxt/vite-builder') : import('@nuxt/webpack-builder'))
return bundle(nuxt)
try {
return bundle(nuxt)
} catch (error) {
await nuxt.callHook('build:error', error)
throw error
}
}

0 comments on commit 7f77947

Please sign in to comment.