@nuxt/docs 3.20.1 → 3.21.0
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 +5 -5
- package/1.getting-started/02.installation.md +4 -7
- package/1.getting-started/03.configuration.md +32 -32
- package/1.getting-started/04.views.md +10 -8
- package/1.getting-started/05.assets.md +8 -8
- package/1.getting-started/06.styling.md +24 -18
- package/1.getting-started/07.routing.md +11 -11
- package/1.getting-started/08.seo-meta.md +10 -6
- package/1.getting-started/09.transitions.md +12 -12
- package/1.getting-started/10.data-fetching.md +18 -18
- package/1.getting-started/11.state-management.md +7 -7
- package/1.getting-started/12.error-handling.md +28 -22
- package/1.getting-started/13.server.md +9 -9
- package/1.getting-started/14.layers.md +52 -18
- package/1.getting-started/15.prerendering.md +10 -4
- package/1.getting-started/16.deployment.md +3 -2
- package/1.getting-started/17.testing.md +18 -8
- package/1.getting-started/18.upgrade.md +111 -60
- package/{2.guide/1.directory-structure → 2.directory-structure}/0.nuxt.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/0.output.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.assets.md +3 -3
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.components.md +13 -9
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.composables.md +4 -4
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.content.md +2 -2
- package/2.directory-structure/1.layers.md +87 -0
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.layouts.md +37 -5
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.middleware.md +8 -8
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.modules.md +10 -4
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.node_modules.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.pages.md +43 -22
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.plugins.md +6 -3
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.public.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.server.md +29 -9
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.shared.md +4 -4
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.utils.md +5 -5
- package/{2.guide/1.directory-structure → 2.directory-structure}/2.env.md +4 -4
- package/{2.guide/1.directory-structure → 2.directory-structure}/2.nuxtignore.md +2 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/2.nuxtrc.md +6 -3
- package/{2.guide/1.directory-structure → 2.directory-structure}/3.app-config.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/3.app.md +5 -5
- package/{2.guide/1.directory-structure → 2.directory-structure}/3.error.md +10 -8
- package/{2.guide/1.directory-structure → 2.directory-structure}/3.nuxt-config.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/3.package.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/3.tsconfig.md +3 -2
- package/2.directory-structure/index.md +65 -0
- package/3.guide/0.index.md +28 -0
- package/{2.guide/2.concepts/3.rendering.md → 3.guide/1.concepts/1.rendering.md} +8 -33
- package/{2.guide/2.concepts/2.vuejs-development.md → 3.guide/1.concepts/10.vuejs-development.md} +11 -10
- package/{2.guide/2.concepts/10.nuxt-lifecycle.md → 3.guide/1.concepts/2.nuxt-lifecycle.md} +34 -27
- package/{2.guide/2.concepts/1.auto-imports.md → 3.guide/1.concepts/3.auto-imports.md} +10 -10
- package/{2.guide/2.concepts → 3.guide/1.concepts}/4.server-engine.md +3 -3
- package/{2.guide/2.concepts → 3.guide/1.concepts}/5.modules.md +15 -2
- package/{2.guide/2.concepts → 3.guide/1.concepts}/7.esm.md +5 -4
- package/{2.guide/2.concepts → 3.guide/1.concepts}/8.typescript.md +11 -17
- package/{2.guide/2.concepts → 3.guide/1.concepts}/9.code-style.md +1 -1
- package/{2.guide/5.best-practices → 3.guide/2.best-practices}/hydration.md +1 -1
- package/{2.guide/5.best-practices → 3.guide/2.best-practices}/performance.md +5 -5
- package/3.guide/3.ai/.navigation.yml +3 -0
- package/3.guide/3.ai/1.mcp.md +277 -0
- package/3.guide/3.ai/2.llms-txt.md +65 -0
- package/3.guide/4.modules/.navigation.yml +3 -0
- package/3.guide/4.modules/1.getting-started.md +103 -0
- package/3.guide/4.modules/2.module-anatomy.md +138 -0
- package/3.guide/4.modules/3.recipes-basics.md +330 -0
- package/3.guide/4.modules/4.recipes-advanced.md +243 -0
- package/3.guide/4.modules/5.testing.md +76 -0
- package/3.guide/4.modules/6.best-practices.md +104 -0
- package/3.guide/4.modules/7.ecosystem.md +32 -0
- package/3.guide/4.modules/index.md +36 -0
- package/{2.guide/4.recipes → 3.guide/5.recipes}/1.custom-routing.md +4 -4
- package/{2.guide/4.recipes → 3.guide/5.recipes}/2.vite-plugin.md +5 -1
- package/{2.guide/4.recipes → 3.guide/5.recipes}/3.custom-usefetch.md +3 -3
- package/{2.guide/4.recipes → 3.guide/5.recipes}/4.sessions-and-authentication.md +2 -2
- package/{2.guide/3.going-further → 3.guide/6.going-further}/1.events.md +3 -4
- package/{2.guide/3.going-further → 3.guide/6.going-further}/1.experimental-features.md +212 -87
- package/3.guide/6.going-further/1.features.md +108 -0
- package/{2.guide/3.going-further → 3.guide/6.going-further}/1.internals.md +5 -4
- package/{2.guide/3.going-further → 3.guide/6.going-further}/10.runtime-config.md +3 -3
- package/{2.guide/3.going-further → 3.guide/6.going-further}/11.nightly-release-channel.md +1 -1
- package/{2.guide/3.going-further → 3.guide/6.going-further}/2.hooks.md +7 -7
- package/{2.guide/3.going-further → 3.guide/6.going-further}/4.kit.md +3 -3
- package/{2.guide/3.going-further → 3.guide/6.going-further}/6.nuxt-app.md +6 -6
- package/{2.guide/3.going-further → 3.guide/6.going-further}/7.layers.md +40 -14
- package/{2.guide/3.going-further → 3.guide/6.going-further}/9.debugging.md +3 -2
- package/{3.api → 4.api}/1.components/1.nuxt-client-fallback.md +5 -1
- package/{3.api → 4.api}/1.components/10.nuxt-picture.md +1 -1
- package/{3.api → 4.api}/1.components/11.teleports.md +2 -2
- package/{3.api → 4.api}/1.components/12.nuxt-route-announcer.md +1 -3
- package/{3.api → 4.api}/1.components/13.nuxt-time.md +0 -2
- package/{3.api → 4.api}/1.components/2.nuxt-page.md +4 -4
- package/{3.api → 4.api}/1.components/3.nuxt-layout.md +7 -7
- package/{3.api → 4.api}/1.components/4.nuxt-link.md +13 -13
- package/{3.api → 4.api}/1.components/5.nuxt-loading-indicator.md +2 -2
- package/{3.api → 4.api}/1.components/6.nuxt-error-boundary.md +2 -2
- package/{3.api → 4.api}/1.components/7.nuxt-welcome.md +2 -2
- package/{3.api → 4.api}/1.components/8.nuxt-island.md +9 -2
- package/{3.api → 4.api}/2.composables/use-app-config.md +1 -1
- package/{3.api → 4.api}/2.composables/use-async-data.md +5 -5
- package/4.api/2.composables/use-cookie.md +183 -0
- package/{3.api → 4.api}/2.composables/use-error.md +3 -3
- package/{3.api → 4.api}/2.composables/use-fetch.md +37 -37
- package/{3.api → 4.api}/2.composables/use-head-safe.md +1 -1
- package/{3.api → 4.api}/2.composables/use-head.md +22 -7
- package/{3.api → 4.api}/2.composables/use-lazy-async-data.md +1 -1
- package/{3.api → 4.api}/2.composables/use-lazy-fetch.md +9 -9
- package/{3.api → 4.api}/2.composables/use-nuxt-app.md +11 -9
- package/{3.api → 4.api}/2.composables/use-response-header.md +1 -1
- package/{3.api → 4.api}/2.composables/use-route-announcer.md +0 -2
- package/{3.api → 4.api}/2.composables/use-route.md +2 -2
- package/4.api/2.composables/use-router.md +94 -0
- package/{3.api → 4.api}/2.composables/use-runtime-config.md +5 -5
- package/{3.api → 4.api}/2.composables/use-seo-meta.md +2 -2
- package/{3.api → 4.api}/2.composables/use-server-seo-meta.md +2 -2
- package/{3.api → 4.api}/2.composables/use-state.md +12 -2
- package/{3.api → 4.api}/3.utils/$fetch.md +2 -2
- package/{3.api → 4.api}/3.utils/abort-navigation.md +3 -3
- package/{3.api → 4.api}/3.utils/add-route-middleware.md +1 -1
- package/{3.api → 4.api}/3.utils/call-once.md +2 -4
- package/{3.api → 4.api}/3.utils/clear-error.md +1 -1
- package/{3.api → 4.api}/3.utils/create-error.md +7 -7
- package/{3.api → 4.api}/3.utils/define-lazy-hydration-component.md +5 -5
- package/{3.api → 4.api}/3.utils/define-nuxt-component.md +1 -1
- package/{3.api → 4.api}/3.utils/define-nuxt-plugin.md +12 -12
- package/{3.api → 4.api}/3.utils/define-nuxt-route-middleware.md +3 -3
- package/{3.api → 4.api}/3.utils/define-page-meta.md +23 -16
- package/{3.api → 4.api}/3.utils/define-route-rules.md +2 -2
- package/{3.api → 4.api}/3.utils/navigate-to.md +14 -14
- package/{3.api → 4.api}/3.utils/on-before-route-leave.md +1 -1
- package/{3.api → 4.api}/3.utils/on-before-route-update.md +1 -1
- package/{3.api → 4.api}/3.utils/preload-route-components.md +2 -2
- package/{3.api → 4.api}/3.utils/refresh-cookie.md +0 -2
- package/{3.api → 4.api}/3.utils/refresh-nuxt-data.md +1 -1
- package/{3.api → 4.api}/3.utils/reload-nuxt-app.md +1 -1
- package/{3.api → 4.api}/3.utils/set-page-layout.md +36 -0
- package/{3.api → 4.api}/3.utils/set-response-status.md +3 -3
- package/{3.api → 4.api}/3.utils/show-error.md +4 -4
- package/{3.api → 4.api}/3.utils/update-app-config.md +2 -2
- package/{3.api → 4.api}/4.commands/add.md +11 -11
- package/4.api/4.commands/analyze.md +42 -0
- package/4.api/4.commands/build-module.md +42 -0
- package/4.api/4.commands/build.md +47 -0
- package/{3.api → 4.api}/4.commands/cleanup.md +6 -6
- package/4.api/4.commands/dev.md +60 -0
- package/{3.api → 4.api}/4.commands/devtools.md +7 -7
- package/4.api/4.commands/generate.md +42 -0
- package/4.api/4.commands/info.md +33 -0
- package/4.api/4.commands/init.md +50 -0
- package/4.api/4.commands/module.md +84 -0
- package/4.api/4.commands/prepare.md +41 -0
- package/4.api/4.commands/preview.md +44 -0
- package/4.api/4.commands/test.md +40 -0
- package/4.api/4.commands/typecheck.md +44 -0
- package/4.api/4.commands/upgrade.md +37 -0
- package/{3.api → 4.api}/5.kit/1.modules.md +31 -18
- package/{3.api → 4.api}/5.kit/10.templates.md +23 -23
- package/{3.api → 4.api}/5.kit/11.nitro.md +36 -36
- package/{3.api → 4.api}/5.kit/12.resolving.md +2 -2
- package/{3.api → 4.api}/5.kit/14.builder.md +35 -23
- package/{3.api → 4.api}/5.kit/16.layers.md +16 -16
- package/{3.api → 4.api}/5.kit/2.programmatic.md +2 -2
- package/{3.api → 4.api}/5.kit/3.compatibility.md +2 -2
- package/{3.api → 4.api}/5.kit/4.autoimports.md +18 -18
- package/4.api/5.kit/5.components.md +146 -0
- package/{3.api → 4.api}/5.kit/6.context.md +1 -1
- package/{3.api → 4.api}/5.kit/8.layout.md +1 -1
- package/4.api/6.advanced/1.hooks.md +105 -0
- package/{3.api → 4.api}/index.md +7 -7
- package/5.community/4.contribution.md +10 -10
- package/5.community/5.framework-contribution.md +9 -9
- package/5.community/6.roadmap.md +25 -25
- package/5.community/7.changelog.md +20 -0
- package/6.bridge/1.overview.md +9 -1
- package/6.bridge/3.bridge-composition-api.md +2 -2
- package/6.bridge/4.plugins-and-middleware.md +4 -4
- package/6.bridge/5.nuxt3-compatible-api.md +1 -1
- package/6.bridge/8.nitro.md +4 -0
- 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 +3 -3
- package/7.migration/3.auto-imports.md +1 -1
- package/7.migration/4.meta.md +1 -1
- package/7.migration/5.plugins-and-middleware.md +3 -3
- package/7.migration/6.pages-and-layouts.md +9 -9
- package/7.migration/7.component-options.md +6 -6
- package/7.migration/8.runtime-config.md +1 -1
- package/package.json +1 -1
- package/2.guide/0.index.md +0 -25
- package/2.guide/3.going-further/1.features.md +0 -103
- package/2.guide/3.going-further/3.modules.md +0 -901
- package/3.api/2.composables/use-cookie.md +0 -183
- package/3.api/2.composables/use-router.md +0 -94
- package/3.api/4.commands/analyze.md +0 -42
- package/3.api/4.commands/build-module.md +0 -42
- package/3.api/4.commands/build.md +0 -47
- package/3.api/4.commands/dev.md +0 -60
- package/3.api/4.commands/generate.md +0 -42
- package/3.api/4.commands/info.md +0 -33
- package/3.api/4.commands/init.md +0 -50
- package/3.api/4.commands/module.md +0 -84
- package/3.api/4.commands/prepare.md +0 -41
- package/3.api/4.commands/preview.md +0 -44
- package/3.api/4.commands/test.md +0 -40
- package/3.api/4.commands/typecheck.md +0 -44
- package/3.api/4.commands/upgrade.md +0 -37
- package/3.api/5.kit/5.components.md +0 -146
- package/3.api/6.advanced/1.hooks.md +0 -105
- /package/{2.guide/1.directory-structure → 2.directory-structure}/.navigation.yml +0 -0
- /package/{2.guide/1.directory-structure → 2.directory-structure}/2.gitignore.md +0 -0
- /package/{2.guide → 3.guide}/.navigation.yml +0 -0
- /package/{2.guide/2.concepts → 3.guide/1.concepts}/.navigation.yml +0 -0
- /package/{2.guide/5.best-practices → 3.guide/2.best-practices}/.navigation.yml +0 -0
- /package/{2.guide/5.best-practices → 3.guide/2.best-practices}/plugins.md +0 -0
- /package/{2.guide/4.recipes → 3.guide/5.recipes}/.navigation.yml +0 -0
- /package/{2.guide/3.going-further → 3.guide/6.going-further}/.navigation.yml +0 -0
- /package/{2.guide/3.going-further → 3.guide/6.going-further}/index.md +0 -0
- /package/{3.api → 4.api}/.navigation.yml +0 -0
- /package/{3.api → 4.api}/1.components/.navigation.yml +0 -0
- /package/{3.api → 4.api}/1.components/1.client-only.md +0 -0
- /package/{3.api → 4.api}/1.components/1.dev-only.md +0 -0
- /package/{3.api → 4.api}/1.components/9.nuxt-img.md +0 -0
- /package/{3.api → 4.api}/2.composables/.navigation.yml +0 -0
- /package/{3.api → 4.api}/2.composables/on-prehydrate.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-hydration.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-loading-indicator.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-nuxt-data.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-preview-mode.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-request-event.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-request-fetch.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-request-header.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-request-headers.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-request-url.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-runtime-hook.md +0 -0
- /package/{3.api → 4.api}/3.utils/.navigation.yml +0 -0
- /package/{3.api → 4.api}/3.utils/clear-nuxt-data.md +0 -0
- /package/{3.api → 4.api}/3.utils/clear-nuxt-state.md +0 -0
- /package/{3.api → 4.api}/3.utils/on-nuxt-ready.md +0 -0
- /package/{3.api → 4.api}/3.utils/prefetch-components.md +0 -0
- /package/{3.api → 4.api}/3.utils/preload-components.md +0 -0
- /package/{3.api → 4.api}/3.utils/prerender-routes.md +0 -0
- /package/{3.api → 4.api}/4.commands/.navigation.yml +0 -0
- /package/{3.api → 4.api}/5.kit/.navigation.yml +0 -0
- /package/{3.api → 4.api}/5.kit/10.runtime-config.md +0 -0
- /package/{3.api → 4.api}/5.kit/13.logging.md +0 -0
- /package/{3.api → 4.api}/5.kit/15.examples.md +0 -0
- /package/{3.api → 4.api}/5.kit/7.pages.md +0 -0
- /package/{3.api → 4.api}/5.kit/9.head.md +0 -0
- /package/{3.api → 4.api}/5.kit/9.plugins.md +0 -0
- /package/{3.api → 4.api}/6.advanced/.navigation.yml +0 -0
- /package/{3.api → 4.api}/6.advanced/2.import-meta.md +0 -0
- /package/{3.api → 4.api}/6.nuxt-config.md +0 -0
|
@@ -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
|
::
|
|
@@ -58,7 +58,7 @@ export default defineEventHandler(() => 'Hello World!')
|
|
|
58
58
|
Given the example above, the `/hello` route will be accessible at <http://localhost:3000/hello>.
|
|
59
59
|
|
|
60
60
|
::note
|
|
61
|
-
Note that currently server routes do not support the full functionality of dynamic routes as [pages](/docs/3.x/
|
|
61
|
+
Note that currently server routes do not support the full functionality of dynamic routes as [pages](/docs/3.x/directory-structure/pages#dynamic-routes) do.
|
|
62
62
|
::
|
|
63
63
|
|
|
64
64
|
## Server Middleware
|
|
@@ -112,8 +112,6 @@ For example, you can define a custom handler utility that wraps the original han
|
|
|
112
112
|
**Example:**
|
|
113
113
|
|
|
114
114
|
```ts [server/utils/handler.ts]
|
|
115
|
-
import type { EventHandler, EventHandlerRequest } from 'h3'
|
|
116
|
-
|
|
117
115
|
export const defineWrappedResponseHandler = <T extends EventHandlerRequest, D> (
|
|
118
116
|
handler: EventHandler<T, D>,
|
|
119
117
|
): EventHandler<T, D> =>
|
|
@@ -130,6 +128,28 @@ export const defineWrappedResponseHandler = <T extends EventHandlerRequest, D> (
|
|
|
130
128
|
})
|
|
131
129
|
```
|
|
132
130
|
|
|
131
|
+
```ts [server/api/hello.get.ts]
|
|
132
|
+
export default defineWrappedResponseHandler(event => 'hello world')
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Server Alias
|
|
136
|
+
|
|
137
|
+
You can use the `#server` alias to import files from anywhere within the `server/` directory, regardless of the importing file's location.
|
|
138
|
+
|
|
139
|
+
```ts [server/api/users/[id]/profile.ts]
|
|
140
|
+
// Instead of relative paths like this:
|
|
141
|
+
// import { formatUser } from '../../../utils/formatUser'
|
|
142
|
+
|
|
143
|
+
// Use the #server alias:
|
|
144
|
+
import { formatUser } from '#server/utils/formatUser'
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
This alias ensures consistent imports across your server code, especially useful in deeply nested route handlers.
|
|
148
|
+
|
|
149
|
+
::note
|
|
150
|
+
The `#server` alias can only be used within the `server/` directory. Importing from `#server` in client code will result in an error.
|
|
151
|
+
::
|
|
152
|
+
|
|
133
153
|
## Server Types
|
|
134
154
|
|
|
135
155
|
::tip
|
|
@@ -168,7 +188,7 @@ You can now universally call this API on `/api/hello/nuxt` and get `Hello, nuxt!
|
|
|
168
188
|
|
|
169
189
|
### Matching HTTP Method
|
|
170
190
|
|
|
171
|
-
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).
|
|
191
|
+
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).
|
|
172
192
|
|
|
173
193
|
```ts [server/api/test.get.ts]
|
|
174
194
|
export default defineEventHandler(() => 'Test get handler')
|
|
@@ -236,7 +256,7 @@ export default defineEventHandler(async (event) => {
|
|
|
236
256
|
})
|
|
237
257
|
```
|
|
238
258
|
|
|
239
|
-
::tip{to="https://unjs.io/blog/2023-08-15-h3-towards-the-edge-of-the-web
|
|
259
|
+
::tip{to="https://unjs.io/blog/2023-08-15-h3-towards-the-edge-of-the-web/#runtime-type-safe-request-utils"}
|
|
240
260
|
Alternatively, use `readValidatedBody` with a schema validator such as Zod for runtime and type safety.
|
|
241
261
|
::
|
|
242
262
|
|
|
@@ -287,8 +307,8 @@ export default defineEventHandler((event) => {
|
|
|
287
307
|
|
|
288
308
|
if (!Number.isInteger(id)) {
|
|
289
309
|
throw createError({
|
|
290
|
-
|
|
291
|
-
|
|
310
|
+
status: 400,
|
|
311
|
+
statusText: 'ID should be an integer',
|
|
292
312
|
})
|
|
293
313
|
}
|
|
294
314
|
return 'All good'
|
|
@@ -402,7 +422,7 @@ export default defineNuxtConfig({
|
|
|
402
422
|
})
|
|
403
423
|
```
|
|
404
424
|
|
|
405
|
-
:read-more{to="/docs/guide/concepts/server-engine"}
|
|
425
|
+
:read-more{to="/docs/3.x/guide/concepts/server-engine"}
|
|
406
426
|
|
|
407
427
|
### Nested Router
|
|
408
428
|
|
|
@@ -464,7 +484,7 @@ Never combine `next()` callback with a legacy middleware that is `async` or retu
|
|
|
464
484
|
|
|
465
485
|
### Server Storage
|
|
466
486
|
|
|
467
|
-
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](#server-plugins).
|
|
487
|
+
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/3.x/directory-structure/server#server-plugins).
|
|
468
488
|
|
|
469
489
|
**Example of adding a Redis storage:**
|
|
470
490
|
|
|
@@ -41,7 +41,7 @@ export default function (input: string) {
|
|
|
41
41
|
}
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
You can now use [auto-imported](/docs/3.x/
|
|
44
|
+
You can now use [auto-imported](/docs/3.x/directory-structure/shared) utilities in your Nuxt app and `server/` directory.
|
|
45
45
|
|
|
46
46
|
```vue [app.vue]
|
|
47
47
|
<script setup lang="ts">
|
|
@@ -68,10 +68,10 @@ export default defineEventHandler((event) => {
|
|
|
68
68
|
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`.
|
|
69
69
|
|
|
70
70
|
::tip
|
|
71
|
-
The way `shared/utils` and `shared/types` auto-imports work and are scanned is identical to the [`composables/`](/docs/3.x/
|
|
71
|
+
The way `shared/utils` and `shared/types` auto-imports work and are scanned is identical to the [`composables/`](/docs/3.x/directory-structure/composables) and [`utils/`](/docs/3.x/directory-structure/utils) directories.
|
|
72
72
|
::
|
|
73
73
|
|
|
74
|
-
:read-more{to="/docs/
|
|
74
|
+
:read-more{to="/docs/3.x/directory-structure/composables#how-files-are-scanned"}
|
|
75
75
|
|
|
76
76
|
```bash [Directory Structure]
|
|
77
77
|
-| shared/
|
|
@@ -101,4 +101,4 @@ import upper from '#shared/utils/formatters/upper'
|
|
|
101
101
|
|
|
102
102
|
This alias ensures consistent imports across your application, regardless of the importing file's location.
|
|
103
103
|
|
|
104
|
-
:read-more{to="/docs/guide/concepts/auto-imports"}
|
|
104
|
+
:read-more{to="/docs/3.x/guide/concepts/auto-imports"}
|
|
@@ -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 [`utils/` directory](/docs/3.x/
|
|
8
|
+
The main purpose of the [`utils/` directory](/docs/3.x/directory-structure/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,15 @@ 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/guide/concepts/auto-imports"}
|
|
38
|
+
:read-more{to="/docs/3.x/guide/concepts/auto-imports"}
|
|
39
39
|
|
|
40
|
-
:link-example{to="/docs/examples/features/auto-imports"}
|
|
40
|
+
:link-example{to="/docs/3.x/examples/features/auto-imports"}
|
|
41
41
|
|
|
42
42
|
::tip
|
|
43
|
-
The way `utils/` auto-imports work and are scanned is identical to the [`composables/`](/docs/3.x/
|
|
43
|
+
The way `utils/` auto-imports work and are scanned is identical to the [`composables/`](/docs/3.x/directory-structure/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/3.x/
|
|
48
|
+
Only `server/utils` are auto-imported in the [`server/`](/docs/3.x/directory-structure/server#server-utilities) directory.
|
|
49
49
|
::
|
|
@@ -6,7 +6,7 @@ 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/3.x/
|
|
9
|
+
This file should be added to your [`.gitignore`](/docs/3.x/directory-structure/gitignore) file to avoid pushing secrets to your repository.
|
|
10
10
|
::
|
|
11
11
|
|
|
12
12
|
## Dev, Build and Generate Time
|
|
@@ -56,7 +56,7 @@ 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] (https://nuxt.com/docs/guide/going-further/runtime-config#environment-variables).
|
|
59
|
+
`runtimeConfig` [won't pick up environment variables that don't start with `NUXT_` in production] (https://nuxt.com/docs/3.x/guide/going-further/runtime-config#environment-variables).
|
|
60
60
|
::
|
|
61
61
|
|
|
62
62
|
## Production Preview
|
|
@@ -71,9 +71,9 @@ DATABASE_HOST=mydatabaseconnectionstring node .output/server/index.mjs
|
|
|
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/guide/going-further/runtime-config"}
|
|
74
|
+
:read-more{to="/docs/3.x/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/3.x/directory-structure/app-config"}
|
|
79
79
|
::
|
|
@@ -3,11 +3,12 @@ title: .nuxtignore
|
|
|
3
3
|
head.title: '.nuxtignore'
|
|
4
4
|
description: The .nuxtignore file lets Nuxt ignore files in your project’s root directory during the build phase.
|
|
5
5
|
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/3.x/api/nuxt-config#rootdir)) during the build phase.
|
|
9
10
|
|
|
10
|
-
It is subject to the same specification as [`.gitignore`](/docs/3.x/
|
|
11
|
+
It is subject to the same specification as [`.gitignore`](/docs/3.x/directory-structure/gitignore) and `.eslintignore` files, in which each line is a glob pattern indicating which files should be ignored.
|
|
11
12
|
|
|
12
13
|
::tip
|
|
13
14
|
You can also configure [`ignoreOptions`](/docs/3.x/api/nuxt-config#ignoreoptions), [`ignorePrefix`](/docs/3.x/api/nuxt-config#ignoreprefix) and [`ignore`](/docs/3.x/api/nuxt-config#ignore) in your `nuxt.config` file.
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
title: ".nuxtrc"
|
|
3
3
|
description: "The .nuxtrc file allows you to define nuxt configurations in a flat syntax."
|
|
4
4
|
head.title: ".nuxtrc"
|
|
5
|
-
navigation.icon: i-vscode-icons-file-type-nuxt
|
|
5
|
+
navigation.icon: i-vscode-icons-file-type-nuxt
|
|
6
6
|
---
|
|
7
7
|
|
|
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/3.x/
|
|
11
|
+
For more advanced configurations, use [`nuxt.config`](/docs/3.x/directory-structure/nuxt-config).
|
|
12
12
|
::
|
|
13
13
|
|
|
14
14
|
## Usage
|
|
@@ -23,6 +23,9 @@ devtools.enabled=true
|
|
|
23
23
|
# Add Nuxt modules
|
|
24
24
|
modules[]=@nuxt/image
|
|
25
25
|
modules[]=nuxt-security
|
|
26
|
+
|
|
27
|
+
# Module setups (automatically added by Nuxt)
|
|
28
|
+
setups.@nuxt/test-utils="3.23.0"
|
|
26
29
|
```
|
|
27
30
|
|
|
28
31
|
If present, the properties in the `nuxt.config` file will overwrite the properties in `.nuxtrc` file.
|
|
@@ -31,7 +34,7 @@ If present, the properties in the `nuxt.config` file will overwrite the properti
|
|
|
31
34
|
Nuxt automatically adds a `setups` section to track module installation and upgrade state. This is used internally for [module lifecycle hooks](/docs/3.x/api/kit/modules#using-lifecycle-hooks-for-module-installation-and-upgrade) and should not be modified manually.
|
|
32
35
|
::
|
|
33
36
|
|
|
34
|
-
::read-more{to="/docs/api/configuration/nuxt-config"}
|
|
37
|
+
::read-more{to="/docs/3.x/api/configuration/nuxt-config"}
|
|
35
38
|
Discover all the available options in the **Nuxt configuration** documentation.
|
|
36
39
|
::
|
|
37
40
|
|
|
@@ -5,7 +5,7 @@ description: Expose reactive configuration within your application with the App
|
|
|
5
5
|
navigation.icon: i-vscode-icons-file-type-light-config
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
Nuxt provides an `app.config` config file to expose reactive configuration within your application with the ability to update it at runtime within lifecycle or using a nuxt plugin and editing it with HMR (hot-module-replacement).
|
|
8
|
+
Nuxt provides an `app.config.ts` config file to expose reactive configuration within your application with the ability to update it at runtime within lifecycle or using a nuxt plugin and editing it with HMR (hot-module-replacement).
|
|
9
9
|
|
|
10
10
|
You can easily provide runtime app configuration using `app.config.ts` file. It can have either of `.ts`, `.js`, or `.mjs` extensions.
|
|
11
11
|
|
|
@@ -59,7 +59,7 @@ console.log(appConfig) // { foo: 'baz' }
|
|
|
59
59
|
</script>
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
::read-more{to="/docs/api/utils/update-app-config"}
|
|
62
|
+
::read-more{to="/docs/3.x/api/utils/update-app-config"}
|
|
63
63
|
Read more about the `updateAppConfig` utility.
|
|
64
64
|
::
|
|
65
65
|
|
|
@@ -13,7 +13,7 @@ If you have a `pages/` directory, the `app.vue` file is optional. Nuxt will auto
|
|
|
13
13
|
|
|
14
14
|
### Minimal Usage
|
|
15
15
|
|
|
16
|
-
With Nuxt, the [`pages/`](/docs/3.x/
|
|
16
|
+
With Nuxt, the [`pages/`](/docs/3.x/directory-structure/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.vue]
|
|
19
19
|
<template>
|
|
@@ -21,11 +21,11 @@ With Nuxt, the [`pages/`](/docs/3.x/guide/directory-structure/pages) directory i
|
|
|
21
21
|
</template>
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
:link-example{to="/docs/examples/hello-world"}
|
|
24
|
+
:link-example{to="/docs/3.x/examples/hello-world"}
|
|
25
25
|
|
|
26
26
|
### Usage with Pages
|
|
27
27
|
|
|
28
|
-
When you have a [`pages/`](/docs/3.x/
|
|
28
|
+
When you have a [`pages/`](/docs/3.x/directory-structure/pages) directory, you need to use the [`<NuxtPage>`](/docs/3.x/api/components/nuxt-page) component to display the current page:
|
|
29
29
|
|
|
30
30
|
```vue [app.vue]
|
|
31
31
|
<template>
|
|
@@ -51,7 +51,7 @@ 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/3.x/directory-structure/pages"}
|
|
55
55
|
Learn more about how to structure your pages using the `pages/` directory.
|
|
56
56
|
::
|
|
57
57
|
|
|
@@ -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/3.x/directory-structure/layouts"}
|
|
71
71
|
Learn more about how to structure your layouts using the `layouts/` directory.
|
|
72
72
|
::
|
|
@@ -11,14 +11,12 @@ During the lifespan of your application, some errors may appear unexpectedly at
|
|
|
11
11
|
<script setup lang="ts">
|
|
12
12
|
import type { NuxtError } from '#app'
|
|
13
13
|
|
|
14
|
-
const props = defineProps(
|
|
15
|
-
error: Object as () => NuxtError,
|
|
16
|
-
})
|
|
14
|
+
const props = defineProps<{ error: NuxtError }>()
|
|
17
15
|
</script>
|
|
18
16
|
|
|
19
17
|
<template>
|
|
20
18
|
<div>
|
|
21
|
-
<h1>{{ error.
|
|
19
|
+
<h1>{{ error.status }}</h1>
|
|
22
20
|
<NuxtLink to="/">Go back home</NuxtLink>
|
|
23
21
|
</div>
|
|
24
22
|
</template>
|
|
@@ -33,12 +31,16 @@ The error page has a single prop - `error` which contains an error for you to ha
|
|
|
33
31
|
The `error` object provides the following fields:
|
|
34
32
|
```ts
|
|
35
33
|
interface NuxtError {
|
|
36
|
-
|
|
34
|
+
status: number
|
|
37
35
|
fatal: boolean
|
|
38
36
|
unhandled: boolean
|
|
39
|
-
|
|
37
|
+
statusText?: string
|
|
40
38
|
data?: unknown
|
|
41
39
|
cause?: unknown
|
|
40
|
+
// legacy/deprecated equivalent of `status`
|
|
41
|
+
statusCode: number
|
|
42
|
+
// legacy/deprecated equivalent of `statusText`
|
|
43
|
+
statusMessage?: string
|
|
42
44
|
}
|
|
43
45
|
```
|
|
44
46
|
|
|
@@ -46,8 +48,8 @@ If you have an error with custom fields they will be lost; you should assign the
|
|
|
46
48
|
|
|
47
49
|
```ts
|
|
48
50
|
throw createError({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
status: 404,
|
|
52
|
+
statusText: 'Page Not Found',
|
|
51
53
|
data: {
|
|
52
54
|
myCustomField: true,
|
|
53
55
|
},
|
|
@@ -27,8 +27,8 @@ export default defineNuxtConfig({
|
|
|
27
27
|
})
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
::read-more{to="/docs/api/configuration/nuxt-config"}
|
|
30
|
+
::read-more{to="/docs/3.x/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/3.x/
|
|
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/3.x/directory-structure/env), [`.nuxtignore`](/docs/3.x/directory-structure/nuxtignore) and [`.nuxtrc`](/docs/3.x/directory-structure/nuxtrc) dotfiles.
|
|
@@ -27,6 +27,6 @@ The minimal `package.json` of your Nuxt application should looks like:
|
|
|
27
27
|
}
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
::read-more{icon="i-simple-icons-npm" to="https://docs.npmjs.com/cli/configuring-npm/package-json" target="_blank"}
|
|
30
|
+
::read-more{icon="i-simple-icons-npm" to="https://docs.npmjs.com/cli/configuring-npm/package-json/" target="_blank"}
|
|
31
31
|
Read more about the `package.json` file.
|
|
32
32
|
::
|
|
@@ -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
8
|
Nuxt [automatically generates](/docs/3.x/guide/concepts/typescript) a `.nuxt/tsconfig.json` file with the resolved aliases you are using in your Nuxt project, as well as with other sensible defaults.
|
|
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
|
{
|
|
@@ -28,6 +28,7 @@ If you need to customize your `paths`, this will override the auto-generated pat
|
|
|
28
28
|
You can customize the TypeScript configuration of your Nuxt project for each context (`app` and `server`) in the `nuxt.config.ts` file.
|
|
29
29
|
<!-- @case-police-ignore tsConfig -->
|
|
30
30
|
```ts twoslash [nuxt.config.ts]
|
|
31
|
+
// @errors: 2353
|
|
31
32
|
export default defineNuxtConfig({
|
|
32
33
|
typescript: {
|
|
33
34
|
// customize tsconfig.app.json
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'Nuxt Directory Structure'
|
|
3
|
+
description: 'Learn about the directory structure of a Nuxt application and how to use it.'
|
|
4
|
+
navigation: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Nuxt applications have a specific directory structure that is used to organize the code. This structure is designed to be easy to understand and to be used in a consistent way.
|
|
8
|
+
|
|
9
|
+
## Root Directory
|
|
10
|
+
|
|
11
|
+
The root directory of a Nuxt application is the directory that contains the `nuxt.config.ts` file. This file is used to configure the Nuxt application.
|
|
12
|
+
|
|
13
|
+
## App Directory
|
|
14
|
+
|
|
15
|
+
The following directories are related to the universal Nuxt application:
|
|
16
|
+
- [`assets/`](/docs/3.x/directory-structure/assets): website's assets that the build tool (Vite or webpack) will process
|
|
17
|
+
- [`components/`](/docs/3.x/directory-structure/components): Vue components of the application
|
|
18
|
+
- [`composables/`](/docs/3.x/directory-structure/composables): add your Vue composables
|
|
19
|
+
- [`layouts/`](/docs/3.x/directory-structure/layouts): Vue components that wrap around your pages and avoid re-rendering between pages
|
|
20
|
+
- [`middleware/`](/docs/3.x/directory-structure/middleware): run code before navigating to a particular route
|
|
21
|
+
- [`pages/`](/docs/3.x/directory-structure/pages): file-based routing to create routes within your web application
|
|
22
|
+
- [`plugins/`](/docs/3.x/directory-structure/plugins): use Vue plugins and more at the creation of your Nuxt application
|
|
23
|
+
- [`utils/`](/docs/3.x/directory-structure/utils): add functions throughout your application that can be used in your components, composables, and pages.
|
|
24
|
+
|
|
25
|
+
This directory also includes specific files:
|
|
26
|
+
- [`app.config.ts`](/docs/3.x/directory-structure/app-config): a reactive configuration within your application
|
|
27
|
+
- [`app.vue`](/docs/3.x/directory-structure/app): the root component of your Nuxt application
|
|
28
|
+
- [`error.vue`](/docs/3.x/directory-structure/error): the error page of your Nuxt application
|
|
29
|
+
|
|
30
|
+
## Public Directory
|
|
31
|
+
|
|
32
|
+
The [`public/`](/docs/3.x/directory-structure/public) directory is the directory that contains the public files of the Nuxt application. Files contained within this directory are served at the root and are not modified by the build process.
|
|
33
|
+
|
|
34
|
+
This is suitable for files that have to keep their names (e.g. `robots.txt`) _or_ likely won't change (e.g. `favicon.ico`).
|
|
35
|
+
|
|
36
|
+
## Server Directory
|
|
37
|
+
|
|
38
|
+
The [`server/`](/docs/3.x/directory-structure/server) directory is the directory that contains the server-side code of the Nuxt application. It contains the following subdirectories:
|
|
39
|
+
- [`api/`](/docs/3.x/directory-structure/server#server-routes): contains the API routes of the application.
|
|
40
|
+
- [`routes/`](/docs/3.x/directory-structure/server#server-routes): contains the server routes of the application (e.g. dynamic `/sitemap.xml`).
|
|
41
|
+
- [`middleware/`](/docs/3.x/directory-structure/server#server-middleware): run code before a server route is processed
|
|
42
|
+
- [`plugins/`](/docs/3.x/directory-structure/server#server-plugins): use plugins and more at the creation of the Nuxt server
|
|
43
|
+
- [`utils/`](/docs/3.x/directory-structure/server#server-utilities): add functions throughout your application that can be used in your server code.
|
|
44
|
+
|
|
45
|
+
## Shared Directory
|
|
46
|
+
|
|
47
|
+
The [`shared/`](/docs/3.x/directory-structure/shared) directory is the directory that contains the shared code of the Nuxt application and Nuxt server. This code can be used in both the Vue app and the Nitro server.
|
|
48
|
+
|
|
49
|
+
## Content Directory
|
|
50
|
+
|
|
51
|
+
The [`content/`](/docs/3.x/directory-structure/content) directory is enabled by the [Nuxt Content](https://content.nuxt.com) module. It is used to create a file-based CMS for your application using Markdown files.
|
|
52
|
+
|
|
53
|
+
## Modules Directory
|
|
54
|
+
|
|
55
|
+
The [`modules/`](/docs/3.x/directory-structure/modules) directory is the directory that contains the local modules of the Nuxt application. Modules are used to extend the functionality of the Nuxt application.
|
|
56
|
+
|
|
57
|
+
## Layers Directory
|
|
58
|
+
|
|
59
|
+
The [`layers/`](/docs/3.x/directory-structure/layers) directory allows you to organize and share reusable code, components, composables, and configurations. Layers within this directory are automatically registered in your project.
|
|
60
|
+
|
|
61
|
+
## Nuxt Files
|
|
62
|
+
|
|
63
|
+
- [`nuxt.config.ts`](/docs/3.x/directory-structure/nuxt-config) file is the main configuration file for the Nuxt application.
|
|
64
|
+
- [`.nuxtrc`](/docs/3.x/directory-structure/nuxtrc) file is another syntax for configuring the Nuxt application (useful for global configurations).
|
|
65
|
+
- [`.nuxtignore`](/docs/3.x/directory-structure/nuxtignore) file is used to ignore files in the root directory during the build phase.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'Nuxt Guide'
|
|
3
|
+
titleTemplate: '%s'
|
|
4
|
+
description: 'Learn how Nuxt works with in-depth guides.'
|
|
5
|
+
navigation: false
|
|
6
|
+
surround: false
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
::card-group{class="sm:grid-cols-1"}
|
|
10
|
+
::card{icon="i-lucide-medal" title="Key Concepts" to="/docs/3.x/guide/concepts"}
|
|
11
|
+
Discover the main concepts behind Nuxt, from auto-import, hybrid rendering to its TypeScript support.
|
|
12
|
+
::
|
|
13
|
+
::card{icon="i-lucide-square-check" title="Best Practices" to="/docs/3.x/guide/best-practices"}
|
|
14
|
+
Learn about best practices when developing with Nuxt.
|
|
15
|
+
::
|
|
16
|
+
::card{icon="i-lucide-bot" title="Working with AI" to="/docs/4.x/guide/ai"}
|
|
17
|
+
Integrate AI tools into your Nuxt workflow with MCP Server and LLMs.txt.
|
|
18
|
+
::
|
|
19
|
+
::card{icon="i-lucide-box" title="Module Author Guide" to="/docs/3.x/guide/modules"}
|
|
20
|
+
Learn how to create Nuxt modules to integrate, enhance or extend any Nuxt application.
|
|
21
|
+
::
|
|
22
|
+
::card{icon="i-lucide-book-open" title="Recipes" to="/docs/3.x/guide/recipes"}
|
|
23
|
+
Find solutions to common problems and learn how to implement them in your Nuxt project.
|
|
24
|
+
::
|
|
25
|
+
::card{icon="i-lucide-star" title="Going Further" to="/docs/3.x/guide/going-further"}
|
|
26
|
+
Master Nuxt with advanced concepts like experimental features, hooks, and more.
|
|
27
|
+
::
|
|
28
|
+
::
|
|
@@ -3,7 +3,7 @@ title: 'Rendering Modes'
|
|
|
3
3
|
description: 'Learn about the different rendering modes available in Nuxt.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
Nuxt supports different rendering modes, [universal rendering](#universal-rendering), [client-side rendering](#client-side-rendering) but also offers [hybrid-rendering](#hybrid-rendering) and the possibility to render your application on [CDN Edge Servers](#edge-side-rendering).
|
|
6
|
+
Nuxt supports different rendering modes, [universal rendering](/docs/3.x/guide/concepts/rendering#universal-rendering), [client-side rendering](/docs/3.x/guide/concepts/rendering#client-side-rendering) but also offers [hybrid-rendering](/docs/3.x/guide/concepts/rendering#hybrid-rendering) and the possibility to render your application on [CDN Edge Servers](/docs/3.x/guide/concepts/rendering#edge-side-rendering).
|
|
7
7
|
|
|
8
8
|
Both the browser and server can interpret JavaScript code to turn Vue.js components into HTML elements. This step is called **rendering**. Nuxt supports both **universal** and **client-side** rendering. The two approaches have benefits and downsides that we will cover.
|
|
9
9
|
|
|
@@ -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/3.x/
|
|
47
|
+
[Middlewares](/docs/3.x/directory-structure/middleware) and [pages](/docs/3.x/directory-structure/pages) run in the server and on the client during hydration. [Plugins](/docs/3.x/directory-structure/plugins) can be rendered on the server or client or both. [Components](/docs/3.x/directory-structure/components) can be forced to run on the client only as well. [Composables](/docs/3.x/directory-structure/composables) and [utilities](/docs/3.x/directory-structure/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.
|
|
@@ -52,12 +52,12 @@ On the initial request, the `counter` ref is initialized in the server since it
|
|
|
52
52
|
|
|
53
53
|
**Downsides of server-side rendering:**
|
|
54
54
|
- **Development constraints:** Server and browser environments don't provide the same APIs, and it can be tricky to write code that can run on both sides seamlessly. Fortunately, Nuxt provides guidelines and specific variables to help you determine where a piece of code is executed.
|
|
55
|
-
- **Cost:** A server needs to be running in order to render pages on the fly. This adds a monthly cost like any traditional server. However, the server calls are highly reduced thanks to universal rendering with the browser taking over on client-side navigation. A cost reduction is possible by leveraging [edge-side-rendering](#edge-side-rendering).
|
|
55
|
+
- **Cost:** A server needs to be running in order to render pages on the fly. This adds a monthly cost like any traditional server. However, the server calls are highly reduced thanks to universal rendering with the browser taking over on client-side navigation. A cost reduction is possible by leveraging [edge-side-rendering](/docs/3.x/guide/concepts/rendering#edge-side-rendering).
|
|
56
56
|
|
|
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
|
|
@@ -91,7 +91,7 @@ export default defineNuxtConfig({
|
|
|
91
91
|
|
|
92
92
|
::note
|
|
93
93
|
If you do use `ssr: false`, you should also place an HTML file in `~/app/spa-loading-template.html` with some HTML you would like to use to render a loading screen that will be rendered until your app is hydrated.
|
|
94
|
-
:read-more{title="SPA Loading Template" to="/docs/api/configuration/nuxt-config#spaloadingtemplate"}
|
|
94
|
+
:read-more{title="SPA Loading Template" to="/docs/3.x/api/configuration/nuxt-config#spaloadingtemplate"}
|
|
95
95
|
::
|
|
96
96
|
|
|
97
97
|
:video-accordion{title="Watch a video from Alexander Lichter about Building a plain SPA with Nuxt" videoId="7Lr0QTP1Ro8"}
|
|
@@ -131,6 +131,7 @@ The `200.html` and `404.html` might be useful for the hosting provider you are u
|
|
|
131
131
|
When prerendering a client-rendered app, Nuxt will generate `index.html`, `200.html` and `404.html` files by default. However, if you need to prevent any (or all) of these files from being generated in your build, you can use the `'prerender:generate'` hook from [Nitro](/docs/3.x/getting-started/prerendering#prerendergenerate-nitro-hook).
|
|
132
132
|
|
|
133
133
|
```ts twoslash [nuxt.config.ts]
|
|
134
|
+
// @errors: 2353 7006
|
|
134
135
|
export default defineNuxtConfig({
|
|
135
136
|
ssr: false,
|
|
136
137
|
nitro: {
|
|
@@ -225,33 +226,7 @@ Edge-side rendering is possible thanks to [Nitro](https://nitro.build/), the [se
|
|
|
225
226
|
|
|
226
227
|
The current platforms where you can leverage ESR are:
|
|
227
228
|
- [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/
|
|
229
|
+
- [Vercel Cloud](https://vercel.com/home) using the `nuxt build` command and `NITRO_PRESET=vercel-edge` environment variable
|
|
230
|
+
- [Netlify Edge Functions](https://www.netlify.com/platform/#netlify-edge-functions) using the `nuxt build` command and `NITRO_PRESET=netlify-edge` environment variable
|
|
230
231
|
|
|
231
232
|
Note that **Hybrid Rendering** can be used when using Edge-Side Rendering with route rules.
|
|
232
|
-
|
|
233
|
-
You can explore open source examples deployed on some of the platform mentioned above:
|
|
234
|
-
::card-group
|
|
235
|
-
::card
|
|
236
|
-
---
|
|
237
|
-
icon: i-simple-icons-github
|
|
238
|
-
title: Nuxt Todos Edge
|
|
239
|
-
to: https://github.com/atinux/nuxt-todos-edge
|
|
240
|
-
target: _blank
|
|
241
|
-
ui.icon.base: text-black dark:text-white
|
|
242
|
-
---
|
|
243
|
-
A todos application with user authentication, SSR and SQLite.
|
|
244
|
-
::
|
|
245
|
-
::card
|
|
246
|
-
---
|
|
247
|
-
icon: i-simple-icons-github
|
|
248
|
-
title: Atinotes
|
|
249
|
-
to: https://github.com/atinux/atinotes
|
|
250
|
-
target: _blank
|
|
251
|
-
ui.icon.base: text-black dark:text-white
|
|
252
|
-
---
|
|
253
|
-
An editable website with universal rendering based on Cloudflare KV.
|
|
254
|
-
::
|
|
255
|
-
::
|
|
256
|
-
|
|
257
|
-
<!-- TODO: link to templates with ESR category for examples -->
|