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 <pyapar@gmail.com>
This commit is contained in:
Daniel Roe 2022-05-02 21:15:47 +01:00 committed by GitHub
parent 0a5da2bd5d
commit 1f8e3e2f33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 2 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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