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

This commit is contained in:
Anthony Fu 2023-04-30 00:37:06 +02:00 committed by GitHub
parent fac160c79f
commit 17ca50354b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 0 deletions

View File

@ -71,6 +71,7 @@ Hook | Arguments | Description
`schema:written` | - | Called after the schema is written. `schema:written` | - | Called after the schema is written.
`vite:extend` | `viteBuildContext` | Allows to extend Vite default context. `vite:extend` | `viteBuildContext` | Allows to extend Vite default context.
`vite:extendConfig` | `viteInlineConfig, env` | Allows to extend Vite default config. `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:serverCreated` | `viteServer, env` | Called when the Vite server is created.
`vite:compiled` | - | Called after Vite server is compiled. `vite:compiled` | - | Called after Vite server is compiled.
`webpack:config` | `webpackConfigs` | Called before configuring the webpack compiler. `webpack:config` | `webpackConfigs` | Called before configuring the webpack compiler.

View File

@ -290,6 +290,13 @@ export interface NuxtHooks {
* @returns Promise * @returns Promise
*/ */
'vite:extendConfig': (viteInlineConfig: ViteConfig, env: { isClient: boolean, isServer: boolean }) => HookResult '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. * Called when the Vite server is created.
* @param viteServer Vite development server * @param viteServer Vite development server

View File

@ -127,6 +127,8 @@ export async function buildClient (ctx: ViteBuildContext) {
viteJsxPlugin(clientConfig.vueJsx) viteJsxPlugin(clientConfig.vueJsx)
) )
await ctx.nuxt.callHook('vite:configResolved', clientConfig, { isClient: true, isServer: false })
if (ctx.nuxt.options.dev) { if (ctx.nuxt.options.dev) {
// Dev // Dev
const viteServer = await vite.createServer(clientConfig) const viteServer = await vite.createServer(clientConfig)

View File

@ -148,6 +148,8 @@ export async function buildServer (ctx: ViteBuildContext) {
viteJsxPlugin(serverConfig.vueJsx) viteJsxPlugin(serverConfig.vueJsx)
) )
await ctx.nuxt.callHook('vite:configResolved', serverConfig, { isClient: false, isServer: true })
const onBuild = () => ctx.nuxt.callHook('vite:compiled') const onBuild = () => ctx.nuxt.callHook('vite:compiled')
// Production build // Production build