@nuxt/docs 3.19.3 → 3.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/1.getting-started/02.installation.md +3 -3
  2. package/1.getting-started/07.routing.md +4 -0
  3. package/1.getting-started/10.data-fetching.md +12 -12
  4. package/1.getting-started/14.layers.md +28 -9
  5. package/1.getting-started/18.upgrade.md +8 -4
  6. package/2.guide/1.directory-structure/1.node_modules.md +1 -1
  7. package/2.guide/1.directory-structure/3.tsconfig.md +23 -0
  8. package/2.guide/2.concepts/7.esm.md +5 -1
  9. package/2.guide/2.concepts/9.code-style.md +1 -1
  10. package/2.guide/3.going-further/1.experimental-features.md +92 -4
  11. package/2.guide/3.going-further/3.modules.md +36 -20
  12. package/2.guide/3.going-further/7.layers.md +44 -19
  13. package/2.guide/4.recipes/2.vite-plugin.md +41 -0
  14. package/3.api/1.components/13.nuxt-time.md +5 -1
  15. package/3.api/2.composables/use-async-data.md +80 -13
  16. package/3.api/2.composables/use-cookie.md +1 -1
  17. package/3.api/2.composables/use-fetch.md +5 -1
  18. package/3.api/2.composables/use-head-safe.md +37 -20
  19. package/3.api/2.composables/use-head.md +136 -36
  20. package/3.api/2.composables/use-hydration.md +24 -18
  21. package/3.api/2.composables/use-lazy-async-data.md +59 -10
  22. package/3.api/2.composables/use-lazy-fetch.md +66 -10
  23. package/3.api/2.composables/use-nuxt-app.md +1 -1
  24. package/3.api/2.composables/use-nuxt-data.md +1 -1
  25. package/3.api/2.composables/use-request-fetch.md +1 -1
  26. package/3.api/2.composables/use-route.md +1 -1
  27. package/3.api/2.composables/use-runtime-hook.md +1 -1
  28. package/3.api/3.utils/navigate-to.md +1 -1
  29. package/3.api/3.utils/refresh-cookie.md +2 -2
  30. package/3.api/5.kit/1.modules.md +88 -2
  31. package/3.api/5.kit/11.nitro.md +4 -0
  32. package/3.api/5.kit/14.builder.md +60 -4
  33. package/3.api/5.kit/15.examples.md +3 -5
  34. package/3.api/5.kit/2.programmatic.md +2 -2
  35. package/3.api/5.kit/5.components.md +1 -0
  36. package/3.api/5.kit/9.head.md +132 -0
  37. package/3.api/6.advanced/1.hooks.md +2 -2
  38. package/5.community/3.reporting-bugs.md +1 -1
  39. package/package.json +1 -1
@@ -8,21 +8,81 @@ links:
8
8
  size: xs
9
9
  ---
10
10
 
11
- ## Description
11
+ `useLazyFetch` provides a wrapper around [`useFetch`](/docs/3.x/api/composables/use-fetch) that triggers navigation before the handler is resolved by setting the `lazy` option to `true`.
12
12
 
13
- By default, [`useFetch`](/docs/3.x/api/composables/use-fetch) blocks navigation until its async handler is resolved. `useLazyFetch` provides a wrapper around [`useFetch`](/docs/3.x/api/composables/use-fetch) that triggers navigation before the handler is resolved by setting the `lazy` option to `true`.
13
+ ## Usage
14
+
15
+ By default, [`useFetch`](/docs/3.x/api/composables/use-fetch) blocks navigation until its async handler is resolved. `useLazyFetch` allows navigation to proceed immediately, with data being fetched in the background.
16
+
17
+ ```vue [app/pages/index.vue]
18
+ <script setup lang="ts">
19
+ const { status, data: posts } = await useLazyFetch('/api/posts')
20
+ </script>
21
+
22
+ <template>
23
+ <div v-if="status === 'pending'">
24
+ Loading ...
25
+ </div>
26
+ <div v-else>
27
+ <div v-for="post in posts">
28
+ <!-- do something -->
29
+ </div>
30
+ </div>
31
+ </template>
32
+ ```
14
33
 
