Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
feat(nitro): add nitro:build:before hook (#4304)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
danielroe and pi0 authored May 2, 2022
1 parent 0a5da2b commit 1f8e3e2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/nuxt/src/core/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions packages/schema/src/types/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions packages/vite/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1f8e3e2

Please sign in to comment.