From 1f8e3e2f33b182af3354624825d783c80eefffe3 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 2 May 2022 21:15:47 +0100 Subject: [PATCH] feat(nitro): add `nitro:build:before` hook (#4304) * fix(nitro): add back `nitro:generate` hook * fix: use `nitro:generate` hook for vite workarounds * fix: remove comment * fix: only call `nitro:generate` in build mode * rename hook to `nitro:_build` * fix: use `nitro:build:before` * move dev guard Co-authored-by: Pooya Parsa --- packages/nuxt/src/core/nitro.ts | 1 + packages/schema/src/types/hooks.ts | 1 + packages/vite/src/server.ts | 6 ++++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/core/nitro.ts b/packages/nuxt/src/core/nitro.ts index 77f5ede078d..77bfcbbb0c3 100644 --- a/packages/nuxt/src/core/nitro.ts +++ b/packages/nuxt/src/core/nitro.ts @@ -139,6 +139,7 @@ export async function initNitro (nuxt: Nuxt) { // nuxt build/dev nuxt.hook('build:done', async () => { + await nuxt.callHook('nitro:build:before', nitro) if (nuxt.options.dev) { await build(nitro) } else { diff --git a/packages/schema/src/types/hooks.ts b/packages/schema/src/types/hooks.ts index 5b5c2c091ae..9eeccfbc12b 100644 --- a/packages/schema/src/types/hooks.ts +++ b/packages/schema/src/types/hooks.ts @@ -101,6 +101,7 @@ export interface NuxtHooks { // nitropack 'nitro:config': (nitroConfig: NitroConfig) => HookResult 'nitro:init': (nitro: Nitro) => HookResult + 'nitro:build:before': (nitro: Nitro) => HookResult // @nuxt/cli 'generate:cache:ignore': (ignore: string[]) => HookResult diff --git a/packages/vite/src/server.ts b/packages/vite/src/server.ts index cb2f14b8476..cf0204d2cd1 100644 --- a/packages/vite/src/server.ts +++ b/packages/vite/src/server.ts @@ -88,8 +88,10 @@ export async function buildServer (ctx: ViteBuildContext) { await ctx.nuxt.callHook('vite:extendConfig', serverConfig, { isClient: false, isServer: true }) - // TODO: Do we still need this? - ctx.nuxt.hook('build:done', async () => { + ctx.nuxt.hook('nitro:build:before', async () => { + if (ctx.nuxt.options.dev) { + return + } const clientDist = resolve(ctx.nuxt.options.buildDir, 'dist/client') // Remove public files that have been duplicated into buildAssetsDir