Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vite): introduce vite:configResolved hook #20411

Merged
merged 1 commit into from Apr 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/3.api/4.advanced/1.hooks.md
Expand Up @@ -71,6 +71,7 @@ Hook | Arguments | Description
`schema:written` | - | Called after the schema is written.
`vite:extend` | `viteBuildContext` | Allows to extend Vite default context.
`vite:extendConfig` | `viteInlineConfig, env` | Allows to extend Vite default config.
`vite:configResolved` | `viteInlineConfig, env` | Allows to read the resolved Vite config.
`vite:serverCreated` | `viteServer, env` | Called when the Vite server is created.
`vite:compiled` | - | Called after Vite server is compiled.
`webpack:config` | `webpackConfigs` | Called before configuring the webpack compiler.
Expand Down
7 changes: 7 additions & 0 deletions packages/schema/src/types/hooks.ts
Expand Up @@ -290,6 +290,13 @@ export interface NuxtHooks {
* @returns Promise
*/
'vite:extendConfig': (viteInlineConfig: ViteConfig, env: { isClient: boolean, isServer: boolean }) => HookResult
/**
* Allows to read the resolved Vite config.
* @param viteInlineConfig The vite inline config object
* @param env Server or client
* @returns Promise
*/
'vite:configResolved': (viteInlineConfig: Readonly<ViteConfig>, env: { isClient: boolean, isServer: boolean }) => HookResult
/**
* Called when the Vite server is created.
* @param viteServer Vite development server
Expand Down
2 changes: 2 additions & 0 deletions packages/vite/src/client.ts
Expand Up @@ -127,6 +127,8 @@ export async function buildClient (ctx: ViteBuildContext) {
viteJsxPlugin(clientConfig.vueJsx)
)

await ctx.nuxt.callHook('vite:configResolved', clientConfig, { isClient: true, isServer: false })

if (ctx.nuxt.options.dev) {
// Dev
const viteServer = await vite.createServer(clientConfig)
Expand Down
2 changes: 2 additions & 0 deletions packages/vite/src/server.ts
Expand Up @@ -148,6 +148,8 @@ export async function buildServer (ctx: ViteBuildContext) {
viteJsxPlugin(serverConfig.vueJsx)
)

await ctx.nuxt.callHook('vite:configResolved', serverConfig, { isClient: false, isServer: true })

const onBuild = () => ctx.nuxt.callHook('vite:compiled')

// Production build
Expand Down