15
34
  ::note
16
35
  `useLazyFetch` has the same signature as [`useFetch`](/docs/3.x/api/composables/use-fetch).
17
36
  ::
18
37
 
38
+ ::warning
39
+ Awaiting `useLazyFetch` only ensures the call is initialized. On client-side navigation, data may not be immediately available, and you must handle the `pending` state in your component's template.
40
+ ::
41
+
42
+ ::warning
43
+ `useLazyFetch` is a reserved function name transformed by the compiler, so you should not name your own function `useLazyFetch`.
44
+ ::
45
+
46
+ ## Type
47
+
48
+ ```ts [Signature]
49
+ export function useLazyFetch<DataT, ErrorT> (
50
+ url: string | Request | Ref<string | Request> | (() => string | Request),
51
+ options?: UseFetchOptions<DataT>,
52
+ ): Promise<AsyncData<DataT, ErrorT>>
53
+ ```
54
+
19
55
  ::note
20
- Awaiting `useLazyFetch` in this mode only ensures the call is initialized. On client-side navigation, data may not be immediately available, and you should make sure to handle the pending state in your app.
56
+ `useLazyFetch` is equivalent to `useFetch` with `lazy: true` option set. See [`useFetch`](/docs/3.x/api/composables/use-fetch) for full type definitions.
21
57
  ::
22
58
 
