@nuxt/docs 4.3.0 → 4.4.2
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.
- package/1.getting-started/02.installation.md +2 -1
- package/1.getting-started/06.styling.md +1 -1
- package/1.getting-started/09.transitions.md +100 -0
- package/1.getting-started/15.prerendering.md +8 -0
- package/1.getting-started/16.deployment.md +2 -3
- package/1.getting-started/17.testing.md +63 -8
- package/1.getting-started/18.upgrade.md +138 -2
- package/2.directory-structure/1.app/1.layouts.md +60 -1
- package/2.directory-structure/1.server.md +7 -7
- package/3.guide/1.concepts/1.rendering.md +4 -0
- package/3.guide/2.best-practices/hydration.md +13 -13
- package/3.guide/2.best-practices/performance.md +2 -3
- package/3.guide/3.ai/1.mcp.md +1 -1
- package/3.guide/3.ai/2.llms-txt.md +1 -1
- package/3.guide/4.modules/3.recipes-basics.md +90 -0
- package/3.guide/5.recipes/3.custom-usefetch.md +36 -67
- package/3.guide/5.recipes/4.sessions-and-authentication.md +2 -2
- package/3.guide/6.going-further/1.experimental-features.md +81 -5
- package/3.guide/6.going-further/2.hooks.md +1 -1
- package/4.api/1.components/12.nuxt-route-announcer.md +4 -0
- package/4.api/1.components/14.nuxt-announcer.md +81 -0
- package/4.api/1.components/3.nuxt-layout.md +29 -0
- package/4.api/1.components/8.nuxt-island.md +1 -1
- package/4.api/2.composables/create-use-async-data.md +90 -0
- package/4.api/2.composables/create-use-fetch.md +97 -0
- package/4.api/2.composables/use-announcer.md +128 -0
- package/4.api/2.composables/use-async-data.md +2 -2
- package/4.api/2.composables/use-cookie.md +24 -0
- package/4.api/2.composables/use-fetch.md +5 -5
- package/4.api/2.composables/use-lazy-fetch.md +1 -0
- package/4.api/2.composables/use-route-announcer.md +5 -1
- package/4.api/3.utils/clear-nuxt-state.md +4 -2
- package/4.api/3.utils/define-page-meta.md +61 -4
- package/4.api/4.commands/add.md +1 -1
- package/4.api/4.commands/build.md +3 -2
- package/4.api/4.commands/dev.md +2 -1
- package/4.api/4.commands/generate.md +2 -1
- package/4.api/5.kit/11.nitro.md +6 -2
- package/4.api/5.kit/4.autoimports.md +5 -1
- package/4.api/6.advanced/1.hooks.md +1 -1
- package/4.api/6.nuxt-config.md +38 -21
- package/5.community/2.getting-help.md +1 -1
- package/5.community/6.roadmap.md +3 -3
- package/7.migration/11.server.md +1 -1
- package/package.json +1 -1
package/4.api/5.kit/11.nitro.md
CHANGED
|
@@ -301,6 +301,10 @@ function addPrerenderRoutes (routes: string | string[]): void
|
|
|
301
301
|
|
|
302
302
|
Add imports to the server. It makes your imports available in Nitro without the need to import them manually.
|
|
303
303
|
|
|
304
|
+
::warning
|
|
305
|
+
If you want to provide a utility that works in both server and client contexts and is usable in the [`shared/`](/docs/4.x/directory-structure/shared) directory, the function must be imported from the same source file for both [`addImports`](/docs/4.x/api/kit/autoimports#addimports) and `addServerImports` and should have identical signature. That source file should not import anything context-specific (i.e., Nitro context, Nuxt app context) or else it might cause errors during type-checking.
|
|
306
|
+
::
|
|
307
|
+
|
|
304
308
|
### Usage
|
|
305
309
|
|
|
306
310
|
```ts twoslash
|
|
@@ -422,10 +426,10 @@ export default defineEventHandler(() => {
|
|
|
422
426
|
## `addServerScanDir`
|
|
423
427
|
|
|
424
428
|
Add directories to be scanned by Nitro. It will check for subdirectories, which will be registered
|
|
425
|
-
just like the
|
|
429
|
+
just like the `~~/server` folder is.
|
|
426
430
|
|
|
427
431
|
::note
|
|
428
|
-
Only
|
|
432
|
+
Only `~~/server/api`, `~~/server/routes`, `~~/server/middleware`, and `~~/server/utils` are scanned.
|
|
429
433
|
::
|
|
430
434
|
|
|
431
435
|
### Usage
|
|
@@ -24,7 +24,11 @@ Watch Vue School video about Auto-imports Nuxt Kit utilities.
|
|
|
24
24
|
|
|
25
25
|
## `addImports`
|
|
26
26
|
|
|
27
|
-
Add imports to the Nuxt application. It makes your imports available in the Nuxt
|
|
27
|
+
Add imports to the Nuxt application. It makes your imports available in the Nuxt app context without the need to import them manually.
|
|
28
|
+
|
|
29
|
+
::tip
|
|
30
|
+
To add imports for the Nitro server context, refer to the [`addServerImports`](/docs/4.x/api/kit/nitro#addserverimports) function.
|
|
31
|
+
::
|
|
28
32
|
|
|
29
33
|
### Usage
|
|
30
34
|
|
|
@@ -30,7 +30,7 @@ Check the [app source code](https://github.com/nuxt/nuxt/blob/main/packages/nuxt
|
|
|
30
30
|
| `page:loading:end` | - | Client | Called after `page:finish` |
|
|
31
31
|
| `page:transition:finish` | `pageComponent?` | Client | After page transition [onAfterLeave](https://vuejs.org/guide/built-ins/transition#javascript-hooks) event. |
|
|
32
32
|
| `dev:ssr-logs` | `logs` | Client | Called with an array of server-side logs that have been passed to the client (if `features.devLogs` is enabled). |
|
|
33
|
-
| `page:view-transition:start` | `transition` | Client | Called after `document.startViewTransition` is called when [experimental viewTransition support is enabled](/docs/4.x/getting-started/transitions#view-transitions-api-experimental). |
|
|
33
|
+
| `page:view-transition:start` | `transition` | Client | Called after `document.startViewTransition` is called when [experimental viewTransition support is enabled](/docs/4.x/getting-started/transitions#view-transitions-api-experimental). The `transition` argument is a [`ViewTransition`](https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition) object with a `types` property ([`ViewTransitionTypeSet`](https://developer.mozilla.org/en-US/docs/Web/API/ViewTransitionTypeSet)) that can be read or modified. |
|
|
34
34
|
|
|
35
35
|
## Nuxt Hooks (build time)
|
|
36
36
|
|
package/4.api/6.nuxt-config.md
CHANGED
|
@@ -13,12 +13,13 @@ You can improve your DX by defining additional aliases to access custom director
|
|
|
13
13
|
- **Default**
|
|
14
14
|
```json
|
|
15
15
|
{
|
|
16
|
-
"~": "/<
|
|
17
|
-
"@": "/<
|
|
16
|
+
"~": "/<rootDir>/app",
|
|
17
|
+
"@": "/<rootDir>/app",
|
|
18
18
|
"~~": "/<rootDir>",
|
|
19
19
|
"@@": "/<rootDir>",
|
|
20
20
|
"#shared": "/<rootDir>/shared",
|
|
21
|
-
"
|
|
21
|
+
"#server": "/<rootDir>/server",
|
|
22
|
+
"assets": "/<rootDir>/app/assets",
|
|
22
23
|
"public": "/<rootDir>/public",
|
|
23
24
|
"#build": "/<rootDir>/.nuxt",
|
|
24
25
|
"#internal/nuxt/paths": "/<rootDir>/.nuxt/paths.mjs"
|
|
@@ -372,7 +373,7 @@ export default defineNuxtConfig({
|
|
|
372
373
|
build: {
|
|
373
374
|
templates: [
|
|
374
375
|
{
|
|
375
|
-
src: '
|
|
376
|
+
src: '~~/modules/support/plugin.js', // `src` can be absolute or relative
|
|
376
377
|
dst: 'support.js', // `dst` is relative to project `.nuxt` dir
|
|
377
378
|
},
|
|
378
379
|
],
|
|
@@ -880,7 +881,7 @@ Defaults to 'silent' when running in CI or when a TTY is not available. This opt
|
|
|
880
881
|
Modules are Nuxt extensions which can extend its core functionality and add endless integrations.
|
|
881
882
|
|
|
882
883
|
Each module is either a string (which can refer to a package, or be a path to a file), a tuple with the module as first string and the options as a second object, or an inline module function.
|
|
883
|
-
Nuxt tries to resolve each item in the modules array using node require path (in `node_modules`) and then will be resolved from project `
|
|
884
|
+
Nuxt tries to resolve each item in the modules array using node require path (in `node_modules`) and then will be resolved from project `rootDir` if `~~` alias is used.
|
|
884
885
|
|
|
885
886
|
- **Type**: `array`
|
|
886
887
|
|
|
@@ -895,8 +896,8 @@ export default defineNuxtConfig({
|
|
|
895
896
|
modules: [
|
|
896
897
|
// Using package name
|
|
897
898
|
'@nuxt/scripts',
|
|
898
|
-
// Relative to your project
|
|
899
|
-
'
|
|
899
|
+
// Relative to your project rootDir
|
|
900
|
+
'~~/custom-modules/awesome.js',
|
|
900
901
|
// Providing options
|
|
901
902
|
['@nuxtjs/google-analytics', { ua: 'X1234567' }],
|
|
902
903
|
// Inline definition
|
|
@@ -1013,8 +1014,12 @@ Options passed directly to the transformer from `unctx` that preserves async con
|
|
|
1013
1014
|
|
|
1014
1015
|
Functions to inject a key for.
|
|
1015
1016
|
|
|
1016
|
-
As long as the number of arguments passed to the function is less than `argumentLength`, an additional magic string will be injected
|
|
1017
|
-
The key
|
|
1017
|
+
As long as the number of arguments passed to the function is less than `argumentLength`, an additional magic string will be injected as the last argument. This key is stable between SSR and client-side hydration. You will need to take steps to handle this additional key.
|
|
1018
|
+
The key is unique based on the location of the function being invoked within the file.
|
|
1019
|
+
|
|
1020
|
+
::read-more{to="/docs/4.x/guide/modules/recipes-basics#add-keyed-functions"}
|
|
1021
|
+
Learn more about keyed functions.
|
|
1022
|
+
::
|
|
1018
1023
|
|
|
1019
1024
|
- **Type**: `array`
|
|
1020
1025
|
- **Default**
|
|
@@ -1022,31 +1027,38 @@ The key will be unique based on the location of the function being invoked withi
|
|
|
1022
1027
|
[
|
|
1023
1028
|
{
|
|
1024
1029
|
"name": "callOnce",
|
|
1025
|
-
"argumentLength": 3
|
|
1030
|
+
"argumentLength": 3,
|
|
1031
|
+
"source": "#app/composables/once"
|
|
1026
1032
|
},
|
|
1027
1033
|
{
|
|
1028
1034
|
"name": "defineNuxtComponent",
|
|
1029
|
-
"argumentLength": 2
|
|
1035
|
+
"argumentLength": 2,
|
|
1036
|
+
"source": "#app/composables/component"
|
|
1030
1037
|
},
|
|
1031
1038
|
{
|
|
1032
1039
|
"name": "useState",
|
|
1033
|
-
"argumentLength": 2
|
|
1040
|
+
"argumentLength": 2,
|
|
1041
|
+
"source": "#app/composables/state"
|
|
1034
1042
|
},
|
|
1035
1043
|
{
|
|
1036
1044
|
"name": "useFetch",
|
|
1037
|
-
"argumentLength": 3
|
|
1045
|
+
"argumentLength": 3,
|
|
1046
|
+
"source": "#app/composables/fetch"
|
|
1038
1047
|
},
|
|
1039
1048
|
{
|
|
1040
1049
|
"name": "useAsyncData",
|
|
1041
|
-
"argumentLength": 3
|
|
1050
|
+
"argumentLength": 3,
|
|
1051
|
+
"source": "#app/composables/asyncData"
|
|
1042
1052
|
},
|
|
1043
1053
|
{
|
|
1044
1054
|
"name": "useLazyAsyncData",
|
|
1045
|
-
"argumentLength": 3
|
|
1055
|
+
"argumentLength": 3,
|
|
1056
|
+
"source": "#app/composables/asyncData"
|
|
1046
1057
|
},
|
|
1047
1058
|
{
|
|
1048
1059
|
"name": "useLazyFetch",
|
|
1049
|
-
"argumentLength": 3
|
|
1060
|
+
"argumentLength": 3,
|
|
1061
|
+
"source": "#app/composables/fetch"
|
|
1050
1062
|
}
|
|
1051
1063
|
]
|
|
1052
1064
|
```
|
|
@@ -1297,7 +1309,7 @@ Define the server directory of your Nuxt application, where Nitro routes, middle
|
|
|
1297
1309
|
If a relative path is specified, it will be relative to your `rootDir`.
|
|
1298
1310
|
|
|
1299
1311
|
- **Type**: `string`
|
|
1300
|
-
- **Default:** `"/<
|
|
1312
|
+
- **Default:** `"/<rootDir>/server"`
|
|
1301
1313
|
|
|
1302
1314
|
## serverHandlers
|
|
1303
1315
|
|
|
@@ -1318,7 +1330,7 @@ Each handler accepts the following options:
|
|
|
1318
1330
|
```ts
|
|
1319
1331
|
export default defineNuxtConfig({
|
|
1320
1332
|
serverHandlers: [
|
|
1321
|
-
{ route: '/path/foo/**:name', handler: '
|
|
1333
|
+
{ route: '/path/foo/**:name', handler: '#server/foohandler.ts' },
|
|
1322
1334
|
],
|
|
1323
1335
|
})
|
|
1324
1336
|
```
|
|
@@ -1408,22 +1420,27 @@ export default defineNuxtConfig({
|
|
|
1408
1420
|
srcDir: 'app/',
|
|
1409
1421
|
})
|
|
1410
1422
|
```
|
|
1423
|
+
|
|
1411
1424
|
This expects the following folder structure:
|
|
1412
1425
|
```bash
|
|
1413
1426
|
-| app/
|
|
1414
1427
|
---| assets/
|
|
1415
1428
|
---| components/
|
|
1429
|
+
---| composables/
|
|
1416
1430
|
---| layouts/
|
|
1417
1431
|
---| middleware/
|
|
1418
1432
|
---| pages/
|
|
1419
1433
|
---| plugins/
|
|
1434
|
+
---| utils/
|
|
1420
1435
|
---| app.config.ts
|
|
1421
1436
|
---| app.vue
|
|
1422
1437
|
---| error.vue
|
|
1423
1438
|
-| server/
|
|
1439
|
+
-| shared/
|
|
1424
1440
|
-| public/
|
|
1425
1441
|
-| modules/
|
|
1426
|
-
-|
|
|
1442
|
+
-| layers/
|
|
1443
|
+
-| nuxt.config.ts
|
|
1427
1444
|
-| package.json
|
|
1428
1445
|
```
|
|
1429
1446
|
|
|
@@ -1692,7 +1709,7 @@ Please note that not all vite options are supported in Nuxt.
|
|
|
1692
1709
|
### `root`
|
|
1693
1710
|
|
|
1694
1711
|
- **Type**: `string`
|
|
1695
|
-
- **Default:** `"/<
|
|
1712
|
+
- **Default:** `"/<rootDir>"`
|
|
1696
1713
|
|
|
1697
1714
|
### `server`
|
|
1698
1715
|
|
|
@@ -1705,7 +1722,7 @@ Please note that not all vite options are supported in Nuxt.
|
|
|
1705
1722
|
```json
|
|
1706
1723
|
[
|
|
1707
1724
|
"/<rootDir>/.nuxt",
|
|
1708
|
-
"/<
|
|
1725
|
+
"/<rootDir>/app",
|
|
1709
1726
|
"/<rootDir>",
|
|
1710
1727
|
"/<workspaceDir>"
|
|
1711
1728
|
]
|
|
@@ -41,7 +41,7 @@ We recommend taking a look at [how to report bugs](/docs/4.x/community/reporting
|
|
|
41
41
|
|
|
42
42
|
## "I need professional help"
|
|
43
43
|
|
|
44
|
-
If the community couldn't provide the help you need in the time-frame you have, NuxtLabs offers professional support with the [Nuxt Experts](https://nuxt.com/enterprise/
|
|
44
|
+
If the community couldn't provide the help you need in the time-frame you have, NuxtLabs offers professional support with the [Nuxt Experts](https://nuxt.com/enterprise/agencies).
|
|
45
45
|
|
|
46
46
|
The objective of the Nuxt Expert is to provide support to the Vue ecosystem, while also creating freelance opportunities for those contributing to open-source solutions, thus helping to maintain the sustainability of the ecosystem.
|
|
47
47
|
|
package/5.community/6.roadmap.md
CHANGED
|
@@ -61,15 +61,15 @@ We commit to support each major version of Nuxt for a minimum of six months afte
|
|
|
61
61
|
|
|
62
62
|
The current active version of [Nuxt](https://nuxt.com) is **v4** which is available as `nuxt` on npm with the `latest` tag.
|
|
63
63
|
|
|
64
|
-
Nuxt 3 will continue to receive maintenance updates (
|
|
64
|
+
Nuxt 3 will continue to receive maintenance updates (bug fixes and security patches) until the end of July 2026.
|
|
65
65
|
|
|
66
66
|
Each active version has its own nightly releases which are generated automatically. For more about enabling the Nuxt nightly release channel, see [the nightly release channel docs](/docs/4.x/guide/going-further/nightly-release-channel).
|
|
67
67
|
|
|
68
68
|
| Release | | Initial release | End Of Life | Docs |
|
|
69
69
|
|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------|----------------------------|-------------------------------------------------------------------|
|
|
70
|
-
| **5.x** (scheduled) | |
|
|
70
|
+
| **5.x** (scheduled) | | Q1 2026 (estimated) | TBA | |
|
|
71
71
|
| **4.x** (stable) | <a href="https://www.npmjs.com/package/nuxt?activeTab=versions"><img alt="Nuxt latest version" src="https://img.shields.io/npm/v/nuxt.svg?logo=nuxt&label=&style=flat&colorA=18181B&colorB=28CF8D" class="not-prose h-5 w-auto" :zoom="false"></a> | 2025-07-16 | 6 months after 5.x release | [nuxt.com](/docs/4.x/getting-started/introduction) |
|
|
72
|
-
| **3.x** (maintenance) | <a href="https://www.npmjs.com/package/nuxt?activeTab=versions"><img alt="Nuxt 3.x version" src="https://img.shields.io/npm/v/nuxt/3x.svg?logo=nuxt&label=&style=flat&colorA=18181B&colorB=28CF8D" class="not-prose h-5 w-auto" :zoom="false"></a> | 2022-11-16 | 2026-
|
|
72
|
+
| **3.x** (maintenance) | <a href="https://www.npmjs.com/package/nuxt?activeTab=versions"><img alt="Nuxt 3.x version" src="https://img.shields.io/npm/v/nuxt/3x.svg?logo=nuxt&label=&style=flat&colorA=18181B&colorB=28CF8D" class="not-prose h-5 w-auto" :zoom="false"></a> | 2022-11-16 | 2026-07-31 | [nuxt.com](/docs/3.x/getting-started/introduction) |
|
|
73
73
|
| **2.x** (unsupported) | <a href="https://www.npmjs.com/package/nuxt?activeTab=versions"><img alt="Nuxt 2.x version" src="https://img.shields.io/npm/v/nuxt/2x.svg?logo=nuxt&label=&style=flat&colorA=18181B&colorB=28CF8D" class="not-prose h-5 w-auto" :zoom="false"></a> | 2018-09-21 | 2024-06-30 | [v2.nuxt.com](https://v2.nuxt.com/docs/get-started/installation/) |
|
|
74
74
|
| **1.x** (unsupported) | <a href="https://www.npmjs.com/package/nuxt?activeTab=versions"><img alt="Nuxt 1.x version" src="https://img.shields.io/npm/v/nuxt/1x.svg?logo=nuxt&label=&style=flat&colorA=18181B&colorB=28CF8D" class="not-prose h-5 w-auto" :zoom="false"></a> | 2018-01-08 | 2019-09-21 | |
|
|
75
75
|
|
package/7.migration/11.server.md
CHANGED
|
@@ -10,7 +10,7 @@ In a built Nuxt 3 application, there is no runtime Nuxt dependency. That means y
|
|
|
10
10
|
## Steps
|
|
11
11
|
|
|
12
12
|
1. Remove the `render` key in your `nuxt.config`.
|
|
13
|
-
2. Any files in
|
|
13
|
+
2. Any files in `~~/server/api` and `~~/server/middleware` will be automatically registered; you can remove them from your `serverMiddleware` array.
|
|
14
14
|
3. Update any other items in your `serverMiddleware` array to point to files or npm packages directly, rather than using inline functions.
|
|
15
15
|
|
|
16
16
|
:read-more{to="/docs/4.x/directory-structure/server"}
|