fix(nuxi): support build:error hook (#1298)

This commit is contained in:
Levi (Nguyễn Lương Huy) 2021-10-21 01:50:01 +07:00 committed by GitHub
parent bfa4a02ca3
commit 7f7794787b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View File

@ -68,12 +68,12 @@ export interface NuxtHooks {
'nitro:context': (context: any) => HookResult 'nitro:context': (context: any) => HookResult
// @nuxt/cli // @nuxt/cli
'cli:buildError': (error: unknown) => HookResult
'generate:cache:ignore': (ignore: string[]) => HookResult 'generate:cache:ignore': (ignore: string[]) => HookResult
'config': (options: NuxtConfig) => HookResult 'config': (options: NuxtConfig) => HookResult
'run:before': (options: { argv: string[], cmd: { name: string, usage: string, description: string, options: Record<string, any> }, rootDir: string }) => HookResult 'run:before': (options: { argv: string[], cmd: { name: string, usage: string, description: string, options: Record<string, any> }, rootDir: string }) => HookResult
// nuxi // nuxi
'build:error': (error: Error) => HookResult
'prepare:types': (options: { references: TSReference[], declarations: string[], tsConfig: TSConfig }) => HookResult 'prepare:types': (options: { references: TSReference[], declarations: string[], tsConfig: TSConfig }) => HookResult
// @nuxt/core // @nuxt/core

View File

@ -24,7 +24,7 @@ export default defineNuxtCommand({
await writeTypes(nuxt) await writeTypes(nuxt)
nuxt.hook('error', (err) => { nuxt.hook('build:error', (err) => {
consola.error('Nuxt Build Error:', err) consola.error('Nuxt Build Error:', err)
process.exit(1) process.exit(1)
}) })

View File

@ -48,5 +48,10 @@ function watch (nuxt: Nuxt) {
async function bundle (nuxt: Nuxt) { async function bundle (nuxt: Nuxt) {
const useVite = nuxt.options.vite !== false const useVite = nuxt.options.vite !== false
const { bundle } = await (useVite ? import('@nuxt/vite-builder') : import('@nuxt/webpack-builder')) 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
}
} }