23
- :read-more{to="/docs/api/composables/use-fetch"}
59
+ ## Parameters
60
+
61
+ `useLazyFetch` accepts the same parameters as [`useFetch`](/docs/3.x/api/composables/use-fetch):
62
+
63
+ - `URL` (`string | Request | Ref<string | Request> | () => string | Request`): The URL or request to fetch.
64
+ - `options` (object): Same as [`useFetch` options](/docs/3.x/api/composables/use-fetch#parameters), with `lazy` automatically set to `true`.
65
+
66
+ :read-more{to="/docs/3.x/api/composables/use-fetch#parameters"}
24
67
 
25
- ## Example
68
+ ## Return Values
69
+
70
+ Returns the same `AsyncData` object as [`useFetch`](/docs/3.x/api/composables/use-fetch):
71
+
72
+ | Name | Type | Description |
73
+ | --- | --- |--- |
74
+ | `data` | `Ref<DataT \| undefined>` | The result of the asynchronous fetch. |
75
+ | `refresh` | `(opts?: AsyncDataExecuteOptions) => Promise<void>` | Function to manually refresh the data. |
76
+ | `execute` | `(opts?: AsyncDataExecuteOptions) => Promise<void>` | Alias for `refresh`. |
77
+ | `error` | `Ref<ErrorT \| undefined>` | Error object if the data fetching failed. |
78
+ | `status` | `Ref<'idle' \| 'pending' \| 'success' \| 'error'>` | Status of the data request. |
79
+ | `clear` | `() => void` | Resets `data` to `undefined`, `error` to `undefined`, sets `status` to `idle`, and cancels any pending requests. |
80
+
81
+ :read-more{to="/docs/3.x/api/composables/use-fetch#return-values"}
82
+
83
+ ## Examples
84
+
85
+ ### Handling Pending State
26
86
 
27
87
  ```vue [pages/index.vue]
28
88
  <script setup lang="ts">
@@ -48,8 +108,4 @@ watch(posts, (newPosts) => {
48
108
  </template>
49
109
  ```
50
110
 
51
- ::note
52
- `useLazyFetch` is a reserved function name transformed by the compiler, so you should not name your own function `useLazyFetch`.
53
- ::
54
-
55
- :read-more{to="/docs/getting-started/data-fetching"}
111
+ :read-more{to="/docs/3.x/getting-started/data-fetching"}
@@ -108,7 +108,7 @@ Nuxt exposes the following properties through `ssrContext`:
108
108
  ::code-group
109
109
  ```vue [app.vue]
110
110
  <script setup lang="ts">
111
- const { data } = await useAsyncData('count', () => $fetch('/api/count'))
111
+ const { data } = await useAsyncData('count', (_nuxtApp, { signal }) => $fetch('/api/count', { signal }))
112
112
  </script>
113
113
  ```
114
114
  ```ts [server/api/count.ts]
@@ -67,7 +67,7 @@ Optimistic Updates is a technique where the user interface is updated immediatel
67
67
  ```vue [pages/todos.vue]
68
68
  <script setup lang="ts">
69
69
  // We can access same data later using 'todos' key
70
- const { data } = await useAsyncData('todos', () => $fetch('/api/todos'))
70
+ const { data } = await useAsyncData('todos', (_nuxtApp, { signal }) => $fetch('/api/todos', { signal }))
71
71
  </script>
72
72
  ```
73
73
 
@@ -33,7 +33,7 @@ const { data: forwarded } = await useAsyncData(() => requestFetch('/api/cookies'
33
33
 
34
34
  // This will NOT forward anything
35
35
  // Result: { cookies: {} }
36
- const { data: notForwarded } = await useAsyncData(() => $fetch('/api/cookies'))
36
+ const { data: notForwarded } = await useAsyncData((_nuxtApp, { signal }) => $fetch('/api/cookies', { signal }))
37
37
  </script>
38
38
  ```
39
39
 
@@ -76,7 +76,7 @@ The `useRoute()` composable should only be used in the setup function of a Vue c
76
76
  This applies to any composable that uses `useRoute()` internally too.
77
77
  ::
78
78
 
79
- ::read-more{to="/docs/4.x/guide/directory-structure/app/middleware"}
79
+ ::read-more{to="/docs/3.x/guide/directory-structure/app/middleware"}
80
80
  Read more about accessing the route in the middleware section.
81
81
  ::
82
82
 
@@ -15,7 +15,7 @@ This composable is available in Nuxt v3.14+.
15
15
  ```ts [signature]
16
16
  function useRuntimeHook<THookName extends keyof RuntimeNuxtHooks> (
17
17
  name: THookName,
18
- fn: RuntimeNuxtHooks[THookName] extends HookCallback ? RuntimeNuxtHooks[THookName] : never
18
+ fn: RuntimeNuxtHooks[THookName] extends HookCallback ? RuntimeNuxtHooks[THookName] : never,
19
19
  ): void
20
20
  ```
21
21
 
@@ -119,7 +119,7 @@ await navigateTo('https://nuxt.com', {
119
119
  ```ts [Signature]
120
120
  export function navigateTo (
121
121
  to: RouteLocationRaw | undefined | null,
122
- options?: NavigateToOptions
122
+ options?: NavigateToOptions,
123
123
  ): Promise<void | NavigationFailure | false> | false | void | RouteLocationRaw
124
124
 
125
125
  interface NavigateToOptions {
@@ -35,8 +35,8 @@ const loggedIn = computed(() => !!tokenCookie.value)
35
35
  </script>
36
36
  ```
37
37
 
38
- ::note{to="/docs/guide/going-further/experimental-features#cookiestore"}
39
- You can enable experimental `cookieStore` option to automatically refresh `useCookie` value when cookie changes in the browser.
38
+ ::note{to="/docs/3.x/guide/going-further/experimental-features#cookiestore"}
39
+ Since [Nuxt v3.12.0](https://github.com/nuxt/nuxt/releases/tag/v3.12.0), the experimental `cookieStore` option is enabled by default. It automatically refreshes the `useCookie` value when cookies change in the browser.
40
40
  ::
41
41
 
42
42
  ## Type
@@ -8,7 +8,7 @@ links:
8
8
  size: xs
9
9
  ---
10
10
 
11
- Modules are the building blocks of Nuxt. Kit provides a set of utilities to help you create and use modules. You can use these utilities to create your own modules or to reuse existing modules. For example, you can use the `defineNuxtModule` function to define a module and the `installModule` function to install a module programmatically.
11
+ Modules are the building blocks of Nuxt. Kit provides a set of utilities to help you create and use modules. You can use these utilities to create your own modules or to reuse existing modules. For example, you can use the `defineNuxtModule` function to define a module and specify dependencies using the `moduleDependencies` option.
12
12
 
13
13
  ## `defineNuxtModule`
14
14
 
@@ -47,7 +47,7 @@ export function defineNuxtModule<TOptions extends ModuleOptions> (
47
47
 
48
48
  export function defineNuxtModule<TOptions extends ModuleOptions> (): {
49
49
  with: <TOptionsDefaults extends Partial<TOptions>> (
50
- definition: ModuleDefinition<TOptions, TOptionsDefaults, true> | NuxtModule<TOptions, TOptionsDefaults, true>
50
+ definition: ModuleDefinition<TOptions, TOptionsDefaults, true> | NuxtModule<TOptions, TOptionsDefaults, true>,
51
51
  ) => NuxtModule<TOptions, TOptionsDefaults, true>
52
52
  }
53
53
  ```
@@ -62,6 +62,7 @@ export function defineNuxtModule<TOptions extends ModuleOptions> (): {
62
62
  | `defaults` | `T \| ((nuxt: Nuxt) => T)`{lang="ts"} | `false` | Default options for the module. If a function is provided, it will be called with the Nuxt instance as the first argument. |
63
63
  | `schema` | `T` | `false` | Schema for the module options. If provided, options will be applied to the schema. |
64
64
  | `hooks` | `Partial<NuxtHooks>`{lang="ts"} | `false` | Hooks to be installed for the module. If provided, the module will install the hooks. |
65
+ | `moduleDependencies` | `Record<string, ModuleDependency> \| ((nuxt: Nuxt) => Record<string, ModuleDependency>)`{lang="ts"} | `false` | Dependencies on other modules with version constraints and configuration. Can be an object or a function that receives the Nuxt instance. See [example](#specifying-module-dependencies). |
65
66
  | `onInstall` | `(nuxt: Nuxt) => Awaitable<void>`{lang="ts"} | `false` | Lifecycle hook called when the module is first installed. Requires `meta.name` and `meta.version` to be defined. |
66
67
  | `onUpgrade` | `(options: T, nuxt: Nuxt, previousVersion: string) => Awaitable<void>`{lang="ts"} | `false` | Lifecycle hook called when the module is upgraded to a newer version. Requires `meta.name` and `meta.version` to be defined. |
67
68
  | `setup` | `(this: void, resolvedOptions: T, nuxt: Nuxt) => Awaitable<void \| false \| ModuleSetupInstallResult>`{lang="ts"} | `false` | Setup function for the module. If provided, the module will call the setup function. |
@@ -239,8 +240,93 @@ export default defineNuxtModule({
239
240
  })
240
241
  ```
241
242
 
243
+ #### Specifying Module Dependencies
244
+
245
+ You can use the `moduleDependencies` option to declare dependencies on other modules. This provides a robust way to ensure proper setup order, version compatibility, and configuration management.
246
+
247
+ The `moduleDependencies` option can be either an object or a function that receives the Nuxt instance:
248
+
249
+ ##### Example
250
+
251
+ ```ts
252
+ import { defineNuxtModule } from '@nuxt/kit'
253
+
254
+ export default defineNuxtModule({
255
+ meta: {
256
+ name: 'my-module',
257
+ },
258
+ moduleDependencies: {
259
+ '@nuxtjs/tailwindcss': {
260
+ // Specify a version constraint (semver format)
261
+ version: '>=6.0.0',
262
+ // Configuration that overrides user settings
263
+ overrides: {
264
+ exposeConfig: true,
265
+ },
266
+ // Configuration that sets defaults but respects user settings
267
+ defaults: {
268
+ config: {
269
+ darkMode: 'class',
270
+ },
271
+ },
272
+ },
273
+ '@nuxtjs/fontaine': {
274
+ // Optional dependencies won't be installed but ensure that options
275
+ // can be set if they _are_ installed
276
+ optional: true,
277
+ defaults: {
278
+ fonts: [
279
+ {
280
+ family: 'Roboto',
281
+ fallbacks: ['Impact'],
282
+ },
283
+ ],
284
+ },
285
+ },
286
+ },
287
+ setup (options, nuxt) {
288
+
289
+ },
290
+ })
291
+ ```
292
+
293
+ You can also use a function to dynamically determine dependencies based on the Nuxt configuration:
294
+
295
+ ```ts
296
+ import { defineNuxtModule } from '@nuxt/kit'
297
+
298
+ export default defineNuxtModule({
299
+ meta: {
300
+ name: 'my-module',
301
+ },
302
+ moduleDependencies (nuxt) {
303
+ const dependencies: Record<string, any> = {
304
+ '@nuxtjs/tailwindcss': {
305
+ version: '>=6.0.0',
306
+ },
307
+ }
308
+
309
+ // Conditionally add dependencies based on Nuxt config
310
+ if (nuxt.options.experimental?.someFeature) {
311
+ dependencies['@nuxtjs/fontaine'] = {
312
+ optional: true,
313
+ }
314
+ }
315
+
316
+ return dependencies
317
+ },
318
+ setup (options, nuxt) {
319
+ // Your setup logic runs after all dependencies are initialized
320
+ },
321
+ })
322
+ ```
323
+
242
324
  ## `installModule`
243
325
 
326
+ ::callout{type="warning"}
327
+ **Deprecated:** Use the [`moduleDependencies`](#specifying-module-dependencies) option in `defineNuxtModule` instead. The `installModule` function will be removed (or may become non-blocking) in a future version.
328
+ ::
329
+
244
330
  Install specified Nuxt module programmatically. This is helpful when your module depends on other modules. You can pass the module options as an object to `inlineOptions` and they will be passed to the module's `setup` function.
245
331
 
246
332
  ### Usage
@@ -197,6 +197,10 @@ Add plugin to extend Nitro's runtime behavior.
197
197
  You can read more about Nitro plugins in the [Nitro documentation](https://nitro.build/guide/plugins).
198
198
  ::
199
199
 
200
+ ::warning
201
+ It is necessary to explicitly import `defineNitroPlugin` from `nitropack/runtime` within your plugin file. The same requirement applies to utilities such as `useRuntimeConfig`.
202
+ ::
203
+
200
204
  ### Usage
201
205
 
202
206
  ```ts twoslash
@@ -14,6 +14,10 @@ Nuxt have builders based on [Vite](https://github.com/nuxt/nuxt/tree/main/packag
14
14
 
15
15
  Extends the Vite configuration. Callback function can be called multiple times, when applying to both client and server builds.
16
16
 
17
+ ::warning
18
+ This hook is now deprecated, and we recommend using a Vite plugin instead with a `config` hook, or &mdash; for environment-specific configuration &mdash; the `applyToEnvironment` hook.
19
+ ::
20
+
17
21
  ### Usage
18
22
 
19
23
  ```ts twoslash
@@ -30,6 +34,45 @@ export default defineNuxtModule({
30
34
  })
31
35
  ```
32
36
 
37
+ For environment-specific configuration in Nuxt 5+, use `addVitePlugin()` instead:
38
+
39
+ ```ts twoslash
40
+ import { addVitePlugin, defineNuxtModule } from '@nuxt/kit'
41
+
42
+ export default defineNuxtModule({
43
+ setup () {
44
+ // For global configuration (affects all environments)
45
+ addVitePlugin(() => ({
46
+ name: 'my-global-plugin',
47
+ config (config) {
48
+ // This runs before environment setup
49
+ config.optimizeDeps ||= {}
50
+ config.optimizeDeps.include ||= []
51
+ config.optimizeDeps.include.push('cross-fetch')
52
+ },
53
+ }))
54
+
55
+ // For environment-specific configuration
56
+ addVitePlugin(() => ({
57
+ name: 'my-client-plugin',
58
+ applyToEnvironment (environment) {
59
+ return environment.name === 'client'
60
+ },
61
+ configEnvironment (name, config) {
62
+ // This only affects the client environment
63
+ config.optimizeDeps ||= {}
64
+ config.optimizeDeps.include ||= []
65
+ config.optimizeDeps.include.push('client-only-package')
66
+ },
67
+ }))
68
+ },
69
+ })
70
+ ```
71
+
72
+ ::warning
73
+ **Important:** The `config` hook runs before `applyToEnvironment` and modifies the global configuration. Use `configEnvironment` for environment-specific configuration changes.
74
+ ::
75
+
33
76
  ### Type
34
77
 
35
78
  ```ts twoslash
@@ -54,8 +97,8 @@ Checkout Vite website for more information about its configuration.
54
97
  | --------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------ |
55
98
  | `dev` | `boolean` | `false` | If set to `true`, the callback function will be called when building in development mode. |
56
99
  | `build` | `boolean` | `false` | If set to `true`, the callback function will be called when building in production mode. |
57
- | `server` | `boolean` | `false` | If set to `true`, the callback function will be called when building the server bundle. |
58
- | `client` | `boolean` | `false` | If set to `true`, the callback function will be called when building the client bundle. |
100
+ | `server` | `boolean` | `false` | If set to `true`, the callback function will be called when building the server bundle. **Deprecated in Nuxt 5+.** Use `addVitePlugin()` with `applyToEnvironment()` instead. |
101
+ | `client` | `boolean` | `false` | If set to `true`, the callback function will be called when building the client bundle. **Deprecated in Nuxt 5+.** Use `addVitePlugin()` with `applyToEnvironment()` instead. |
59
102
  | `prepend` | `boolean` | `false` | If set to `true`, the callback function will be prepended to the array with `unshift()` instead of `push()`. |
60
103
 
61
104
  ## `extendWebpackConfig`
@@ -111,6 +154,10 @@ Checkout webpack website for more information about its configuration.
111
154
 
112
155
  Append Vite plugin to the config.
113
156
 
157
+ ::warning
158
+ In Nuxt 5+, plugins registered with `server: false` or `client: false` options will not have their `config` or `configResolved` hooks called. Instead, use the `applyToEnvironment()` method instead for environment-specific plugins.
159
+ ::
160
+
114
161
  ### Usage
115
162
 
116
163
  ```ts twoslash
@@ -131,6 +178,15 @@ export default defineNuxtModule({
131
178
  },
132
179
  setup (options) {
133
180
  addVitePlugin(svg4VuePlugin(options.svg4vue))
181
+
182
+ // or, to add a vite plugin to only one environment
183
+ addVitePlugin(() => ({
184
+ name: 'my-client-plugin',
185
+ applyToEnvironment (environment) {
186
+ return environment.name === 'client'
187
+ },
188
+ // ... rest of your client-only plugin
189
+ }))
134
190
  },
135
191
  })
136
192
  ```
@@ -159,8 +215,8 @@ See [Vite website](https://vite.dev/guide/api-plugin.html) for more information
159
215
  | --------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------ |
160
216
  | `dev` | `boolean` | `false` | If set to `true`, the callback function will be called when building in development mode. |
161
217
  | `build` | `boolean` | `false` | If set to `true`, the callback function will be called when building in production mode. |
162
- | `server` | `boolean` | `false` | If set to `true`, the callback function will be called when building the server bundle. |
163
- | `client` | `boolean` | `false` | If set to `true`, the callback function will be called when building the client bundle. |
218
+ | `server` | `boolean` | `false` | If set to `true`, the callback function will be called when building the server bundle. **Deprecated in Nuxt 5+.** Use `applyToEnvironment()` instead. |
219
+ | `client` | `boolean` | `false` | If set to `true`, the callback function will be called when building the client bundle. **Deprecated in Nuxt 5+.** Use `applyToEnvironment()` instead. |
164
220
  | `prepend` | `boolean` | `false` | If set to `true`, the callback function will be prepended to the array with `unshift()` instead of `push()`. |
165
221
 
166
222
  ## `addWebpackPlugin`
@@ -22,11 +22,9 @@ import { buildNuxt, loadNuxt } from '@nuxt/kit'
22
22
  async function getViteConfig () {
23
23
  const nuxt = await loadNuxt({ cwd: process.cwd(), dev: false, overrides: { ssr: false } })
24
24
  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_')
30
28
  })
31
29
  buildNuxt(nuxt).catch((err) => {
32
30
  if (!err.toString().includes('_stop_')) {
@@ -8,7 +8,7 @@ links:
8
8
  size: xs
9
9
  ---
10
10
 
11
- Programmatic usage can be helpful when you want to use Nuxt programmatically, for example, when building a [CLI tool](https://github.com/nuxt/cli) or [test utils](https://github.com/nuxt/nuxt/tree/main/packages/test-utils).
11
+ Programmatic usage can be helpful when you want to use Nuxt programmatically, for example, when building a [CLI tool](https://github.com/nuxt/cli) or [test utils](https://github.com/nuxt/test-utils).
12
12
 
13
13
  ## `loadNuxt`
14
14
 
@@ -31,7 +31,7 @@ function loadNuxt (loadOptions?: LoadNuxtOptions): Promise<Nuxt>
31
31
 
32
32
  ## `buildNuxt`
33
33
 
34
- Build Nuxt programmatically. It will invoke the builder (currently [@nuxt/vite-builder](https://github.com/nuxt/nuxt/tree/main/packages/vite) or [@nuxt/webpack-builder](https://github.com/nuxt/nuxt/tree/main/packages/webpack)) to bundle the application.
34
+ Build Nuxt programmatically. It will invoke the builder (currently [@nuxt/vite-builder](https://github.com/nuxt/nuxt/blob/main/packages/vite) or [@nuxt/webpack-builder](https://github.com/nuxt/nuxt/blob/main/packages/webpack)) to bundle the application.
35
35
 
36
36
  ### Type
37
37
 
@@ -113,6 +113,7 @@ function addComponent (options: AddComponentOptions): void
113
113
  | ------------------ | ---------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |
114
114
  | `name` | `string` | `true` | Component name. |
115
115
  | `filePath` | `string` | `true` | Path to the component. |
116
+ | `declarationPath` | `string` | `false` | Path to component's declaration file. It is used to generate components' [type templates](/docs/3.x/api/kit/templates#addtypetemplate); if not provided, `filePath` is used instead. |
116
117
  | `pascalName` | `string` | `false` | Pascal case component name. If not provided, it will be generated from the component name. |
117
118
  | `kebabName` | `string` | `false` | Kebab case component name. If not provided, it will be generated from the component name. |
118
119
  | `export` | `string` | `false` | Specify named or default export. If not provided, it will be set to `'default'`. |
@@ -0,0 +1,132 @@
1
+ ---
2
+ title: Head
3
+ description: Nuxt Kit provides utilities to help you manage head configuration in modules.
4
+ links:
5
+ - label: Source
6
+ icon: i-simple-icons-github
7
+ to: https://github.com/nuxt/nuxt/blob/main/packages/kit/src/head.ts
8
+ size: xs
9
+ ---
10
+
11
+ ## `setGlobalHead`
12
+
13
+ Sets global head configuration for your Nuxt application. This utility allows modules to programmatically configure meta tags, links, scripts, and other head elements that will be applied across all pages.
14
+
15
+ The provided head configuration will be merged with any existing head configuration using deep merging, with your provided values taking precedence.
16
+
17
+ ::tip
18
+ This is particularly useful for modules that need to inject global meta tags, stylesheets, or scripts into the application head.
19
+ ::
20
+
21
+ ### Type
22
+
23
+ ```ts twoslash
24
+ // @errors: 2391
25
+ // ---cut---
26
+ import type { SerializableHead } from '@unhead/vue/types'
27
+
28
+ interface AppHeadMetaObject extends SerializableHead {
29
+ charset?: string
30
+ viewport?: string
31
+ }
32
+
33
+ function setGlobalHead (head: AppHeadMetaObject): void
34
+ ```
35
+
36
+ ### Parameters
37
+
38
+ #### `head`
39
+
40
+ **Type**: `AppHeadMetaObject`
41
+
42
+ An object containing head configuration. All properties are optional and will be merged with existing configuration:
43
+
44
+ - `charset`: Character encoding for the document
45
+ - `viewport`: Viewport meta tag configuration
46
+ - `meta`: Array of meta tag objects
47
+ - `link`: Array of link tag objects (stylesheets, icons, etc.)
48
+ - `style`: Array of inline style tag objects
49
+ - `script`: Array of script tag objects
50
+ - `noscript`: Array of noscript tag objects
51
+ - `title`: Default page title
52
+ - `titleTemplate`: Template for formatting page titles
53
+ - `bodyAttrs`: Attributes to add to the `<body>` tag
54
+ - `htmlAttrs`: Attributes to add to the `<html>` tag
55
+
56
+ ### Examples
57
+
58
+ #### Adding Global Meta Tags
59
+
60
+ ```ts
61
+ import { defineNuxtModule, setGlobalHead } from '@nuxt/kit'
62
+
63
+ export default defineNuxtModule({
64
+ setup () {
65
+ setGlobalHead({
66
+ meta: [
67
+ { name: 'theme-color', content: '#ffffff' },
68
+ { name: 'author', content: 'Your Name' },
69
+ ],
70
+ })
71
+ },
72
+ })
73
+ ```
74
+
75
+ #### Injecting Global Stylesheets
76
+
77
+ ```ts
78
+ import { defineNuxtModule, setGlobalHead } from '@nuxt/kit'
79
+
80
+ export default defineNuxtModule({
81
+ setup () {
82
+ setGlobalHead({
83
+ link: [
84
+ {
85
+ rel: 'stylesheet',
86
+ href: 'https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap',
87
+ },
88
+ ],
89
+ })
90
+ },
91
+ })
92
+ ```
93
+
94
+ #### Adding Global Scripts
95
+
96
+ ```ts
97
+ import { defineNuxtModule, setGlobalHead } from '@nuxt/kit'
98
+
99
+ export default defineNuxtModule({
100
+ setup () {
101
+ setGlobalHead({
102
+ script: [
103
+ {
104
+ src: 'https://cdn.example.com/analytics.js',
105
+ async: true,
106
+ defer: true,
107
+ },
108
+ ],
109
+ })
110
+ },
111
+ })
112
+ ```
113
+
114
+ #### Setting HTML Attributes
115
+
116
+ ```ts
117
+ import { defineNuxtModule, setGlobalHead } from '@nuxt/kit'
118
+
119
+ export default defineNuxtModule({
120
+ setup () {
121
+ setGlobalHead({
122
+ htmlAttrs: {
123
+ lang: 'en',
124
+ dir: 'ltr',
125
+ },
126
+ bodyAttrs: {
127
+ class: 'custom-body-class',
128
+ },
129
+ })
130
+ },
131
+ })
132
+ ```
@@ -75,8 +75,8 @@ Hook | Arguments | Description
75
75
  `schema:beforeWrite` | `schema` | Called before writing the given schema.
76
76
  `schema:written` | - | Called after the schema is written.
77
77
  `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 in Nuxt 5+.** In Nuxt 5, this operates on a shared configuration rather than separate client/server configs.
79
+ `vite:configResolved` | `viteInlineConfig, env` | Allows reading the resolved Vite config. **Deprecated in Nuxt 5+.** In Nuxt 5, this operates on a shared configuration rather than separate client/server configs.
80
80
  `vite:serverCreated` | `viteServer, env` | Called when the Vite server is created.
81
81
  `vite:compiled` | - | Called after Vite server is compiled.
82
82
  `webpack:config` | `webpackConfigs` | Called before configuring the webpack compiler.
@@ -39,7 +39,7 @@ If your issue concerns Vue or Vite, please try to reproduce it first with the Vu
39
39
 
40
40
  ::card-group
41
41
  :card{title="Vue SSR on StackBlitz" icon="i-simple-icons-stackblitz" to="https://stackblitz.com/github/nuxt-contrib/vue3-ssr-starter/tree/main?terminal=dev" target="_blank"}
42
- :card{title="Vue SSR on CodeSandbox" icon="i-simple-icons-codesandbox" to="https://codesandbox.io/s/github/nuxt-contrib/vue3-ssr-starter/main" target="_blank"}
42
+ :card{title="Vue SSR on CodeSandbox" icon="i-simple-icons-codesandbox" to="https://codesandbox.io/p/sandbox/github/nuxt-contrib/vue3-ssr-starter/main" target="_blank"}
43
43
  :card{title="Vue SSR Template on GitHub" icon="i-simple-icons-github" to="https://github.com/nuxt-contrib/vue3-ssr-starter/generate" target="_blank"}
44
44
  ::
45
45
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/docs",
3
- "version": "3.19.3",
3
+ "version": "3.20.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",