@nuxt/docs-nightly 4.5.1-29752449.30d24817 → 4.5.2-2610052030-052d82e
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/01.introduction.md +8 -8
- package/1.getting-started/02.installation.md +2 -4
- package/1.getting-started/03.configuration.md +16 -16
- package/1.getting-started/04.views.md +8 -8
- package/1.getting-started/05.assets.md +10 -10
- package/1.getting-started/06.styling.md +10 -10
- package/1.getting-started/07.routing.md +15 -15
- package/1.getting-started/08.seo-meta.md +15 -15
- package/1.getting-started/09.transitions.md +10 -10
- package/1.getting-started/10.data-fetching.md +61 -47
- package/1.getting-started/11.state-management.md +11 -11
- package/1.getting-started/12.error-handling.md +20 -18
- package/1.getting-started/13.server.md +7 -7
- package/1.getting-started/14.layers.md +6 -6
- package/1.getting-started/15.prerendering.md +22 -28
- package/1.getting-started/16.deployment.md +22 -6
- package/1.getting-started/17.testing.md +200 -21
- package/1.getting-started/18.upgrade.md +78 -278
- package/2.directory-structure/0.nuxt.md +2 -2
- package/2.directory-structure/0.output.md +3 -3
- package/2.directory-structure/1.app/1.assets.md +3 -3
- package/2.directory-structure/1.app/1.components.md +26 -109
- package/2.directory-structure/1.app/1.composables.md +5 -5
- package/2.directory-structure/1.app/1.layouts.md +10 -10
- package/2.directory-structure/1.app/1.middleware.md +14 -10
- package/2.directory-structure/1.app/1.pages.md +25 -20
- package/2.directory-structure/1.app/1.plugins.md +7 -7
- package/2.directory-structure/1.app/1.utils.md +9 -5
- package/2.directory-structure/1.app/3.app-config.md +7 -7
- package/2.directory-structure/1.app/3.app.md +6 -6
- package/2.directory-structure/1.app/3.error.md +1 -1
- package/2.directory-structure/1.content.md +1 -1
- package/2.directory-structure/1.layers.md +13 -13
- package/2.directory-structure/1.modules.md +3 -3
- package/2.directory-structure/1.node_modules.md +1 -1
- package/2.directory-structure/1.server.md +33 -14
- package/2.directory-structure/1.shared.md +7 -5
- package/2.directory-structure/1.test.md +25 -0
- package/2.directory-structure/2.env.md +7 -7
- package/2.directory-structure/2.nuxtignore.md +3 -3
- package/2.directory-structure/2.nuxtrc.md +3 -3
- package/2.directory-structure/3.nuxt-config.md +2 -2
- package/2.directory-structure/3.tsconfig.md +21 -11
- package/2.directory-structure/index.md +29 -25
- package/3.guide/0.index.md +6 -6
- package/3.guide/1.concepts/1.rendering.md +76 -12
- package/3.guide/1.concepts/10.vuejs-development.md +73 -8
- package/3.guide/1.concepts/2.nuxt-lifecycle.md +18 -18
- package/3.guide/1.concepts/3.auto-imports.md +11 -11
- package/3.guide/1.concepts/4.server-engine.md +6 -6
- package/3.guide/1.concepts/5.modules.md +4 -4
- package/3.guide/1.concepts/6.server-components.md +198 -0
- package/3.guide/1.concepts/7.esm.md +5 -5
- package/3.guide/1.concepts/8.typescript.md +9 -9
- package/3.guide/2.best-practices/accessibility.md +155 -0
- package/3.guide/2.best-practices/hydration.md +5 -5
- package/3.guide/2.best-practices/performance.md +13 -9
- package/3.guide/3.ai/1.mcp.md +104 -19
- package/3.guide/4.modules/2.module-anatomy.md +5 -5
- package/3.guide/4.modules/3.recipes-basics.md +8 -8
- package/3.guide/4.modules/4.module-dependencies.md +1 -1
- package/3.guide/4.modules/5.recipes-advanced.md +6 -8
- package/3.guide/4.modules/6.testing.md +2 -2
- package/3.guide/4.modules/7.best-practices.md +2 -2
- package/3.guide/4.modules/9.server-compatibility.md +215 -0
- package/3.guide/4.modules/index.md +9 -9
- package/3.guide/5.recipes/1.custom-routing.md +15 -11
- package/3.guide/5.recipes/2.vite-plugin.md +3 -3
- package/3.guide/5.recipes/3.custom-usefetch.md +5 -5
- package/3.guide/5.recipes/4.sessions-and-authentication.md +2 -2
- package/3.guide/5.recipes/5.mostly-static-sites.md +127 -0
- package/3.guide/6.going-further/1.events.md +1 -1
- package/3.guide/6.going-further/1.experimental-features.md +254 -22
- package/3.guide/6.going-further/1.features.md +42 -6
- package/3.guide/6.going-further/1.internals.md +10 -10
- package/3.guide/6.going-further/10.runtime-config.md +28 -6
- package/3.guide/6.going-further/11.nightly-release-channel.md +1 -1
- package/3.guide/6.going-further/2.hooks.md +6 -6
- package/3.guide/6.going-further/4.kit.md +4 -4
- package/3.guide/6.going-further/5.server-imports.md +221 -0
- package/3.guide/6.going-further/6.nuxt-app.md +7 -7
- package/3.guide/6.going-further/7.layers.md +13 -13
- package/3.guide/6.going-further/8.builders.md +38 -14
- package/4.api/1.components/1.nuxt-client-fallback.md +1 -1
- package/4.api/1.components/10.nuxt-picture.md +1 -1
- package/4.api/1.components/11.teleports.md +1 -1
- package/4.api/1.components/12.nuxt-route-announcer.md +5 -3
- package/4.api/1.components/14.nuxt-announcer.md +3 -3
- package/4.api/1.components/2.nuxt-page.md +5 -5
- package/4.api/1.components/3.nuxt-layout.md +8 -8
- package/4.api/1.components/4.nuxt-link.md +6 -4
- package/4.api/1.components/5.nuxt-loading-indicator.md +3 -3
- package/4.api/1.components/6.nuxt-error-boundary.md +1 -1
- package/4.api/1.components/8.nuxt-island.md +5 -5
- package/4.api/2.composables/create-use-async-data.md +51 -8
- package/4.api/2.composables/create-use-fetch.md +126 -9
- package/4.api/2.composables/use-announcer.md +3 -3
- package/4.api/2.composables/use-app-config.md +1 -1
- package/4.api/2.composables/use-async-data.md +19 -11
- package/4.api/2.composables/use-cookie.md +22 -6
- package/4.api/2.composables/use-error.md +1 -1
- package/4.api/2.composables/use-fetch.md +14 -10
- package/4.api/2.composables/use-head-safe.md +2 -2
- package/4.api/2.composables/use-head.md +2 -2
- package/4.api/2.composables/use-hydration.md +1 -1
- package/4.api/2.composables/use-layout.md +1 -1
- package/4.api/2.composables/use-lazy-async-data.md +8 -8
- package/4.api/2.composables/use-lazy-fetch.md +11 -11
- package/4.api/2.composables/use-loading-indicator.md +2 -2
- package/4.api/2.composables/use-nuxt-app.md +13 -13
- package/4.api/2.composables/use-nuxt-data.md +1 -1
- package/4.api/2.composables/use-preview-mode.md +3 -3
- package/4.api/2.composables/use-request-event.md +29 -3
- package/4.api/2.composables/use-request-fetch.md +2 -2
- package/4.api/2.composables/use-request-header.md +1 -1
- package/4.api/2.composables/use-request-headers.md +1 -1
- package/4.api/2.composables/use-request-url.md +1 -1
- package/4.api/2.composables/use-response-header.md +2 -2
- package/4.api/2.composables/use-route-announcer.md +4 -2
- package/4.api/2.composables/use-route.md +2 -2
- package/4.api/2.composables/use-router.md +5 -5
- package/4.api/2.composables/use-runtime-config.md +5 -5
- package/4.api/2.composables/use-runtime-hook.md +1 -1
- package/4.api/2.composables/use-seo-meta.md +3 -3
- package/4.api/2.composables/use-server-seo-meta.md +5 -5
- package/4.api/2.composables/use-state.md +4 -4
- package/4.api/3.utils/$fetch.md +5 -5
- package/4.api/3.utils/abort-navigation.md +1 -1
- package/4.api/3.utils/add-route-middleware.md +2 -2
- package/4.api/3.utils/call-once.md +3 -3
- package/4.api/3.utils/clear-error.md +2 -2
- package/4.api/3.utils/clear-nuxt-data.md +1 -1
- package/4.api/3.utils/clear-nuxt-state.md +2 -2
- package/4.api/3.utils/create-error.md +19 -1
- package/4.api/3.utils/define-nuxt-plugin.md +2 -2
- package/4.api/3.utils/define-nuxt-route-middleware.md +3 -3
- package/4.api/3.utils/define-page-meta.md +12 -12
- package/4.api/3.utils/define-route-rules.md +4 -4
- package/4.api/3.utils/define-use-async-data-addon.md +57 -0
- package/4.api/3.utils/define-use-fetch-addon.md +168 -0
- package/4.api/3.utils/navigate-to.md +6 -2
- package/4.api/3.utils/prefetch-components.md +1 -1
- package/4.api/3.utils/preload-route-components.md +2 -2
- package/4.api/3.utils/prerender-routes.md +3 -3
- package/4.api/3.utils/refresh-cookie.md +1 -1
- package/4.api/3.utils/refresh-nuxt-data.md +3 -3
- package/4.api/3.utils/reload-nuxt-app.md +1 -1
- package/4.api/3.utils/set-page-layout.md +1 -1
- package/4.api/3.utils/set-response-status.md +2 -2
- package/4.api/3.utils/show-error.md +3 -3
- package/4.api/3.utils/update-app-config.md +2 -2
- package/4.api/4.commands/README.md +9 -0
- package/4.api/5.kit/1.modules.md +3 -3
- package/4.api/5.kit/10.runtime-config.md +1 -1
- package/4.api/5.kit/10.templates.md +42 -0
- package/4.api/5.kit/12.nitro.md +59 -18
- package/4.api/5.kit/14.logging.md +56 -2
- package/4.api/5.kit/15.builder.md +1 -1
- package/4.api/5.kit/18.dependencies.md +90 -0
- package/4.api/5.kit/2.programmatic.md +78 -1
- package/4.api/5.kit/3.compatibility.md +2 -2
- package/4.api/5.kit/4.autoimports.md +13 -13
- package/4.api/5.kit/5.components.md +3 -3
- package/4.api/5.kit/6.context.md +2 -2
- package/4.api/5.kit/7.pages.md +35 -4
- package/4.api/5.kit/8.layout.md +1 -1
- package/4.api/6.advanced/1.hooks.md +6 -3
- package/4.api/6.nuxt-config.md +44 -21
- package/4.api/index.md +7 -7
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +14 -12
- package/5.community/5.framework-contribution.md +4 -4
- package/5.community/6.roadmap.md +6 -6
- package/6.bridge/1.overview.md +12 -12
- package/6.bridge/2.typescript.md +1 -1
- package/6.bridge/3.bridge-composition-api.md +6 -6
- package/6.bridge/4.plugins-and-middleware.md +4 -4
- package/6.bridge/5.nuxt3-compatible-api.md +9 -9
- package/6.bridge/6.meta.md +5 -5
- package/6.bridge/7.runtime-config.md +1 -1
- package/6.bridge/8.nitro.md +1 -1
- package/6.bridge/9.vite.md +1 -1
- package/7.migration/1.overview.md +2 -2
- package/7.migration/10.bundling.md +1 -1
- package/7.migration/11.server.md +3 -3
- package/7.migration/2.configuration.md +6 -6
- package/7.migration/20.module-authors.md +7 -7
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +4 -4
- package/7.migration/5.plugins-and-middleware.md +3 -3
- package/7.migration/6.pages-and-layouts.md +13 -13
- package/7.migration/7.component-options.md +15 -15
- package/7.migration/8.runtime-config.md +4 -4
- package/README.md +1 -1
- package/errors/e8007.md +28 -0
- package/package.json +2 -2
- package/4.api/4.commands/.navigation.yml +0 -3
- package/4.api/4.commands/add.md +0 -112
- package/4.api/4.commands/analyze.md +0 -42
- package/4.api/4.commands/build-module.md +0 -42
- package/4.api/4.commands/build.md +0 -48
- package/4.api/4.commands/cleanup.md +0 -38
- package/4.api/4.commands/dev.md +0 -61
- package/4.api/4.commands/devtools.md +0 -38
- package/4.api/4.commands/generate.md +0 -43
- package/4.api/4.commands/info.md +0 -33
- package/4.api/4.commands/init.md +0 -50
- package/4.api/4.commands/module.md +0 -84
- package/4.api/4.commands/prepare.md +0 -41
- package/4.api/4.commands/preview.md +0 -44
- package/4.api/4.commands/test.md +0 -40
- package/4.api/4.commands/typecheck.md +0 -44
- package/4.api/4.commands/upgrade.md +0 -37
|
@@ -5,7 +5,7 @@ description: Use the utils/ directory to auto-import your utility functions thro
|
|
|
5
5
|
navigation.icon: i-vscode-icons-folder-type-tools
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
The main purpose of the [`app/utils/` directory](/docs/
|
|
8
|
+
The main purpose of the [`app/utils/` directory](/docs/directory-structure/app/utils) is to allow a semantic distinction between your Vue composables and other auto-imported utility functions.
|
|
9
9
|
|
|
10
10
|
## Usage
|
|
11
11
|
|
|
@@ -35,15 +35,19 @@ You can now use auto imported utility functions in `.js`, `.ts` and `.vue` files
|
|
|
35
35
|
</template>
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
:read-more{to="/docs/
|
|
38
|
+
:read-more{to="/docs/guide/concepts/auto-imports"}
|
|
39
39
|
|
|
40
|
-
:link-example{to="/docs/
|
|
40
|
+
:link-example{to="/docs/examples/features/auto-imports"}
|
|
41
41
|
|
|
42
42
|
::tip
|
|
43
|
-
The way `app/utils/` auto-imports work and are scanned is identical to the [`app/composables/`](/docs/
|
|
43
|
+
The way `app/utils/` auto-imports work and are scanned is identical to the [`app/composables/`](/docs/directory-structure/app/composables) directory.
|
|
44
44
|
::
|
|
45
45
|
|
|
46
46
|
::important
|
|
47
47
|
These utils are only available within the Vue part of your app. :br
|
|
48
|
-
Only `server/utils` are auto-imported in the [`server/`](/docs/
|
|
48
|
+
Only `server/utils` are auto-imported in the [`server/`](/docs/directory-structure/server#server-utilities) directory.
|
|
49
|
+
::
|
|
50
|
+
|
|
51
|
+
::tip
|
|
52
|
+
Types can be auto-imported the same way. Put app-only types in `app/types/`, server-only types in [`server/types/`](/docs/directory-structure/server#server-types), and types shared between both in [`shared/types/`](/docs/directory-structure/shared).
|
|
49
53
|
::
|
|
@@ -20,7 +20,7 @@ Do not put any secret values inside `app.config` file. It is exposed to the user
|
|
|
20
20
|
::
|
|
21
21
|
|
|
22
22
|
::note
|
|
23
|
-
When configuring a custom [`srcDir`](/docs/
|
|
23
|
+
When configuring a custom [`srcDir`](/docs/api/nuxt-config#srcdir), make sure to place the `app.config` file at the root of the new `srcDir` path.
|
|
24
24
|
::
|
|
25
25
|
|
|
26
26
|
## Usage
|
|
@@ -35,7 +35,7 @@ export default defineAppConfig({
|
|
|
35
35
|
})
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
We can now universally access `theme` both when server-rendering the page and in the browser using [`useAppConfig`](/docs/
|
|
38
|
+
We can now universally access `theme` both when server-rendering the page and in the browser using [`useAppConfig`](/docs/api/composables/use-app-config) composable.
|
|
39
39
|
|
|
40
40
|
```vue [app/pages/index.vue]
|
|
41
41
|
<script setup lang="ts">
|
|
@@ -45,7 +45,7 @@ console.log(appConfig.theme)
|
|
|
45
45
|
</script>
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
The [`updateAppConfig`](/docs/
|
|
48
|
+
The [`updateAppConfig`](/docs/api/utils/update-app-config) utility can be used to update the `app.config` at runtime.
|
|
49
49
|
|
|
50
50
|
```vue [app/pages/index.vue]
|
|
51
51
|
<script setup>
|
|
@@ -59,7 +59,7 @@ console.log(appConfig) // { foo: 'baz' }
|
|
|
59
59
|
</script>
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
::read-more{to="/docs/
|
|
62
|
+
::read-more{to="/docs/api/utils/update-app-config"}
|
|
63
63
|
Read more about the `updateAppConfig` utility.
|
|
64
64
|
::
|
|
65
65
|
|
|
@@ -67,7 +67,7 @@ Read more about the `updateAppConfig` utility.
|
|
|
67
67
|
|
|
68
68
|
Nuxt tries to automatically generate a TypeScript interface from provided app config so you won't have to type it yourself.
|
|
69
69
|
|
|
70
|
-
The fully inferred type is only available in app code (components, composables, plugins and so on). In server routes, code in the `shared/` directory and `nuxt.config`, keys defined in `app.config` files are typed as `unknown` instead: typing them there would require typechecking your app code outside the app context, where app auto-imports are not available. Keys defined inline in the `appConfig` option of `nuxt.config` are typed everywhere. If you need other keys typed outside app code, you can extend the `
|
|
70
|
+
The fully inferred type is only available in app code (components, composables, plugins and so on). In server routes, code in the `shared/` directory and `nuxt.config`, keys defined in `app.config` files are typed as `unknown` instead: typing them there would require typechecking your app code outside the app context, where app auto-imports are not available. Keys defined inline in the `appConfig` option of `nuxt.config` are typed everywhere. If you need other keys typed outside app code, you can extend the `SharedAppConfig` interface as described below. The location of the augmentation file determines which contexts see it: a `.d.ts` file in the `shared/` directory covers app code, shared code and server routes.
|
|
71
71
|
|
|
72
72
|
However, there are some cases where you might want to type it yourself. There are two possible things you might want to type.
|
|
73
73
|
|
|
@@ -92,7 +92,7 @@ export {}
|
|
|
92
92
|
|
|
93
93
|
### App Config Output
|
|
94
94
|
|
|
95
|
-
If you want to type the result of calling [`useAppConfig()`](/docs/
|
|
95
|
+
If you want to type the result of calling [`useAppConfig()`](/docs/api/composables/use-app-config) in app code, then you will want to extend `AppConfig`. Outside app code (server routes, the `shared/` directory and `nuxt.config`) `useAppConfig()` returns `SharedAppConfig`, so extend that interface instead.
|
|
96
96
|
|
|
97
97
|
::warning
|
|
98
98
|
Be careful when typing `AppConfig` as you will overwrite the types Nuxt infers from your actually defined app config.
|
|
@@ -116,7 +116,7 @@ export {}
|
|
|
116
116
|
|
|
117
117
|
## Merging Strategy
|
|
118
118
|
|
|
119
|
-
Nuxt uses a custom merging strategy for the `AppConfig` within [the layers](/docs/
|
|
119
|
+
Nuxt uses a custom merging strategy for the `AppConfig` within [the layers](/docs/getting-started/layers) of your application.
|
|
120
120
|
|
|
121
121
|
This strategy is implemented using a [Function Merger](https://github.com/unjs/defu#function-merger), which allows defining a custom merging strategy for every key in `app.config` that has an array as value.
|
|
122
122
|
|
|
@@ -13,7 +13,7 @@ If you have a `app/pages/` directory, the `app.vue` file is optional. Nuxt will
|
|
|
13
13
|
|
|
14
14
|
### Minimal Usage
|
|
15
15
|
|
|
16
|
-
With Nuxt, the [`app/pages/`](/docs/
|
|
16
|
+
With Nuxt, the [`app/pages/`](/docs/directory-structure/app/pages) directory is optional. If it is not present, Nuxt will not include the [vue-router](https://router.vuejs.org) dependency. This is useful when building a landing page or an application that does not require routing.
|
|
17
17
|
|
|
18
18
|
```vue [app/app.vue]
|
|
19
19
|
<template>
|
|
@@ -21,11 +21,11 @@ With Nuxt, the [`app/pages/`](/docs/4.x/directory-structure/app/pages) directory
|
|
|
21
21
|
</template>
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
:link-example{to="/docs/
|
|
24
|
+
:link-example{to="/docs/examples/hello-world"}
|
|
25
25
|
|
|
26
26
|
### Usage with Pages
|
|
27
27
|
|
|
28
|
-
When you have a [`app/pages/`](/docs/
|
|
28
|
+
When you have a [`app/pages/`](/docs/directory-structure/app/pages) directory, you need to use the [`<NuxtPage>`](/docs/api/components/nuxt-page) component to display the current page:
|
|
29
29
|
|
|
30
30
|
```vue [app/app.vue]
|
|
31
31
|
<template>
|
|
@@ -51,13 +51,13 @@ You can also define the common structure of your application directly in `app.vu
|
|
|
51
51
|
Remember that `app.vue` acts as the main component of your Nuxt application. Anything you add to it (JS and CSS) will be global and included in every page.
|
|
52
52
|
::
|
|
53
53
|
|
|
54
|
-
::read-more{to="/docs/
|
|
54
|
+
::read-more{to="/docs/directory-structure/app/pages"}
|
|
55
55
|
Learn more about how to structure your pages using the `app/pages/` directory.
|
|
56
56
|
::
|
|
57
57
|
|
|
58
58
|
### Usage with Layouts
|
|
59
59
|
|
|
60
|
-
When your application requires different layouts for different pages, you can use the `app/layouts/` directory with the [`<NuxtLayout>`](/docs/
|
|
60
|
+
When your application requires different layouts for different pages, you can use the `app/layouts/` directory with the [`<NuxtLayout>`](/docs/api/components/nuxt-layout) component. This allows you to define multiple layouts and apply them per page.
|
|
61
61
|
|
|
62
62
|
```vue [app/app.vue]
|
|
63
63
|
<template>
|
|
@@ -67,6 +67,6 @@ When your application requires different layouts for different pages, you can us
|
|
|
67
67
|
</template>
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
::read-more{to="/docs/
|
|
70
|
+
::read-more{to="/docs/directory-structure/app/layouts"}
|
|
71
71
|
Learn more about how to structure your layouts using the `app/layouts/` directory.
|
|
72
72
|
::
|
|
@@ -23,7 +23,7 @@ const props = defineProps<{ error: NuxtError }>()
|
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
::note
|
|
26
|
-
Although it is called an 'error page' it's not a route and shouldn't be placed in your `~/pages` directory. For the same reason, you shouldn't use `definePageMeta` within this page. That being said, you can still use layouts in the error file, by utilizing the [`NuxtLayout`](/docs/
|
|
26
|
+
Although it is called an 'error page' it's not a route and shouldn't be placed in your `~/pages` directory. For the same reason, you shouldn't use `definePageMeta` within this page. That being said, you can still use layouts in the error file, by utilizing the [`NuxtLayout`](/docs/api/components/nuxt-layout) component and specifying the name of the layout.
|
|
27
27
|
::
|
|
28
28
|
|
|
29
29
|
The error page has a single prop - `error` which contains an error for you to handle.
|
|
@@ -36,7 +36,7 @@ The module automatically loads and parses them.
|
|
|
36
36
|
|
|
37
37
|
## Render Content
|
|
38
38
|
|
|
39
|
-
To render content pages, add a [catch-all route](/docs/
|
|
39
|
+
To render content pages, add a [catch-all route](/docs/directory-structure/app/pages/#catch-all-route) using the [`<ContentRenderer>`](https://content.nuxt.com/docs/components/content-renderer) component:
|
|
40
40
|
|
|
41
41
|
```vue [app/pages/[...slug\\].vue]
|
|
42
42
|
<script lang="ts" setup>
|
|
@@ -64,17 +64,17 @@ Named layer aliases were introduced in Nuxt v3.16.0.
|
|
|
64
64
|
|
|
65
65
|
Each layer can include:
|
|
66
66
|
|
|
67
|
-
- [`nuxt.config.ts`](/docs/
|
|
68
|
-
- [`app.config.ts`](/docs/
|
|
69
|
-
- [`app/components/`](/docs/
|
|
70
|
-
- [`app/composables/`](/docs/
|
|
71
|
-
- [`app/utils/`](/docs/
|
|
72
|
-
- [`app/pages/`](/docs/
|
|
73
|
-
- [`app/layouts/`](/docs/
|
|
74
|
-
- [`app/middleware/`](/docs/
|
|
75
|
-
- [`app/plugins/`](/docs/
|
|
76
|
-
- [`server/`](/docs/
|
|
77
|
-
- [`shared/`](/docs/
|
|
67
|
+
- [`nuxt.config.ts`](/docs/directory-structure/nuxt-config) - Layer-specific configuration that will be merged with the main config
|
|
68
|
+
- [`app.config.ts`](/docs/directory-structure/app/app-config) - Reactive application configuration
|
|
69
|
+
- [`app/components/`](/docs/directory-structure/app/components) - Vue components (auto-imported)
|
|
70
|
+
- [`app/composables/`](/docs/directory-structure/app/composables) - Vue composables (auto-imported)
|
|
71
|
+
- [`app/utils/`](/docs/directory-structure/app/utils) - Utility functions (auto-imported)
|
|
72
|
+
- [`app/pages/`](/docs/directory-structure/app/pages) - Application pages
|
|
73
|
+
- [`app/layouts/`](/docs/directory-structure/app/layouts) - Application layouts
|
|
74
|
+
- [`app/middleware/`](/docs/directory-structure/app/middleware) - Route middleware
|
|
75
|
+
- [`app/plugins/`](/docs/directory-structure/app/plugins) - Nuxt plugins
|
|
76
|
+
- [`server/`](/docs/directory-structure/server) - Server routes, middleware, and utilities
|
|
77
|
+
- [`shared/`](/docs/directory-structure/shared) - Shared code between app and server
|
|
78
78
|
|
|
79
79
|
## Priority Order
|
|
80
80
|
|
|
@@ -82,8 +82,8 @@ When multiple layers define the same resource (component, composable, page, etc.
|
|
|
82
82
|
|
|
83
83
|
To control the order, prefix directories with numbers: `1.base/`, `2.features/`, `3.admin/`.
|
|
84
84
|
|
|
85
|
-
Alternatively, reference the directories in [`extends`](/docs/
|
|
85
|
+
Alternatively, reference the directories in [`extends`](/docs/api/nuxt-config#extends) (e.g. `extends: ['~~/layers/admin', '~~/layers/base']`) to order them from `nuxt.config` without renaming, with the first entry taking the highest priority.
|
|
86
86
|
|
|
87
|
-
:read-more{to="/docs/
|
|
87
|
+
:read-more{to="/docs/getting-started/layers#layer-priority"}
|
|
88
88
|
|
|
89
89
|
:video-accordion{title="Watch a video from Learn Vue about Nuxt Layers" videoId="lnFCM7c9f7I"}
|
|
@@ -11,7 +11,7 @@ The auto-registered files patterns are:
|
|
|
11
11
|
- `modules/*/index.ts`
|
|
12
12
|
- `modules/*.ts`
|
|
13
13
|
|
|
14
|
-
You don't need to add those local modules to your [`nuxt.config.ts`](/docs/
|
|
14
|
+
You don't need to add those local modules to your [`nuxt.config.ts`](/docs/directory-structure/nuxt-config) separately.
|
|
15
15
|
|
|
16
16
|
::code-group
|
|
17
17
|
|
|
@@ -57,7 +57,7 @@ Note that all components, pages, composables and other files that would be norma
|
|
|
57
57
|
::
|
|
58
58
|
|
|
59
59
|
Modules are executed in the following sequence:
|
|
60
|
-
- First, the modules defined in [`nuxt.config.ts`](/docs/
|
|
60
|
+
- First, the modules defined in [`nuxt.config.ts`](/docs/api/nuxt-config#modules-1) are loaded.
|
|
61
61
|
- Then, modules found in the `modules/` directory are executed, and they load in alphabetical order.
|
|
62
62
|
|
|
63
63
|
You can change the order of local module by adding a number to the front of each directory name:
|
|
@@ -69,7 +69,7 @@ modules/
|
|
|
69
69
|
2.second-module.ts
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
:read-more{to="/docs/
|
|
72
|
+
:read-more{to="/docs/guide/modules"}
|
|
73
73
|
|
|
74
74
|
::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/creating-your-first-module-from-scratch?friend=nuxt" target="_blank"}
|
|
75
75
|
Watch Vue School video about Nuxt private modules.
|
|
@@ -8,5 +8,5 @@ navigation.icon: i-vscode-icons-folder-type-node
|
|
|
8
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) or [`deno`](https://docs.deno.com/runtime/getting_started/installation/)) creates this directory to store the dependencies of your project.
|
|
9
9
|
|
|
10
10
|
::important
|
|
11
|
-
This directory should be added to your [`.gitignore`](/docs/
|
|
11
|
+
This directory should be added to your [`.gitignore`](/docs/directory-structure/gitignore) file to avoid pushing the dependencies to your repository.
|
|
12
12
|
::
|
|
@@ -25,7 +25,7 @@ The handler can directly return JSON data, a `Promise`, or use `event.node.res.e
|
|
|
25
25
|
Do not import Vue app code (components, composables, or other app-only utilities) in your server routes or utilities, and do not import server-only code in your app.
|
|
26
26
|
::
|
|
27
27
|
|
|
28
|
-
:read-more{to="/docs/
|
|
28
|
+
:read-more{to="/docs/directory-structure/shared#why-you-cannot-mix-vue-and-nitro-code" title="Why You Cannot Mix Vue and Nitro Code"}
|
|
29
29
|
|
|
30
30
|
```ts twoslash [server/api/hello.ts]
|
|
31
31
|
export default defineEventHandler((event) => {
|
|
@@ -64,7 +64,7 @@ export default defineEventHandler(() => 'Hello World!')
|
|
|
64
64
|
Given the example above, the `/hello` route will be accessible at <http://localhost:3000/hello>.
|
|
65
65
|
|
|
66
66
|
::note
|
|
67
|
-
Note that currently server routes do not support the full functionality of dynamic routes as [pages](/docs/
|
|
67
|
+
Note that currently server routes do not support the full functionality of dynamic routes as [pages](/docs/directory-structure/app/pages#dynamic-routes) do.
|
|
68
68
|
::
|
|
69
69
|
|
|
70
70
|
## Server Middleware
|
|
@@ -160,7 +160,25 @@ The `#server` alias can only be used within the `server/` directory. Importing f
|
|
|
160
160
|
|
|
161
161
|
Auto-imports and other types are different for the `server/` directory, as it is running in a different context from the `app/` directory.
|
|
162
162
|
|
|
163
|
-
By default, Nuxt 4 generates a [`tsconfig.json`](/docs/
|
|
163
|
+
By default, Nuxt 4 generates a [`tsconfig.json`](/docs/directory-structure/tsconfig) which includes a project reference covering the `server/` folder which ensures accurate typings.
|
|
164
|
+
|
|
165
|
+
Types placed in `~~/server/types/` are auto-imported in the server context only, so you can reference them in server routes, middleware, plugins, and utilities without importing them. Types that are also needed in the Vue app belong in [`shared/types/`](/docs/directory-structure/shared) instead.
|
|
166
|
+
|
|
167
|
+
```ts twoslash [server/types/todo.ts]
|
|
168
|
+
export interface Todo {
|
|
169
|
+
id: string
|
|
170
|
+
title: string
|
|
171
|
+
completed: boolean
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
```ts [server/api/todos.get.ts]
|
|
176
|
+
export default defineEventHandler((): Todo[] => {
|
|
177
|
+
return []
|
|
178
|
+
})
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Only files directly in `server/types/` are scanned; files in nested subdirectories are not auto-imported, matching how [`shared/types/`](/docs/directory-structure/shared#how-files-are-scanned) works.
|
|
164
182
|
|
|
165
183
|
## Recipes
|
|
166
184
|
|
|
@@ -177,7 +195,7 @@ export default defineEventHandler((event) => {
|
|
|
177
195
|
```
|
|
178
196
|
|
|
179
197
|
::tip{to="https://h3.dev/examples/validate-data#validate-params"}
|
|
180
|
-
Alternatively, use `getValidatedRouterParams` with a schema validator such as Zod for runtime and type safety.
|
|
198
|
+
Alternatively, use `getValidatedRouterParams` with a schema validator such as Zod or Valibot for runtime and type safety.
|
|
181
199
|
::
|
|
182
200
|
|
|
183
201
|
You can now universally call this API on `/api/hello/nuxt` and get `Hello, nuxt!`.
|
|
@@ -253,7 +271,7 @@ export default defineEventHandler(async (event) => {
|
|
|
253
271
|
```
|
|
254
272
|
|
|
255
273
|
::tip{to="https://unjs.io/blog/2023-08-15-h3-towards-the-edge-of-the-web/#runtime-type-safe-request-utils"}
|
|
256
|
-
Alternatively, use `readValidatedBody` with a schema validator such as Zod for runtime and type safety.
|
|
274
|
+
Alternatively, use `readValidatedBody` with a schema validator such as Zod or Valibot for runtime and type safety.
|
|
257
275
|
::
|
|
258
276
|
|
|
259
277
|
You can now universally call this API using:
|
|
@@ -286,7 +304,7 @@ export default defineEventHandler((event) => {
|
|
|
286
304
|
```
|
|
287
305
|
|
|
288
306
|
::tip{to="https://unjs.io/blog/2023-08-15-h3-towards-the-edge-of-the-web#runtime-type-safe-request-utils"}
|
|
289
|
-
Alternatively, use `getValidatedQuery` with a schema validator such as Zod for runtime and type safety.
|
|
307
|
+
Alternatively, use `getValidatedQuery` with a schema validator such as Zod or Valibot for runtime and type safety.
|
|
290
308
|
::
|
|
291
309
|
|
|
292
310
|
### Error Handling
|
|
@@ -295,7 +313,7 @@ If no errors are thrown, a status code of `200 OK` will be returned.
|
|
|
295
313
|
|
|
296
314
|
Any uncaught errors will return a `500 Internal Server Error` HTTP Error.
|
|
297
315
|
|
|
298
|
-
To return other error codes, throw an exception with [`createError`](/docs/
|
|
316
|
+
To return other error codes, throw an exception with [`createError`](/docs/api/utils/create-error):
|
|
299
317
|
|
|
300
318
|
```ts [server/api/validation/[id\\].ts]
|
|
301
319
|
export default defineEventHandler((event) => {
|
|
@@ -313,7 +331,7 @@ export default defineEventHandler((event) => {
|
|
|
313
331
|
|
|
314
332
|
### Status Codes
|
|
315
333
|
|
|
316
|
-
To return other status codes, use the [`setResponseStatus`](/docs/
|
|
334
|
+
To return other status codes, use the [`setResponseStatus`](/docs/api/utils/set-response-status) utility.
|
|
317
335
|
|
|
318
336
|
For example, to return `202 Accepted`
|
|
319
337
|
|
|
@@ -352,7 +370,7 @@ NUXT_GITHUB_TOKEN='<my-super-token>'
|
|
|
352
370
|
::
|
|
353
371
|
|
|
354
372
|
::note
|
|
355
|
-
Giving the `event` as argument to `useRuntimeConfig` is optional, but it is recommended to pass it to get the runtime config overwritten by [environment variables](/docs/
|
|
373
|
+
Giving the `event` as argument to `useRuntimeConfig` is optional, but it is recommended to pass it to get the runtime config overwritten by [environment variables](/docs/guide/going-further/runtime-config#environment-variables) at runtime for server routes.
|
|
356
374
|
::
|
|
357
375
|
|
|
358
376
|
### Request Cookies
|
|
@@ -418,7 +436,7 @@ export default defineNuxtConfig({
|
|
|
418
436
|
})
|
|
419
437
|
```
|
|
420
438
|
|
|
421
|
-
:read-more{to="/docs/
|
|
439
|
+
:read-more{to="/docs/guide/concepts/server-engine"}
|
|
422
440
|
|
|
423
441
|
### Nested Router
|
|
424
442
|
|
|
@@ -438,12 +456,13 @@ export default useBase('/api/hello', router.handler)
|
|
|
438
456
|
This is an experimental feature and is available in all environments.
|
|
439
457
|
::
|
|
440
458
|
|
|
459
|
+
You can return streams directly from the event handler.
|
|
460
|
+
|
|
441
461
|
```ts [server/api/foo.get.ts]
|
|
442
462
|
import fs from 'node:fs'
|
|
443
|
-
import { sendStream } from 'h3'
|
|
444
463
|
|
|
445
|
-
export default defineEventHandler((
|
|
446
|
-
return
|
|
464
|
+
export default defineEventHandler(() => {
|
|
465
|
+
return fs.createReadStream('/path/to/file')
|
|
447
466
|
})
|
|
448
467
|
```
|
|
449
468
|
|
|
@@ -480,7 +499,7 @@ Never combine `next()` callback with a legacy middleware that is `async` or retu
|
|
|
480
499
|
|
|
481
500
|
### Server Storage
|
|
482
501
|
|
|
483
|
-
Nitro provides a cross-platform [storage layer](https://nitro.build/guide/storage). In order to configure additional storage mount points, you can use `nitro.storage`, or [server plugins](/docs/
|
|
502
|
+
Nitro provides a cross-platform [storage layer](https://nitro.build/guide/storage). In order to configure additional storage mount points, you can use `nitro.storage`, or [server plugins](/docs/directory-structure/server#server-plugins).
|
|
484
503
|
|
|
485
504
|
**Example of adding a Redis storage:**
|
|
486
505
|
|
|
@@ -29,7 +29,9 @@ Server-only code (such as Node APIs, Nitro utilities, or server route handlers)
|
|
|
29
29
|
|
|
30
30
|
### Type-Only Imports
|
|
31
31
|
|
|
32
|
-
`import type` is erased at compile time and does not pull runtime code into the other bundle, so importing only types across the boundary may appear to work. Even so, keep shared types (such as API response types) in `shared/types/`, where they are auto-imported in both contexts. This keeps the boundary clear, avoids accidentally turning a type import into a value import later, and matches Nuxt's separate [type contexts](/docs/
|
|
32
|
+
`import type` is erased at compile time and does not pull runtime code into the other bundle, so importing only types across the boundary may appear to work. Even so, keep shared types (such as API response types) in `shared/types/`, where they are auto-imported in both contexts. This keeps the boundary clear, avoids accidentally turning a type import into a value import later, and matches Nuxt's separate [type contexts](/docs/guide/concepts/typescript#project-references) for app, server, and shared code.
|
|
33
|
+
|
|
34
|
+
Types that are only used in one context can live next to that context instead: `app/types/` is auto-imported in the Vue app only, and [`server/types/`](/docs/directory-structure/server#server-types) is auto-imported in the Nitro server only. Use `shared/types/` when a type is needed in both.
|
|
33
35
|
|
|
34
36
|
:video-accordion{title="Watch a video from Vue School on sharing utils and types between app and server" videoId="nnAR-MO3q5M"}
|
|
35
37
|
|
|
@@ -51,7 +53,7 @@ export default function (input: string) {
|
|
|
51
53
|
}
|
|
52
54
|
```
|
|
53
55
|
|
|
54
|
-
You can now use [auto-imported](/docs/
|
|
56
|
+
You can now use [auto-imported](/docs/directory-structure/shared) utilities in your Nuxt app and `server/` directory.
|
|
55
57
|
|
|
56
58
|
```vue [app/app.vue]
|
|
57
59
|
<script setup lang="ts">
|
|
@@ -78,10 +80,10 @@ export default defineEventHandler((event) => {
|
|
|
78
80
|
Only files in the `shared/utils/` and `shared/types/` directories will be auto-imported. Files nested within subdirectories of these directories will not be auto-imported unless you add these directories to `imports.dirs` and `nitro.imports.dirs`.
|
|
79
81
|
|
|
80
82
|
::tip
|
|
81
|
-
The way `shared/utils` and `shared/types` auto-imports work and are scanned is identical to the [`app/composables/`](/docs/
|
|
83
|
+
The way `shared/utils` and `shared/types` auto-imports work and are scanned is identical to the [`app/composables/`](/docs/directory-structure/app/composables) and [`app/utils/`](/docs/directory-structure/app/utils) directories.
|
|
82
84
|
::
|
|
83
85
|
|
|
84
|
-
:read-more{to="/docs/
|
|
86
|
+
:read-more{to="/docs/directory-structure/app/composables#how-files-are-scanned"}
|
|
85
87
|
|
|
86
88
|
```bash [Directory Structure]
|
|
87
89
|
-| shared/
|
|
@@ -111,4 +113,4 @@ import upper from '#shared/utils/formatters/upper'
|
|
|
111
113
|
|
|
112
114
|
This alias ensures consistent imports across your application, regardless of the importing file's location.
|
|
113
115
|
|
|
114
|
-
:read-more{to="/docs/
|
|
116
|
+
:read-more{to="/docs/guide/concepts/auto-imports"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'test'
|
|
3
|
+
head.title: 'test/'
|
|
4
|
+
description: 'Use the test/ directory to organize unit, Nuxt, and end-to-end tests for your application.'
|
|
5
|
+
navigation.icon: i-vscode-icons-folder-type-test
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
The `test/` directory is the recommended place for your application tests. Nuxt does not scan it the way it does `app/` or `server/`; you choose the runner and layout yourself (typically with [`@nuxt/test-utils`](/docs/getting-started/testing)).
|
|
9
|
+
|
|
10
|
+
A common layout separates environments:
|
|
11
|
+
|
|
12
|
+
```bash [Directory structure]
|
|
13
|
+
-| test/
|
|
14
|
+
---| e2e/
|
|
15
|
+
---| nuxt/
|
|
16
|
+
---| unit/
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- `test/unit/` — fast Node tests without the Nuxt runtime
|
|
20
|
+
- `test/nuxt/` — tests that need the Nuxt runtime environment
|
|
21
|
+
- `test/e2e/` — end-to-end tests against a running app
|
|
22
|
+
|
|
23
|
+
::read-more{to="/docs/getting-started/testing#organizing-your-tests"}
|
|
24
|
+
See **Organizing Your Tests** for setup, Vitest projects, and TypeScript context.
|
|
25
|
+
::
|
|
@@ -6,12 +6,12 @@ navigation.icon: i-vscode-icons-file-type-dotenv
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
::important
|
|
9
|
-
This file should be added to your [`.gitignore`](/docs/
|
|
9
|
+
This file should be added to your [`.gitignore`](/docs/directory-structure/gitignore) file to avoid pushing secrets to your repository.
|
|
10
10
|
::
|
|
11
11
|
|
|
12
12
|
## Dev, Build and Generate Time
|
|
13
13
|
|
|
14
|
-
Nuxt CLI has built-in [
|
|
14
|
+
Nuxt CLI has built-in `.env` support via [c12](https://github.com/unjs/c12) in development mode and when running [`nuxt build`](/docs/api/commands/build) and [`nuxt generate`](/docs/api/commands/generate).
|
|
15
15
|
|
|
16
16
|
In addition to any process environment variables, if you have a `.env` file in your project root directory, it will be automatically loaded **at dev, build and generate time**. Any environment variables set there will be accessible within your `nuxt.config` file and modules.
|
|
17
17
|
|
|
@@ -34,7 +34,7 @@ npx nuxt dev --dotenv .env.local
|
|
|
34
34
|
When updating `.env` in development mode, the Nuxt instance is automatically restarted to apply new values to the `process.env`.
|
|
35
35
|
|
|
36
36
|
::important
|
|
37
|
-
In your application code, you should use [Runtime Config](/docs/
|
|
37
|
+
In your application code, you should use [Runtime Config](/docs/guide/going-further/runtime-config) instead of plain env variables.
|
|
38
38
|
::
|
|
39
39
|
|
|
40
40
|
## Production
|
|
@@ -56,12 +56,12 @@ Since `.env` files are not used in production, you must explicitly set environme
|
|
|
56
56
|
* Many cloud service providers, such as Vercel, Netlify, and AWS, provide interfaces for setting environment variables via their dashboards, CLI tools or configuration files.
|
|
57
57
|
|
|
58
58
|
::important
|
|
59
|
-
`runtimeConfig` [won't pick up environment variables that don't start with `NUXT_` in production] (
|
|
59
|
+
`runtimeConfig` [won't pick up environment variables that don't start with `NUXT_` in production] (/docs/guide/going-further/runtime-config#environment-variables).
|
|
60
60
|
::
|
|
61
61
|
|
|
62
62
|
## Production Preview
|
|
63
63
|
|
|
64
|
-
For local production preview purpose, we recommend using [`nuxt preview`](/docs/
|
|
64
|
+
For local production preview purpose, we recommend using [`nuxt preview`](/docs/api/commands/preview) since using this command, the `.env` file will be loaded into `process.env` for convenience. Note that this command requires dependencies to be installed in the package directory.
|
|
65
65
|
|
|
66
66
|
Or you could pass the environment variables as arguments using the terminal. For example, on Linux or macOS:
|
|
67
67
|
|
|
@@ -71,9 +71,9 @@ NODE_ENV=production DATABASE_HOST=mydatabaseconnectionstring node .output/server
|
|
|
71
71
|
|
|
72
72
|
Note that for a purely static site, it is not possible to set runtime configuration config after your project is prerendered.
|
|
73
73
|
|
|
74
|
-
:read-more{to="/docs/
|
|
74
|
+
:read-more{to="/docs/guide/going-further/runtime-config"}
|
|
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/
|
|
78
|
+
:read-more{to="/docs/directory-structure/app/app-config"}
|
|
79
79
|
::
|
|
@@ -6,12 +6,12 @@ navigation.icon: i-vscode-icons-file-type-nuxt
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
The `.nuxtignore` file tells Nuxt to ignore files in your project’s root directory ([`rootDir`](/docs/
|
|
9
|
+
The `.nuxtignore` file tells Nuxt to ignore files in your project’s root directory ([`rootDir`](/docs/api/nuxt-config#rootdir)) during the build phase.
|
|
10
10
|
|
|
11
|
-
It is subject to the same specification as [`.gitignore`](/docs/
|
|
11
|
+
It is subject to the same specification as [`.gitignore`](/docs/directory-structure/gitignore) and `.eslintignore` files, in which each line is a glob pattern indicating which files should be ignored.
|
|
12
12
|
|
|
13
13
|
::tip
|
|
14
|
-
You can also configure [`ignoreOptions`](/docs/
|
|
14
|
+
You can also configure [`ignoreOptions`](/docs/api/nuxt-config#ignoreoptions), [`ignorePrefix`](/docs/api/nuxt-config#ignoreprefix) and [`ignore`](/docs/api/nuxt-config#ignore) in your `nuxt.config` file.
|
|
15
15
|
::
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
@@ -8,7 +8,7 @@ navigation.icon: i-vscode-icons-file-type-nuxt
|
|
|
8
8
|
The `.nuxtrc` file can be used to configure Nuxt with a flat syntax. It is based on [`unjs/rc9`](https://github.com/unjs/rc9).
|
|
9
9
|
|
|
10
10
|
::tip
|
|
11
|
-
For more advanced configurations, use [`nuxt.config`](/docs/
|
|
11
|
+
For more advanced configurations, use [`nuxt.config`](/docs/directory-structure/nuxt-config).
|
|
12
12
|
::
|
|
13
13
|
|
|
14
14
|
## Usage
|
|
@@ -31,10 +31,10 @@ setups.@nuxt/test-utils="3.23.0"
|
|
|
31
31
|
If present, the properties in the `nuxt.config` file will overwrite the properties in `.nuxtrc` file.
|
|
32
32
|
|
|
33
33
|
::note
|
|
34
|
-
Nuxt automatically adds a `setups` section to track module installation and upgrade state. This is used internally for [module lifecycle hooks](/docs/
|
|
34
|
+
Nuxt automatically adds a `setups` section to track module installation and upgrade state. This is used internally for [module lifecycle hooks](/docs/api/kit/modules#using-lifecycle-hooks-for-module-installation-and-upgrade) and should not be modified manually.
|
|
35
35
|
::
|
|
36
36
|
|
|
37
|
-
::read-more{to="/docs/
|
|
37
|
+
::read-more{to="/docs/api/configuration/nuxt-config"}
|
|
38
38
|
Discover all the available options in the **Nuxt configuration** documentation.
|
|
39
39
|
::
|
|
40
40
|
|
|
@@ -27,8 +27,8 @@ export default defineNuxtConfig({
|
|
|
27
27
|
})
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
::read-more{to="/docs/
|
|
30
|
+
::read-more{to="/docs/api/configuration/nuxt-config"}
|
|
31
31
|
Discover all the available options in the **Nuxt configuration** documentation.
|
|
32
32
|
::
|
|
33
33
|
|
|
34
|
-
To ensure your configuration is up to date, Nuxt will make a full restart when detecting changes in the main configuration file, the [`.env`](/docs/
|
|
34
|
+
To ensure your configuration is up to date, Nuxt will make a full restart when detecting changes in the main configuration file, the [`.env`](/docs/directory-structure/env), [`.nuxtignore`](/docs/directory-structure/nuxtignore) and [`.nuxtrc`](/docs/directory-structure/nuxtrc) dotfiles.
|
|
@@ -5,7 +5,7 @@ head.title: "tsconfig.json"
|
|
|
5
5
|
navigation.icon: i-vscode-icons-file-type-tsconfig
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
Nuxt [automatically generates](/docs/
|
|
8
|
+
Nuxt [automatically generates](/docs/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/guide/concepts/auto-imports), [API route types](/docs/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
|
|
|
@@ -33,20 +33,26 @@ Your Nuxt project should include the following `tsconfig.json` file at the root
|
|
|
33
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
|
-
::read-more{to="/docs/
|
|
36
|
+
::read-more{to="/docs/guide/concepts/typescript#project-references"}
|
|
37
37
|
Read more about the different type contexts of a Nuxt project here.
|
|
38
38
|
::
|
|
39
39
|
|
|
40
40
|
## Extending TypeScript Configuration
|
|
41
41
|
|
|
42
|
-
You can customize the TypeScript configuration of your Nuxt project for each context (`app`, `shared`, `node`, and `server`)
|
|
42
|
+
You can customize the TypeScript configuration of your Nuxt project in the `nuxt.config.ts` file: set shared `compilerOptions` for every context at once with `typescript.tsConfig`, and override them for each context (`app`, `shared`, `node`, and `server`) individually.
|
|
43
43
|
<!-- @case-police-ignore tsConfig -->
|
|
44
44
|
```ts twoslash [nuxt.config.ts]
|
|
45
45
|
// @errors: 2353
|
|
46
46
|
export default defineNuxtConfig({
|
|
47
47
|
typescript: {
|
|
48
|
-
//
|
|
48
|
+
// shared compiler options for every generated tsconfig
|
|
49
49
|
tsConfig: {
|
|
50
|
+
compilerOptions: {
|
|
51
|
+
// ...
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
// customize tsconfig.app.json
|
|
55
|
+
appTsConfig: {
|
|
50
56
|
// ...
|
|
51
57
|
},
|
|
52
58
|
// customize tsconfig.shared.json
|
|
@@ -57,14 +63,18 @@ export default defineNuxtConfig({
|
|
|
57
63
|
nodeTsConfig: {
|
|
58
64
|
// ...
|
|
59
65
|
},
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// customize tsconfig.server.json
|
|
64
|
-
tsConfig: {
|
|
65
|
-
// ...
|
|
66
|
-
},
|
|
66
|
+
// customize tsconfig.server.json
|
|
67
|
+
serverTsConfig: {
|
|
68
|
+
// ...
|
|
67
69
|
},
|
|
68
70
|
},
|
|
69
71
|
})
|
|
70
72
|
```
|
|
73
|
+
|
|
74
|
+
::note
|
|
75
|
+
Most `compilerOptions` set in `typescript.tsConfig` are shared with every context, but a few are not. DOM- and Vue-specific options (such as `lib`, `jsx` and `jsxImportSource`) only make sense for your application code, so they are applied to `tsconfig.app.json` alone. Nuxt also manages `types`, `paths` and `noEmit` per context (the `node`, `shared` and `server` configs deliberately emit nothing and scan no ambient types), so setting these in `typescript.tsConfig` will not change them. Use the matching per-context option (`appTsConfig`, `nodeTsConfig`, `sharedTsConfig` or `serverTsConfig`) when you need to override them.
|
|
76
|
+
::
|
|
77
|
+
|
|
78
|
+
::note
|
|
79
|
+
`typescript.serverTsConfig` extends `tsconfig.server.json`. `nitro.typescript.tsConfig` is kept in sync with it but is deprecated, so set `typescript.serverTsConfig` instead.
|
|
80
|
+
::
|