@nuxt/docs 4.2.0 → 4.2.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.
- package/1.getting-started/02.installation.md +3 -3
- package/1.getting-started/03.configuration.md +4 -4
- package/1.getting-started/04.views.md +2 -2
- package/1.getting-started/05.assets.md +1 -1
- package/1.getting-started/06.styling.md +11 -11
- package/1.getting-started/07.routing.md +4 -0
- package/1.getting-started/09.transitions.md +6 -6
- package/1.getting-started/10.data-fetching.md +14 -14
- package/1.getting-started/11.state-management.md +2 -2
- package/1.getting-started/12.error-handling.md +4 -4
- package/1.getting-started/13.server.md +4 -4
- package/1.getting-started/14.layers.md +29 -10
- package/1.getting-started/17.testing.md +3 -3
- package/1.getting-started/18.upgrade.md +19 -11
- package/2.guide/1.directory-structure/1.app/1.components.md +4 -4
- package/2.guide/1.directory-structure/1.app/1.composables.md +1 -1
- package/2.guide/1.directory-structure/1.app/1.layouts.md +2 -2
- package/2.guide/1.directory-structure/1.app/1.middleware.md +4 -4
- package/2.guide/1.directory-structure/1.app/1.pages.md +13 -13
- package/2.guide/1.directory-structure/1.app/1.plugins.md +1 -5
- package/2.guide/1.directory-structure/1.node_modules.md +1 -1
- package/2.guide/1.directory-structure/1.public.md +1 -1
- package/2.guide/1.directory-structure/1.server.md +5 -5
- package/2.guide/1.directory-structure/2.env.md +1 -1
- package/2.guide/1.directory-structure/3.tsconfig.md +38 -7
- package/2.guide/2.concepts/1.auto-imports.md +2 -2
- package/2.guide/2.concepts/10.nuxt-lifecycle.md +3 -3
- package/2.guide/2.concepts/2.vuejs-development.md +3 -3
- package/2.guide/2.concepts/3.rendering.md +4 -4
- package/2.guide/2.concepts/7.esm.md +2 -2
- package/2.guide/2.concepts/8.typescript.md +15 -38
- package/2.guide/2.concepts/9.code-style.md +1 -1
- package/2.guide/3.going-further/1.experimental-features.md +6 -6
- package/2.guide/3.going-further/1.features.md +1 -1
- package/2.guide/3.going-further/1.internals.md +2 -2
- package/2.guide/3.going-further/2.hooks.md +1 -1
- package/2.guide/3.going-further/3.modules.md +77 -10
- package/2.guide/3.going-further/6.nuxt-app.md +5 -5
- package/2.guide/3.going-further/7.layers.md +32 -15
- package/2.guide/3.going-further/9.debugging.md +1 -1
- package/2.guide/4.recipes/1.custom-routing.md +4 -4
- package/2.guide/4.recipes/3.custom-usefetch.md +1 -1
- package/2.guide/5.best-practices/hydration.md +1 -1
- package/3.api/1.components/10.nuxt-picture.md +1 -1
- package/3.api/1.components/11.teleports.md +1 -1
- package/3.api/1.components/12.nuxt-route-announcer.md +1 -1
- package/3.api/1.components/2.nuxt-page.md +1 -1
- package/3.api/1.components/4.nuxt-link.md +11 -11
- package/3.api/1.components/5.nuxt-loading-indicator.md +1 -1
- package/3.api/1.components/6.nuxt-error-boundary.md +1 -1
- package/3.api/2.composables/use-app-config.md +1 -1
- package/3.api/2.composables/use-async-data.md +76 -13
- package/3.api/2.composables/use-cookie.md +7 -7
- package/3.api/2.composables/use-fetch.md +2 -2
- package/3.api/2.composables/use-head-safe.md +37 -20
- package/3.api/2.composables/use-head.md +136 -36
- package/3.api/2.composables/use-hydration.md +24 -18
- package/3.api/2.composables/use-lazy-async-data.md +58 -9
- package/3.api/2.composables/use-lazy-fetch.md +65 -9
- package/3.api/2.composables/use-nuxt-app.md +7 -7
- package/3.api/2.composables/use-nuxt-data.md +1 -1
- package/3.api/2.composables/use-request-fetch.md +1 -1
- package/3.api/2.composables/use-route.md +1 -1
- package/3.api/2.composables/use-router.md +15 -15
- package/3.api/2.composables/use-runtime-hook.md +1 -1
- package/3.api/2.composables/use-state.md +1 -1
- package/3.api/3.utils/abort-navigation.md +2 -2
- package/3.api/3.utils/define-lazy-hydration-component.md +4 -4
- package/3.api/3.utils/define-nuxt-component.md +1 -1
- package/3.api/3.utils/define-nuxt-plugin.md +1 -1
- package/3.api/3.utils/define-nuxt-route-middleware.md +1 -1
- package/3.api/3.utils/define-page-meta.md +8 -8
- package/3.api/3.utils/navigate-to.md +5 -5
- package/3.api/3.utils/on-before-route-leave.md +1 -1
- package/3.api/3.utils/on-before-route-update.md +1 -1
- package/3.api/3.utils/refresh-cookie.md +1 -1
- package/3.api/3.utils/update-app-config.md +2 -2
- package/3.api/5.kit/1.modules.md +3 -3
- package/3.api/5.kit/14.builder.md +6 -6
- package/3.api/5.kit/2.programmatic.md +2 -2
- package/3.api/6.advanced/1.hooks.md +5 -5
- package/3.api/6.nuxt-config.md +25 -25
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +1 -1
- package/5.community/5.framework-contribution.md +8 -8
- package/5.community/6.roadmap.md +3 -3
- package/6.bridge/4.plugins-and-middleware.md +1 -1
- package/7.migration/2.configuration.md +2 -2
- package/7.migration/20.module-authors.md +1 -1
- package/7.migration/5.plugins-and-middleware.md +1 -1
- package/7.migration/6.pages-and-layouts.md +2 -2
- package/README.md +1 -1
- package/package.json +1 -1
|
@@ -48,13 +48,13 @@ Nuxt provides two globally available helpers that can be returned directly from
|
|
|
48
48
|
1. [`navigateTo`](/docs/4.x/api/utils/navigate-to) - Redirects to the given route
|
|
49
49
|
2. [`abortNavigation`](/docs/4.x/api/utils/abort-navigation) - Aborts the navigation, with an optional error message.
|
|
50
50
|
|
|
51
|
-
Unlike [navigation guards](https://router.vuejs.org/guide/advanced/navigation-guards
|
|
51
|
+
Unlike [navigation guards](https://router.vuejs.org/guide/advanced/navigation-guards#Global-Before-Guards) from `vue-router`, a third `next()` argument is not passed, and **redirect or route cancellation is handled by returning a value from the middleware**.
|
|
52
52
|
|
|
53
53
|
Possible return values are:
|
|
54
54
|
|
|
55
55
|
* nothing (a simple `return` or no return at all) - does not block navigation and will move to the next middleware function, if any, or complete the route navigation
|
|
56
|
-
* `return navigateTo('/')` - redirects to the given path and will set the redirect code to [`302` Found](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302) if the redirect happens on the server side
|
|
57
|
-
* `return navigateTo('/', { redirectCode: 301 })` - redirects to the given path and will set the redirect code to [`301` Moved Permanently](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/301) if the redirect happens on the server side
|
|
56
|
+
* `return navigateTo('/')` - redirects to the given path and will set the redirect code to [`302` Found](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/302) if the redirect happens on the server side
|
|
57
|
+
* `return navigateTo('/', { redirectCode: 301 })` - redirects to the given path and will set the redirect code to [`301` Moved Permanently](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/301) if the redirect happens on the server side
|
|
58
58
|
* `return abortNavigation()` - stops the current navigation
|
|
59
59
|
* `return abortNavigation(error)` - rejects the current navigation with an error
|
|
60
60
|
|
|
@@ -62,7 +62,7 @@ Possible return values are:
|
|
|
62
62
|
:read-more{to="/docs/4.x/api/utils/abort-navigation"}
|
|
63
63
|
|
|
64
64
|
::important
|
|
65
|
-
We recommend using the helper functions above for performing redirects or stopping navigation. Other possible return values described in [the vue-router docs](https://router.vuejs.org/guide/advanced/navigation-guards
|
|
65
|
+
We recommend using the helper functions above for performing redirects or stopping navigation. Other possible return values described in [the vue-router docs](https://router.vuejs.org/guide/advanced/navigation-guards#Global-Before-Guards) may work but there may be breaking changes in future.
|
|
66
66
|
::
|
|
67
67
|
|
|
68
68
|
## Middleware Order
|
|
@@ -6,12 +6,12 @@ navigation.icon: i-vscode-icons-folder-type-view
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
::note
|
|
9
|
-
To reduce your application's bundle size, this directory is **optional**, meaning that [`vue-router`](https://router.vuejs.org) won't be included if you only use [`app.vue`](/docs/4.x/guide/directory-structure/app). To force the pages system, set `pages: true` in `nuxt.config` or have a [`router.options.ts`](/docs/4.x/guide/recipes/custom-routing#using-routeroptions).
|
|
9
|
+
To reduce your application's bundle size, this directory is **optional**, meaning that [`vue-router`](https://router.vuejs.org) won't be included if you only use [`app.vue`](/docs/4.x/guide/directory-structure/app/app). To force the pages system, set `pages: true` in `nuxt.config` or have a [`router.options.ts`](/docs/4.x/guide/recipes/custom-routing#using-routeroptions).
|
|
10
10
|
::
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
13
|
|
|
14
|
-
Pages are Vue components and can have any [valid extension](/docs/4.x/api/
|
|
14
|
+
Pages are Vue components and can have any [valid extension](/docs/4.x/api/nuxt-config#extensions) that Nuxt supports (by default `.vue`, `.js`, `.jsx`, `.mjs`, `.ts` or `.tsx`).
|
|
15
15
|
|
|
16
16
|
Nuxt will automatically create a route for every page in your `~/pages/` directory.
|
|
17
17
|
|
|
@@ -46,7 +46,7 @@ export default defineComponent({
|
|
|
46
46
|
|
|
47
47
|
The `app/pages/index.vue` file will be mapped to the `/` route of your application.
|
|
48
48
|
|
|
49
|
-
If you are using [`app.vue`](/docs/4.x/guide/directory-structure/app), make sure to use the [`<NuxtPage/>`](/docs/4.x/api/components/nuxt-page) component to display the current page:
|
|
49
|
+
If you are using [`app.vue`](/docs/4.x/guide/directory-structure/app/app), make sure to use the [`<NuxtPage/>`](/docs/4.x/api/components/nuxt-page) component to display the current page:
|
|
50
50
|
|
|
51
51
|
```vue [app/app.vue]
|
|
52
52
|
<template>
|
|
@@ -93,7 +93,7 @@ Here are some examples to illustrate what a page with a single root element look
|
|
|
93
93
|
|
|
94
94
|
## Dynamic Routes
|
|
95
95
|
|
|
96
|
-
If you place anything within square brackets, it will be turned into a [dynamic route](https://router.vuejs.org/guide/essentials/dynamic-matching
|
|
96
|
+
If you place anything within square brackets, it will be turned into a [dynamic route](https://router.vuejs.org/guide/essentials/dynamic-matching) parameter. You can mix and match multiple parameters and even non-dynamic text within a file name or directory.
|
|
97
97
|
|
|
98
98
|
If you want a parameter to be _optional_, you must enclose it in double square brackets - for example, `~/pages/[[slug]]/index.vue` or `~/pages/[[slug]].vue` will match both `/` and `/test`.
|
|
99
99
|
|
|
@@ -154,7 +154,7 @@ Navigating to `/hello/world` would render:
|
|
|
154
154
|
|
|
155
155
|
## Nested Routes
|
|
156
156
|
|
|
157
|
-
It is possible to display [nested routes](https://
|
|
157
|
+
It is possible to display [nested routes](https://router.vuejs.org/guide/essentials/nested-routes) with `<NuxtPage>`.
|
|
158
158
|
|
|
159
159
|
Example:
|
|
160
160
|
|
|
@@ -268,9 +268,9 @@ console.log(route.meta.title) // My home page
|
|
|
268
268
|
</script>
|
|
269
269
|
```
|
|
270
270
|
|
|
271
|
-
If you are using nested routes, the page metadata from all these routes will be merged into a single object. For more on route meta, see the [vue-router docs](https://router.vuejs.org/guide/advanced/meta
|
|
271
|
+
If you are using nested routes, the page metadata from all these routes will be merged into a single object. For more on route meta, see the [vue-router docs](https://router.vuejs.org/guide/advanced/meta).
|
|
272
272
|
|
|
273
|
-
Much like `defineEmits` or `defineProps` (see [Vue docs](https://vuejs.org/api/sfc-script-setup
|
|
273
|
+
Much like `defineEmits` or `defineProps` (see [Vue docs](https://vuejs.org/api/sfc-script-setup#defineprops-defineemits)), `definePageMeta` is a **compiler macro**. It will be compiled away so you cannot reference it within your component. Instead, the metadata passed to it will be hoisted out of the component.
|
|
274
274
|
Therefore, the page meta object cannot reference the component. However, it can reference imported bindings, as well as locally defined **pure functions**.
|
|
275
275
|
|
|
276
276
|
::warning
|
|
@@ -301,13 +301,13 @@ Of course, you are welcome to define metadata for your own use throughout your a
|
|
|
301
301
|
|
|
302
302
|
#### `alias`
|
|
303
303
|
|
|
304
|
-
You can define page aliases. They allow you to access the same page from different paths. It can be either a string or an array of strings as defined [in the vue-router documentation](https://router.vuejs.org/guide/essentials/redirect-and-alias
|
|
304
|
+
You can define page aliases. They allow you to access the same page from different paths. It can be either a string or an array of strings as defined [in the vue-router documentation](https://router.vuejs.org/guide/essentials/redirect-and-alias#Alias).
|
|
305
305
|
|
|
306
306
|
#### `keepalive`
|
|
307
307
|
|
|
308
|
-
Nuxt will automatically wrap your page in [the Vue `<KeepAlive>` component](https://vuejs.org/guide/built-ins/keep-alive
|
|
308
|
+
Nuxt will automatically wrap your page in [the Vue `<KeepAlive>` component](https://vuejs.org/guide/built-ins/keep-alive#keepalive) if you set `keepalive: true` in your `definePageMeta`. This might be useful to do, for example, in a parent route that has dynamic child routes, if you want to preserve page state across route changes.
|
|
309
309
|
|
|
310
|
-
When your goal is to preserve state for parent routes use this syntax: `<NuxtPage keepalive />`. You can also set props to be passed to `<KeepAlive>` (see [a full list](https://vuejs.org/api/built-in-components
|
|
310
|
+
When your goal is to preserve state for parent routes use this syntax: `<NuxtPage keepalive />`. You can also set props to be passed to `<KeepAlive>` (see [a full list](https://vuejs.org/api/built-in-components#keepalive)).
|
|
311
311
|
|
|
312
312
|
You can set a default value for this property [in your `nuxt.config`](/docs/4.x/api/nuxt-config#keepalive).
|
|
313
313
|
|
|
@@ -321,13 +321,13 @@ You can define the layout used to render the route. This can be either false (to
|
|
|
321
321
|
|
|
322
322
|
#### `layoutTransition` and `pageTransition`
|
|
323
323
|
|
|
324
|
-
You can define transition properties for the `<transition>` component that wraps your pages and layouts, or pass `false` to disable the `<transition>` wrapper for that route. You can see [a list of options that can be passed](https://vuejs.org/api/built-in-components
|
|
324
|
+
You can define transition properties for the `<transition>` component that wraps your pages and layouts, or pass `false` to disable the `<transition>` wrapper for that route. You can see [a list of options that can be passed](https://vuejs.org/api/built-in-components#transition) or read [more about how transitions work](https://vuejs.org/guide/built-ins/transition#transition).
|
|
325
325
|
|
|
326
326
|
You can set default values for these properties [in your `nuxt.config`](/docs/4.x/api/nuxt-config#layouttransition).
|
|
327
327
|
|
|
328
328
|
#### `middleware`
|
|
329
329
|
|
|
330
|
-
You can define middleware to apply before loading this page. It will be merged with all the other middleware used in any matching parent/child routes. It can be a string, a function (an anonymous/inlined middleware function following [the global before guard pattern](https://router.vuejs.org/guide/advanced/navigation-guards
|
|
330
|
+
You can define middleware to apply before loading this page. It will be merged with all the other middleware used in any matching parent/child routes. It can be a string, a function (an anonymous/inlined middleware function following [the global before guard pattern](https://router.vuejs.org/guide/advanced/navigation-guards#Global-Before-Guards)), or an array of strings/functions. [More about named middleware](/docs/4.x/guide/directory-structure/app/middleware).
|
|
331
331
|
|
|
332
332
|
#### `name`
|
|
333
333
|
|
|
@@ -335,7 +335,7 @@ You may define a name for this page's route.
|
|
|
335
335
|
|
|
336
336
|
#### `path`
|
|
337
337
|
|
|
338
|
-
You may define a path matcher, if you have a more complex pattern than can be expressed with the file name. See [the `vue-router` docs](https://router.vuejs.org/guide/essentials/route-matching-syntax
|
|
338
|
+
You may define a path matcher, if you have a more complex pattern than can be expressed with the file name. See [the `vue-router` docs](https://router.vuejs.org/guide/essentials/route-matching-syntax#Custom-regex-in-params) for more information.
|
|
339
339
|
|
|
340
340
|
#### `props`
|
|
341
341
|
|
|
@@ -205,7 +205,7 @@ Note that we highly recommend using [`composables`](/docs/4.x/guide/directory-st
|
|
|
205
205
|
|
|
206
206
|
::warning
|
|
207
207
|
**If your plugin provides a `ref` or `computed`, it will not be unwrapped in a component `<template>`.** :br
|
|
208
|
-
This is due to how Vue works with refs that aren't top-level to the template. You can read more about it [in the Vue documentation](https://vuejs.org/guide/essentials/reactivity-fundamentals
|
|
208
|
+
This is due to how Vue works with refs that aren't top-level to the template. You can read more about it [in the Vue documentation](https://vuejs.org/guide/essentials/reactivity-fundamentals#caveat-when-unwrapping-in-templates).
|
|
209
209
|
::
|
|
210
210
|
|
|
211
211
|
## Typing Plugins
|
|
@@ -234,10 +234,6 @@ declare module 'vue' {
|
|
|
234
234
|
export {}
|
|
235
235
|
```
|
|
236
236
|
|
|
237
|
-
::note
|
|
238
|
-
If you are using WebStorm, you may need to augment `@vue/runtime-core` until [this issue](https://youtrack.jetbrains.com/issue/WEB-59818/VUE-TypeScript-WS-PS-does-not-correctly-display-type-of-globally-injected-properties) is resolved.
|
|
239
|
-
::
|
|
240
|
-
|
|
241
237
|
## Vue Plugins
|
|
242
238
|
|
|
243
239
|
If you want to use Vue plugins, like [vue-gtag](https://github.com/MatteoGabriele/vue-gtag) to add Google Analytics tags, you can use a Nuxt plugin to do so.
|
|
@@ -5,7 +5,7 @@ head.title: "node_modules/"
|
|
|
5
5
|
navigation.icon: i-vscode-icons-folder-type-node
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
The package manager ([`npm`](https://docs.npmjs.com/cli/commands/npm) or [`yarn`](https://yarnpkg.com) or [`pnpm`](https://pnpm.io/cli/install) or [`bun`](https://bun.
|
|
8
|
+
The package manager ([`npm`](https://docs.npmjs.com/cli/commands/npm/) or [`yarn`](https://yarnpkg.com) or [`pnpm`](https://pnpm.io/cli/install) or [`bun`](https://bun.com/package-manager)) creates this directory to store the dependencies of your project.
|
|
9
9
|
|
|
10
10
|
::important
|
|
11
11
|
This directory should be added to your [`.gitignore`](/docs/4.x/guide/directory-structure/gitignore) file to avoid pushing the dependencies to your repository.
|
|
@@ -22,6 +22,6 @@ useSeoMeta({
|
|
|
22
22
|
</script>
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
::tip{to="https://v2.nuxt.com/docs/directory-structure/static" target="_blank"}
|
|
25
|
+
::tip{to="https://v2.nuxt.com/docs/directory-structure/static/" target="_blank"}
|
|
26
26
|
This is known as the [`static/`] directory in Nuxt 2.
|
|
27
27
|
::
|
|
@@ -132,9 +132,9 @@ export const defineWrappedResponseHandler = <T extends EventHandlerRequest, D> (
|
|
|
132
132
|
|
|
133
133
|
## Server Types
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
Auto-imports and other types are different for the `server/` directory, as it is running in a different context from the `app/` directory.
|
|
136
|
+
|
|
137
|
+
By default, Nuxt 4 generates a [`tsconfig.json`](/docs/4.x/guide/directory-structure/tsconfig) which includes a project reference covering the `server/` folder which ensures accurate typings.
|
|
138
138
|
|
|
139
139
|
## Recipes
|
|
140
140
|
|
|
@@ -158,7 +158,7 @@ You can now universally call this API on `/api/hello/nuxt` and get `Hello, nuxt!
|
|
|
158
158
|
|
|
159
159
|
### Matching HTTP Method
|
|
160
160
|
|
|
161
|
-
Handle file names can be suffixed with `.get`, `.post`, `.put`, `.delete`, ... to match request's [HTTP Method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods).
|
|
161
|
+
Handle file names can be suffixed with `.get`, `.post`, `.put`, `.delete`, ... to match request's [HTTP Method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods).
|
|
162
162
|
|
|
163
163
|
```ts [server/api/test.get.ts]
|
|
164
164
|
export default defineEventHandler(() => 'Test get handler')
|
|
@@ -226,7 +226,7 @@ export default defineEventHandler(async (event) => {
|
|
|
226
226
|
})
|
|
227
227
|
```
|
|
228
228
|
|
|
229
|
-
::tip{to="https://unjs.io/blog/2023-08-15-h3-towards-the-edge-of-the-web
|
|
229
|
+
::tip{to="https://unjs.io/blog/2023-08-15-h3-towards-the-edge-of-the-web/#runtime-type-safe-request-utils"}
|
|
230
230
|
Alternatively, use `readValidatedBody` with a schema validator such as Zod for runtime and type safety.
|
|
231
231
|
::
|
|
232
232
|
|
|
@@ -75,5 +75,5 @@ Note that for a purely static site, it is not possible to set runtime configurat
|
|
|
75
75
|
|
|
76
76
|
::note
|
|
77
77
|
If you want to use environment variables set at build time but do not care about updating these down the line (or only need to update them reactively _within_ your app) then `appConfig` may be a better choice. You can define `appConfig` both within your `nuxt.config` (using environment variables) and also within an `~/app.config.ts` file in your project.
|
|
78
|
-
:read-more{to="/docs/4.x/guide/directory-structure/app-config"}
|
|
78
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/app-config"}
|
|
79
79
|
::
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "tsconfig.json"
|
|
3
|
-
description: "Nuxt
|
|
3
|
+
description: "Learn how Nuxt manages TypeScript configuration across different parts of your project."
|
|
4
4
|
head.title: "tsconfig.json"
|
|
5
5
|
navigation.icon: i-vscode-icons-file-type-tsconfig
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
Nuxt [automatically generates](/docs/4.x/guide/concepts/typescript) multiple TypeScript configuration files (`.nuxt/tsconfig.app.json`, `.nuxt/tsconfig.server.json`, `.nuxt/tsconfig.node.json` and `.nuxt/tsconfig.shared.json`)
|
|
8
|
+
Nuxt [automatically generates](/docs/4.x/guide/concepts/typescript#auto-generated-types) multiple TypeScript configuration files (`.nuxt/tsconfig.app.json`, `.nuxt/tsconfig.server.json`, `.nuxt/tsconfig.node.json` and `.nuxt/tsconfig.shared.json`) that include recommended basic TypeScript configuration for your project, references to [auto-imports](/docs/4.x/guide/concepts/auto-imports), [API route types](/docs/4.x/guide/concepts/server-engine#typed-api-routes), path aliases, and more.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Your Nuxt project should include the following `tsconfig.json` file at the root of the project:
|
|
11
11
|
|
|
12
12
|
```json [tsconfig.json]
|
|
13
13
|
{
|
|
@@ -29,10 +29,41 @@ You can benefit from this by creating a `tsconfig.json` in the root of your proj
|
|
|
29
29
|
}
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
::
|
|
33
|
-
|
|
32
|
+
::warning
|
|
33
|
+
We do not recommend modifying the contents of this file directly, as doing so could overwrite important settings that Nuxt or other modules rely on. Instead, extend it via `nuxt.config.ts`.
|
|
34
34
|
::
|
|
35
35
|
|
|
36
|
-
::
|
|
37
|
-
|
|
36
|
+
::read-more{to="/docs/4.x/guide/concepts/typescript#project-references"}
|
|
37
|
+
Read more about the different type contexts of a Nuxt project here.
|
|
38
38
|
::
|
|
39
|
+
|
|
40
|
+
## Extending TypeScript Configuration
|
|
41
|
+
|
|
42
|
+
You can customize the TypeScript configuration of your Nuxt project for each context (`app`, `shared`, `node`, and `server`) in the `nuxt.config.ts` file.
|
|
43
|
+
<!-- @case-police-ignore tsConfig -->
|
|
44
|
+
```ts twoslash [nuxt.config.ts]
|
|
45
|
+
export default defineNuxtConfig({
|
|
46
|
+
typescript: {
|
|
47
|
+
// customize tsconfig.app.json
|
|
48
|
+
tsConfig: {
|
|
49
|
+
// ...
|
|
50
|
+
},
|
|
51
|
+
// customize tsconfig.shared.json
|
|
52
|
+
sharedTsConfig: {
|
|
53
|
+
// ...
|
|
54
|
+
},
|
|
55
|
+
// customize tsconfig.node.json
|
|
56
|
+
nodeTsConfig: {
|
|
57
|
+
// ...
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
nitro: {
|
|
61
|
+
typescript: {
|
|
62
|
+
// customize tsconfig.server.json
|
|
63
|
+
tsConfig: {
|
|
64
|
+
// ...
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
```
|
|
@@ -3,7 +3,7 @@ title: Auto-imports
|
|
|
3
3
|
description: "Nuxt auto-imports components, composables, helper functions and Vue APIs."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
Nuxt auto-imports components, composables and [Vue.js APIs](https://vuejs.org/api) to use across your application without explicitly importing them.
|
|
6
|
+
Nuxt auto-imports components, composables and [Vue.js APIs](https://vuejs.org/api/) to use across your application without explicitly importing them.
|
|
7
7
|
|
|
8
8
|
```vue twoslash [app/app.vue]
|
|
9
9
|
<script setup lang="ts">
|
|
@@ -109,7 +109,7 @@ Nuxt directly auto-imports files created in defined directories:
|
|
|
109
109
|
|
|
110
110
|
::warning
|
|
111
111
|
**Auto-imported `ref` and `computed` won't be unwrapped in a component `<template>`.** :br
|
|
112
|
-
This is due to how Vue works with refs that aren't top-level to the template. You can read more about it [in the Vue documentation](https://vuejs.org/guide/essentials/reactivity-fundamentals
|
|
112
|
+
This is due to how Vue works with refs that aren't top-level to the template. You can read more about it [in the Vue documentation](https://vuejs.org/guide/essentials/reactivity-fundamentals#caveat-when-unwrapping-in-templates).
|
|
113
113
|
::
|
|
114
114
|
|
|
115
115
|
### Explicit Imports
|
|
@@ -40,13 +40,13 @@ The Vue and Nuxt instances are created first. Afterward, Nuxt executes its serve
|
|
|
40
40
|
- Built-in plugins, such as Vue Router and `unhead`.
|
|
41
41
|
- Custom plugins located in the `app/plugins/` directory, including those without a suffix (e.g., `myPlugin.ts`) and those with the `.server` suffix (e.g., `myServerPlugin.server.ts`).
|
|
42
42
|
|
|
43
|
-
Plugins execute in a specific order and may have dependencies on one another. For more details, including execution order and parallelism, refer to the [Plugins documentation](/docs/4.x/guide/directory-structure/plugins).
|
|
43
|
+
Plugins execute in a specific order and may have dependencies on one another. For more details, including execution order and parallelism, refer to the [Plugins documentation](/docs/4.x/guide/directory-structure/app/plugins).
|
|
44
44
|
|
|
45
45
|
::callout{icon="i-lucide-lightbulb"}
|
|
46
46
|
After this step, Nuxt calls the [`app:created`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
|
|
47
47
|
::
|
|
48
48
|
|
|
49
|
-
:read-more{to="/docs/4.x/guide/directory-structure/plugins"}
|
|
49
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/plugins"}
|
|
50
50
|
|
|
51
51
|
### Step 4: Route Validation
|
|
52
52
|
|
|
@@ -120,7 +120,7 @@ Custom plugins in the `app/plugins/` directory, such as those without a suffix (
|
|
|
120
120
|
After this step, Nuxt calls the [`app:created`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
|
|
121
121
|
::
|
|
122
122
|
|
|
123
|
-
:read-more{to="/docs/4.x/guide/directory-structure/plugins"}
|
|
123
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/plugins"}
|
|
124
124
|
|
|
125
125
|
### Step 2: Route Validation
|
|
126
126
|
|
|
@@ -21,7 +21,7 @@ We chose to build Nuxt on top of Vue for these reasons:
|
|
|
21
21
|
|
|
22
22
|
### Single File Components
|
|
23
23
|
|
|
24
|
-
[Vue’s single-file components](https://vuejs.org/guide/scaling-up/sfc
|
|
24
|
+
[Vue’s single-file components](https://vuejs.org/guide/scaling-up/sfc) (SFC or `*.vue` files) encapsulate the markup (`<template>`), logic (`<script>`) and styling (`<style>`) of a Vue component. Nuxt provides a zero-config experience for SFCs with [Hot Module Replacement](https://vite.dev/guide/features#hot-module-replacement) that offers a seamless developer experience.
|
|
25
25
|
|
|
26
26
|
### Auto-imports
|
|
27
27
|
|
|
@@ -78,7 +78,7 @@ export default {
|
|
|
78
78
|
</script>
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
The [Composition API](https://vuejs.org/guide/extras/composition-api-faq
|
|
81
|
+
The [Composition API](https://vuejs.org/guide/extras/composition-api-faq) introduced in Vue 3 is not a replacement of the Options API, but it enables better logic reuse throughout an application, and is a more natural way to group code by concern in complex components.
|
|
82
82
|
|
|
83
83
|
Used with the `setup` keyword in the `<script>` definition, here is the above component rewritten with Composition API and Nuxt 3’s auto-imported Reactivity APIs:
|
|
84
84
|
|
|
@@ -91,7 +91,7 @@ const increment = () => count.value++
|
|
|
91
91
|
|
|
92
92
|
The goal of Nuxt is to provide a great developer experience around the Composition API.
|
|
93
93
|
|
|
94
|
-
- Use auto-imported [Reactivity functions](https://vuejs.org/api/reactivity-core
|
|
94
|
+
- Use auto-imported [Reactivity functions](https://vuejs.org/api/reactivity-core) from Vue and Nuxt [built-in composables](/docs/4.x/api/composables/use-async-data).
|
|
95
95
|
- Write your own auto-imported reusable functions in the [`app/composables/` directory](/docs/4.x/guide/directory-structure/app/composables).
|
|
96
96
|
|
|
97
97
|
### TypeScript Support
|
|
@@ -44,7 +44,7 @@ const handleClick = () => {
|
|
|
44
44
|
|
|
45
45
|
On the initial request, the `counter` ref is initialized in the server since it is rendered inside the `<p>` tag. The contents of `handleClick` is never executed here. During hydration in the browser, the `counter` ref is re-initialized. The `handleClick` finally binds itself to the button; Therefore it is reasonable to deduce that the body of `handleClick` will always run in a browser environment.
|
|
46
46
|
|
|
47
|
-
[Middlewares](/docs/4.x/guide/directory-structure/app/middleware) and [pages](/docs/4.x/guide/directory-structure/app/pages) run in the server and on the client during hydration. [Plugins](/docs/4.x/guide/directory-structure/plugins) can be rendered on the server or client or both. [Components](/docs/4.x/guide/directory-structure/app/components) can be forced to run on the client only as well. [Composables](/docs/4.x/guide/directory-structure/app/composables) and [utilities](/docs/4.x/guide/directory-structure/app/utils) are rendered based on the context of their usage.
|
|
47
|
+
[Middlewares](/docs/4.x/guide/directory-structure/app/middleware) and [pages](/docs/4.x/guide/directory-structure/app/pages) run in the server and on the client during hydration. [Plugins](/docs/4.x/guide/directory-structure/app/plugins) can be rendered on the server or client or both. [Components](/docs/4.x/guide/directory-structure/app/components) can be forced to run on the client only as well. [Composables](/docs/4.x/guide/directory-structure/app/composables) and [utilities](/docs/4.x/guide/directory-structure/app/utils) are rendered based on the context of their usage.
|
|
48
48
|
|
|
49
49
|
**Benefits of server-side rendering:**
|
|
50
50
|
- **Performance**: Users can get immediate access to the page's content because browsers can display static content much faster than JavaScript-generated content. At the same time, Nuxt preserves the interactivity of a web application during the hydration process.
|
|
@@ -57,7 +57,7 @@ On the initial request, the `counter` ref is initialized in the server since it
|
|
|
57
57
|
Universal rendering is very versatile and can fit almost any use case, and is especially appropriate for any content-oriented websites: **blogs, marketing websites, portfolios, e-commerce sites, and marketplaces.**
|
|
58
58
|
|
|
59
59
|
::tip
|
|
60
|
-
For more examples about writing Vue code without hydration mismatch, see [the Vue docs](https://vuejs.org/guide/scaling-up/ssr
|
|
60
|
+
For more examples about writing Vue code without hydration mismatch, see [the Vue docs](https://vuejs.org/guide/scaling-up/ssr#hydration-mismatch).
|
|
61
61
|
::
|
|
62
62
|
|
|
63
63
|
::important
|
|
@@ -225,8 +225,8 @@ Edge-side rendering is possible thanks to [Nitro](https://nitro.build/), the [se
|
|
|
225
225
|
|
|
226
226
|
The current platforms where you can leverage ESR are:
|
|
227
227
|
- [Cloudflare Pages](https://pages.cloudflare.com) with zero configuration using the git integration and the `nuxt build` command
|
|
228
|
-
- [Vercel
|
|
229
|
-
- [Netlify Edge Functions](https://www.netlify.com/
|
|
228
|
+
- [Vercel Cloud](https://vercel.com/home) using the `nuxt build` command and `NITRO_PRESET=vercel-edge` environment variable
|
|
229
|
+
- [Netlify Edge Functions](https://www.netlify.com/platform/#netlify-edge-functions) using the `nuxt build` command and `NITRO_PRESET=netlify-edge` environment variable
|
|
230
230
|
|
|
231
231
|
Note that **Hybrid Rendering** can be used when using Edge-Side Rendering with route rules.
|
|
232
232
|
|
|
@@ -31,7 +31,7 @@ export { a }
|
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
Before ECMAScript Modules (ESM) became a standard (it took more than 10 years!), tooling like
|
|
34
|
-
[webpack](https://webpack.js.org/guides/ecma-script-modules) and even languages like TypeScript started supporting so-called **ESM syntax**.
|
|
34
|
+
[webpack](https://webpack.js.org/guides/ecma-script-modules/) and even languages like TypeScript started supporting so-called **ESM syntax**.
|
|
35
35
|
However, there are some key differences with actual spec; here's [a helpful explainer](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/).
|
|
36
36
|
|
|
37
37
|
### What is 'Native' ESM?
|
|
@@ -161,7 +161,7 @@ const pkg = require('cjs-pkg')
|
|
|
161
161
|
console.log(pkg) // { test: 123 }
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
-
[Node.js in native ESM mode](https://nodejs.org/api/esm.html#interoperability-with-commonjs), [typescript with `esModuleInterop` enabled](https://www.typescriptlang.org/tsconfig
|
|
164
|
+
[Node.js in native ESM mode](https://nodejs.org/api/esm.html#interoperability-with-commonjs), [typescript with `esModuleInterop` enabled](https://www.typescriptlang.org/tsconfig/#esModuleInterop) and bundlers such as webpack, provide a compatibility mechanism so that we can default import such library.
|
|
165
165
|
This mechanism is often referred to as "interop require default":
|
|
166
166
|
|
|
167
167
|
```js
|
|
@@ -47,56 +47,37 @@ export default defineNuxtConfig({
|
|
|
47
47
|
|
|
48
48
|
## Auto-generated Types
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
Nuxt projects rely on auto-generated types to work properly. These types are stored in the [`.nuxt`](/docs/4.x/guide/directory-structure/nuxt) directory and are generated when you run the dev server or build your application. You can also generate these files manually by running `nuxt prepare`.
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
The generated `tsconfig.json` files inside the [`.nuxt`](/docs/4.x/guide/directory-structure/nuxt) directory include **recommended basic TypeScript configuration** for your project, references to [auto-imports](/docs/4.x/guide/concepts/auto-imports), [API route types](/docs/4.x/guide/concepts/server-engine#typed-api-routes), path aliases like `#imports`, `~/file`, or `#build/file`, and more.
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
Some of the references in the file are to files that are only generated within your `buildDir` (`.nuxt`) and therefore for full typings, you will need to run `nuxt dev` or `nuxt build`.
|
|
57
|
-
|
|
58
|
-
### `.nuxt/tsconfig.app.json`
|
|
59
|
-
|
|
60
|
-
This file contains the recommended basic TypeScript configuration for your project, including resolved aliases injected by Nuxt or modules you are using, so you can get full type support and path auto-complete for aliases like `~/file` or `#build/file`.
|
|
61
|
-
|
|
62
|
-
::note
|
|
63
|
-
Consider using the `imports` section of [nuxt.config](/docs/4.x/api/nuxt-config#imports) to include directories beyond the default ones. This can be useful for auto-importing types which you're using across your app.
|
|
54
|
+
::warning
|
|
55
|
+
Nuxt relies on this configuration, and [Nuxt Modules](/docs/4.x/guide/going-further/modules) can extend it as well. For this reason, it is not recommended to modify your `tsconfig.json` file directly, as doing so could overwrite important settings. Instead, extend it via `nuxt.config.ts`. [Learn more about extending the configuration here](/docs/4.x/guide/directory-structure/tsconfig).
|
|
64
56
|
::
|
|
65
57
|
|
|
66
|
-
[Read more about how to extend this configuration](/docs/4.x/guide/directory-structure/tsconfig).
|
|
67
|
-
|
|
68
58
|
::tip{icon="i-lucide-video" to="https://youtu.be/umLI7SlPygY" target="_blank"}
|
|
69
59
|
Watch a video from Daniel Roe explaining built-in Nuxt aliases.
|
|
70
60
|
::
|
|
71
61
|
|
|
72
|
-
::note
|
|
73
|
-
Nitro also [auto-generates types](/docs/4.x/guide/concepts/server-engine#typed-api-routes) for API routes. Plus, Nuxt also generates types for globally available components and [auto-imports from your composables](/docs/4.x/guide/directory-structure/app/composables), plus other core functionality.
|
|
74
|
-
::
|
|
75
|
-
|
|
76
|
-
::note
|
|
77
|
-
For backward compatibility, Nuxt still generates `./.nuxt/tsconfig.json`. However, we recommend using [TypeScript project references](/docs/4.x/guide/directory-structure/tsconfig) with the new configuration files (`.nuxt/tsconfig.app.json`, `.nuxt/tsconfig.server.json`, etc.) for better type safety and performance.
|
|
78
|
-
|
|
79
|
-
If you do extend from `./.nuxt/tsconfig.json`, keep in mind that all options will be overwritten by those defined in your `tsconfig.json`. Overwriting options such as `"compilerOptions.paths"` with your own configuration will lead TypeScript to not factor in the module resolutions, which can cause module resolutions such as `#imports` to not be recognized.
|
|
80
|
-
|
|
81
|
-
In case you need to extend options further, you can use the [`alias` property](/docs/4.x/api/nuxt-config#alias) within your `nuxt.config`. Nuxt will pick them up and extend the generated TypeScript configurations accordingly.
|
|
82
|
-
::
|
|
83
|
-
|
|
84
62
|
## Project References
|
|
85
63
|
|
|
86
64
|
Nuxt uses [TypeScript project references](https://www.typescriptlang.org/docs/handbook/project-references.html) to improve type-checking performance and provide better IDE support. This feature allows TypeScript to break up your codebase into smaller, more manageable pieces.
|
|
87
65
|
|
|
88
66
|
### How Nuxt Uses Project References
|
|
89
67
|
|
|
90
|
-
When you run `nuxt dev` or `nuxt
|
|
68
|
+
When you run `nuxt dev`, `nuxt build` or `nuxt prepare`, Nuxt will generate multiple `tsconfig.json` files for different parts of your application.
|
|
91
69
|
|
|
92
|
-
- **`.nuxt/tsconfig.app.json`** - Configuration for your application code
|
|
93
|
-
- **`.nuxt/tsconfig.node.json`** - Configuration for your `nuxt.config` and
|
|
70
|
+
- **`.nuxt/tsconfig.app.json`** - Configuration for your application code within the `app/` directory
|
|
71
|
+
- **`.nuxt/tsconfig.node.json`** - Configuration for your `nuxt.config.ts` and files outside the other contexts
|
|
94
72
|
- **`.nuxt/tsconfig.server.json`** - Configuration for server-side code (when applicable)
|
|
95
73
|
- **`.nuxt/tsconfig.shared.json`** - For code shared between app and server contexts (like types and non-environment specific utilities)
|
|
96
|
-
- **`.nuxt/tsconfig.json`** - Legacy configuration for backward compatibility
|
|
97
74
|
|
|
98
75
|
Each of these files is configured to reference the appropriate dependencies and provide optimal type-checking for their specific context.
|
|
99
76
|
|
|
77
|
+
::note
|
|
78
|
+
For backward compatibility, Nuxt still generates `.nuxt/tsconfig.json`. However, we recommend using [TypeScript project references](/docs/4.x/guide/directory-structure/tsconfig) with the new configuration files (`.nuxt/tsconfig.app.json`, `.nuxt/tsconfig.server.json`, etc.) for better type safety and performance. This legacy file will be removed in a future version of Nuxt.
|
|
79
|
+
::
|
|
80
|
+
|
|
100
81
|
### Benefits of Project References
|
|
101
82
|
|
|
102
83
|
- **Faster builds**: TypeScript can skip rebuilding unchanged projects
|
|
@@ -104,13 +85,9 @@ Each of these files is configured to reference the appropriate dependencies and
|
|
|
104
85
|
- **Isolated compilation**: Errors in one part of your application don't prevent compilation of other parts
|
|
105
86
|
- **Clearer dependency management**: Each project explicitly declares its dependencies
|
|
106
87
|
|
|
107
|
-
::note
|
|
108
|
-
The project reference setup is handled automatically by Nuxt. You typically don't need to modify these configurations manually, but understanding how they work can help you troubleshoot type-checking issues.
|
|
109
|
-
::
|
|
110
|
-
|
|
111
88
|
### Augmenting Types with Project References
|
|
112
89
|
|
|
113
|
-
Since the project is divided into **multiple type contexts**, it's important to **augment types within the correct context** to ensure they
|
|
90
|
+
Since the project is divided into **multiple type contexts**, it's important to **augment types within the correct context** to ensure they're properly recognized. TypeScript will not recognize augmentations placed outside these directories unless they are explicitly included in the appropriate context.
|
|
114
91
|
|
|
115
92
|
For example, if you want to augment types for the `app` context, the augmentation file should be placed in the `app/` directory.
|
|
116
93
|
|
|
@@ -118,15 +95,15 @@ Similarly:
|
|
|
118
95
|
- For the `server` context, place the augmentation file in the `server/` directory.
|
|
119
96
|
- For types that are **shared between the app and server**, place the file in the `shared/` directory.
|
|
120
97
|
|
|
121
|
-
::
|
|
122
|
-
|
|
98
|
+
::read-more{to="/docs/4.x/guide/going-further/modules#extending-tsconfigjson"}
|
|
99
|
+
Read more about augmenting specific type contexts from **files outside those contexts** in the Module Author Guide.
|
|
123
100
|
::
|
|
124
101
|
|
|
125
102
|
## Strict Checks
|
|
126
103
|
|
|
127
104
|
TypeScript comes with certain checks to give you more safety and analysis of your program.
|
|
128
105
|
|
|
129
|
-
[Strict checks](https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html#getting-stricter-checks) are enabled by default in Nuxt to give you greater type safety.
|
|
106
|
+
[Strict checks](https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html#getting-stricter-checks) are enabled by default in Nuxt when the [`typescript.typeCheck`](/docs/4.x/guide/concepts/typescript#type-checking) option is enabled to give you greater type safety.
|
|
130
107
|
|
|
131
108
|
If you are currently converting your codebase to TypeScript, you may want to temporarily disable strict checks by setting `strict` to `false` in your `nuxt.config`:
|
|
132
109
|
|
|
@@ -8,7 +8,7 @@ description: "Nuxt supports ESLint out of the box"
|
|
|
8
8
|
The recommended approach for Nuxt is to enable ESLint support using the [`@nuxt/eslint`](https://eslint.nuxt.com/packages/module) module, that will setup project-aware ESLint configuration for you.
|
|
9
9
|
|
|
10
10
|
:::callout{icon="i-lucide-lightbulb"}
|
|
11
|
-
The module is designed for the [new ESLint flat config format](https://eslint.org/docs/latest/use/configure/configuration-files
|
|
11
|
+
The module is designed for the [new ESLint flat config format](https://eslint.org/docs/latest/use/configure/configuration-files) which is the [default format since ESLint v9](https://eslint.org/blog/2024/04/eslint-v9.0.0-released/). If you are using the legacy `.eslintrc` config, you will need to [configure manually with `@nuxt/eslint-config`](https://eslint.nuxt.com/packages/config#customizing-the-config). We highly recommend you to migrate over the flat config to be future-proof.
|
|
12
12
|
:::
|
|
13
13
|
|
|
14
14
|
## Quick Setup
|
|
@@ -5,7 +5,7 @@ description: "Enable Nuxt experimental features to unlock new possibilities."
|
|
|
5
5
|
|
|
6
6
|
Nuxt includes experimental features that you can enable in your configuration file.
|
|
7
7
|
|
|
8
|
-
Internally, Nuxt uses `@nuxt/schema` to define these experimental features. You can refer to the [API documentation](/docs/4.x/
|
|
8
|
+
Internally, Nuxt uses `@nuxt/schema` to define these experimental features. You can refer to the [API documentation](/docs/4.x/guide/going-further/experimental-features) or the [source code](https://github.com/nuxt/nuxt/blob/main/packages/schema/src/config/experimental.ts) for more information.
|
|
9
9
|
|
|
10
10
|
::note
|
|
11
11
|
Note that these features are experimental and could be removed or modified in the future.
|
|
@@ -290,7 +290,7 @@ export default defineNuxtConfig({
|
|
|
290
290
|
|
|
291
291
|
:link-example{to="https://stackblitz.com/edit/nuxt-view-transitions?file=app.vue" target="_blank"}
|
|
292
292
|
|
|
293
|
-
::read-more{icon="i-simple-icons-mdnwebdocs" to="https://developer.mozilla.org/en-US/docs/Web/API/
|
|
293
|
+
::read-more{icon="i-simple-icons-mdnwebdocs" to="https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API" target="_blank"}
|
|
294
294
|
Read more about the **View Transition API**.
|
|
295
295
|
::
|
|
296
296
|
|
|
@@ -405,12 +405,12 @@ should do this automatically for you.)
|
|
|
405
405
|
// This would be unsafe in a dynamic page (e.g. `[slug].vue`) because the route slug makes a difference
|
|
406
406
|
// to the data fetched, but Nuxt can't know that because it's not reflected in the key.
|
|
407
407
|
const route = useRoute()
|
|
408
|
-
const { data } = await useAsyncData(async () => {
|
|
409
|
-
return await $fetch(`/api/my-page/${route.params.slug}
|
|
408
|
+
const { data } = await useAsyncData(async (_nuxtApp, { signal }) => {
|
|
409
|
+
return await $fetch(`/api/my-page/${route.params.slug}`, { signal })
|
|
410
410
|
})
|
|
411
411
|
// Instead, you should use a key that uniquely identifies the data fetched.
|
|
412
|
-
const { data } = await useAsyncData(route.params.slug, async () => {
|
|
413
|
-
return await $fetch(`/api/my-page/${route.params.slug}
|
|
412
|
+
const { data } = await useAsyncData(route.params.slug, async (_nuxtApp, { signal }) => {
|
|
413
|
+
return await $fetch(`/api/my-page/${route.params.slug}`, { signal })
|
|
414
414
|
})
|
|
415
415
|
```
|
|
416
416
|
|
|
@@ -91,7 +91,7 @@ export default defineNuxtConfig({
|
|
|
91
91
|
|
|
92
92
|
### typescriptBundlerResolution
|
|
93
93
|
|
|
94
|
-
This enables 'Bundler' module resolution mode for TypeScript, which is the recommended setting for frameworks like Nuxt and [Vite](https://vite.dev/guide/performance
|
|
94
|
+
This enables 'Bundler' module resolution mode for TypeScript, which is the recommended setting for frameworks like Nuxt and [Vite](https://vite.dev/guide/performance#reduce-resolve-operations).
|
|
95
95
|
|
|
96
96
|
It improves type support when using modern libraries with `exports`.
|
|
97
97
|
|
|
@@ -30,7 +30,7 @@ Global usage is possible for the browser but not on the server, to avoid sharing
|
|
|
30
30
|
|
|
31
31
|
Since [`useNuxtApp`](/docs/4.x/api/composables/use-nuxt-app) throws an exception if context is currently unavailable, if your composable does not always require `nuxtApp`, you can use [`tryUseNuxtApp`](/docs/4.x/api/composables/use-nuxt-app#tryusenuxtapp) instead, which will return `null` instead of throwing an exception.
|
|
32
32
|
|
|
33
|
-
To extend the `nuxtApp` interface and hook into different stages or access contexts, we can use [Nuxt Plugins](/docs/4.x/guide/directory-structure/plugins).
|
|
33
|
+
To extend the `nuxtApp` interface and hook into different stages or access contexts, we can use [Nuxt Plugins](/docs/4.x/guide/directory-structure/app/plugins).
|
|
34
34
|
|
|
35
35
|
Check [Nuxt App](/docs/4.x/api/composables/use-nuxt-app) for more information about this interface.
|
|
36
36
|
|
|
@@ -76,6 +76,6 @@ Nuxt builds and bundles project using Node.js but also has a runtime side.
|
|
|
76
76
|
|
|
77
77
|
While both areas can be extended, that runtime context is isolated from build-time. Therefore, they are not supposed to share state, code, or context other than runtime configuration!
|
|
78
78
|
|
|
79
|
-
`nuxt.config` and [Nuxt Modules](/docs/4.x/guide/going-further/modules) can be used to extend the build context, and [Nuxt Plugins](/docs/4.x/guide/directory-structure/plugins) can be used to extend runtime.
|
|
79
|
+
`nuxt.config` and [Nuxt Modules](/docs/4.x/guide/going-further/modules) can be used to extend the build context, and [Nuxt Plugins](/docs/4.x/guide/directory-structure/app/plugins) can be used to extend runtime.
|
|
80
80
|
|
|
81
81
|
When building an application for production, `nuxt build` will generate a standalone build in the `.output` directory, independent of `nuxt.config` and [Nuxt modules](/docs/4.x/guide/going-further/modules).
|
|
@@ -39,7 +39,7 @@ Explore all available Nuxt hooks.
|
|
|
39
39
|
|
|
40
40
|
## App Hooks (Runtime)
|
|
41
41
|
|
|
42
|
-
App hooks can be mainly used by [Nuxt Plugins](/docs/4.x/guide/directory-structure/plugins) to hook into rendering lifecycle but could also be used in Vue composables.
|
|
42
|
+
App hooks can be mainly used by [Nuxt Plugins](/docs/4.x/guide/directory-structure/app/plugins) to hook into rendering lifecycle but could also be used in Vue composables.
|
|
43
43
|
|
|
44
44
|
```ts [app/plugins/test.ts]
|
|
45
45
|
export default defineNuxtPlugin((nuxtApp) => {
|