Skip to content

Commit 2c6912d

Browse files
committed
docs: add some notes/deprecations for vite hooks
1 parent e384ba3 commit 2c6912d

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

docs/2.guide/4.recipes/2.vite-plugin.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,26 @@ import config from '~/data/hello.yaml'
6363
```
6464

6565
::
66+
67+
## Using Vite Plugins in Nuxt Modules
68+
69+
If you're developing a Nuxt module and need to add Vite plugins, you should use the [`addVitePlugin`](/docs/4.x/api/kit/builder#addviteplugin) utility:
70+
71+
```ts [modules/my-module.ts]
72+
import { addVitePlugin, defineNuxtModule } from '@nuxt/kit'
73+
import yaml from '@rollup/plugin-yaml'
74+
75+
export default defineNuxtModule({
76+
setup () {
77+
addVitePlugin(yaml())
78+
},
79+
})
80+
```
81+
82+
::important
83+
If you're writing code that needs to access resolved Vite configuration, you should use the `config` and `configResolved` hooks _within_ your Vite plugin, rather than using Nuxt's `vite:extend`, `vite:extendConfig` and `vite:configResolved`.
84+
::
85+
86+
::read-more{to="/docs/4.x/api/kit/builder#addviteplugin"}
87+
Read more about `addVitePlugin` in the Nuxt Kit documentation.
88+
::

docs/3.api/5.kit/14.builder.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Nuxt have builders based on [Vite](https://github.com/nuxt/nuxt/tree/main/packag
1414

1515
Extends the Vite configuration. Callback function can be called multiple times, when applying to both client and server builds.
1616

17+
::warning
18+
This hook is now deprecated, and we recommend using a Vite plugin instead with a `config` hook.
19+
::
20+
1721
### Usage
1822

1923
```ts twoslash

docs/3.api/5.kit/15.examples.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ import { buildNuxt, loadNuxt } from '@nuxt/kit'
2222
async function getViteConfig () {
2323
const nuxt = await loadNuxt({ cwd: process.cwd(), dev: false, overrides: { ssr: false } })
2424
return new Promise((resolve, reject) => {
25-
nuxt.hook('vite:extendConfig', (config, { isClient }) => {
26-
if (isClient) {
27-
resolve(config)
28-
throw new Error('_stop_')
29-
}
25+
nuxt.hook('vite:extend', (config) => {
26+
resolve(config)
27+
throw new Error('_stop_')
3028
})
3129
buildNuxt(nuxt).catch((err) => {
3230
if (!err.toString().includes('_stop_')) {

docs/3.api/6.advanced/1.hooks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ Hook | Arguments | Description
7575
`schema:beforeWrite` | `schema` | Called before writing the given schema.
7676
`schema:written` | - | Called after the schema is written.
7777
`vite:extend` | `viteBuildContext` | Allows extending Vite default context.
78-
`vite:extendConfig` | `viteInlineConfig, env` | Allows extending Vite default config.
79-
`vite:configResolved` | `viteInlineConfig, env` | Allows reading the resolved Vite config.
78+
`vite:extendConfig` | `viteInlineConfig, env` | Allows extending Vite default config. **Deprecated.** We recommend adding a Vite plugin with a `config` hook.
79+
`vite:configResolved` | `viteInlineConfig, env` | Allows reading the resolved Vite config. **Deprecated.** We recommend adding a Vite plugin with a `configResolved` hook.
8080
`vite:serverCreated` | `viteServer, env` | Called when the Vite server is created.
8181
`vite:compiled` | - | Called after Vite server is compiled.
8282
`webpack:config` | `webpackConfigs` | Called before configuring the webpack compiler.

0 commit comments

Comments
 (0)