@nuxt/docs 4.1.2 → 4.2.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 +6 -6
- package/1.getting-started/02.installation.md +3 -2
- package/1.getting-started/03.configuration.md +36 -36
- package/1.getting-started/04.views.md +9 -9
- package/1.getting-started/05.assets.md +15 -9
- package/1.getting-started/06.styling.md +58 -48
- package/1.getting-started/07.routing.md +17 -17
- package/1.getting-started/08.seo-meta.md +59 -46
- package/1.getting-started/09.transitions.md +49 -44
- package/1.getting-started/10.data-fetching.md +104 -81
- package/1.getting-started/11.state-management.md +26 -19
- package/1.getting-started/12.error-handling.md +22 -20
- package/1.getting-started/13.server.md +8 -8
- package/1.getting-started/14.layers.md +22 -16
- package/1.getting-started/15.prerendering.md +32 -32
- package/1.getting-started/16.deployment.md +10 -10
- package/1.getting-started/17.testing.md +44 -44
- package/1.getting-started/18.upgrade.md +241 -110
- package/2.guide/0.index.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/.navigation.yml +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/0.nuxt.md +3 -3
- package/2.guide/1.directory-structure/0.output.md +18 -0
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/.navigation.yml +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.assets.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.components.md +45 -28
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.composables.md +13 -13
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.layouts.md +19 -15
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.middleware.md +31 -25
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.pages.md +39 -37
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.plugins.md +25 -25
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.utils.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app-config.md +18 -18
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.error.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.content.md +7 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.modules.md +8 -8
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.node_modules.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.public.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.server.md +35 -35
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.shared.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.env.md +8 -8
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.gitignore.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtignore.md +5 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtrc.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.nuxt-config.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.package.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.tsconfig.md +3 -3
- package/2.guide/{1.concepts → 2.concepts}/1.auto-imports.md +22 -22
- package/2.guide/{1.concepts → 2.concepts}/10.nuxt-lifecycle.md +17 -17
- package/2.guide/{1.concepts → 2.concepts}/2.vuejs-development.md +13 -13
- package/2.guide/{1.concepts → 2.concepts}/3.rendering.md +24 -22
- package/2.guide/{1.concepts → 2.concepts}/4.server-engine.md +6 -6
- package/2.guide/{1.concepts → 2.concepts}/5.modules.md +5 -5
- package/2.guide/{1.concepts → 2.concepts}/7.esm.md +22 -16
- package/2.guide/{1.concepts → 2.concepts}/8.typescript.md +12 -12
- package/2.guide/3.going-further/1.events.md +3 -3
- package/2.guide/3.going-further/1.experimental-features.md +334 -85
- package/2.guide/3.going-further/1.features.md +58 -11
- package/2.guide/3.going-further/1.internals.md +25 -25
- package/2.guide/3.going-further/10.runtime-config.md +12 -12
- package/2.guide/3.going-further/11.nightly-release-channel.md +1 -1
- package/2.guide/3.going-further/2.hooks.md +14 -14
- package/2.guide/3.going-further/3.modules.md +126 -108
- package/2.guide/3.going-further/4.kit.md +7 -7
- package/2.guide/3.going-further/6.nuxt-app.md +8 -8
- package/2.guide/3.going-further/7.layers.md +76 -59
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +30 -30
- package/2.guide/4.recipes/2.vite-plugin.md +45 -4
- package/2.guide/4.recipes/3.custom-usefetch.md +13 -13
- package/2.guide/4.recipes/4.sessions-and-authentication.md +35 -21
- package/2.guide/5.best-practices/hydration.md +4 -4
- package/2.guide/5.best-practices/performance.md +17 -17
- package/3.api/1.components/1.client-only.md +6 -3
- package/3.api/1.components/1.nuxt-client-fallback.md +10 -7
- package/3.api/1.components/10.nuxt-picture.md +1 -1
- package/3.api/1.components/11.teleports.md +5 -2
- package/3.api/1.components/12.nuxt-route-announcer.md +9 -9
- package/3.api/1.components/13.nuxt-time.md +49 -18
- package/3.api/1.components/2.nuxt-page.md +6 -6
- package/3.api/1.components/3.nuxt-layout.md +15 -10
- package/3.api/1.components/4.nuxt-link.md +42 -22
- package/3.api/1.components/5.nuxt-loading-indicator.md +3 -3
- package/3.api/1.components/6.nuxt-error-boundary.md +12 -10
- package/3.api/2.composables/on-prehydrate.md +2 -2
- package/3.api/2.composables/use-app-config.md +1 -1
- package/3.api/2.composables/use-async-data.md +26 -22
- package/3.api/2.composables/use-cookie.md +29 -21
- package/3.api/2.composables/use-error.md +2 -2
- package/3.api/2.composables/use-fetch.md +62 -32
- package/3.api/2.composables/use-head-safe.md +7 -7
- package/3.api/2.composables/use-head.md +5 -5
- package/3.api/2.composables/use-hydration.md +6 -6
- package/3.api/2.composables/use-lazy-async-data.md +4 -4
- package/3.api/2.composables/use-lazy-fetch.md +4 -4
- package/3.api/2.composables/use-loading-indicator.md +12 -12
- package/3.api/2.composables/use-nuxt-app.md +22 -22
- package/3.api/2.composables/use-nuxt-data.md +8 -8
- package/3.api/2.composables/use-preview-mode.md +15 -18
- package/3.api/2.composables/use-request-event.md +1 -1
- package/3.api/2.composables/use-request-fetch.md +3 -3
- package/3.api/2.composables/use-request-header.md +1 -1
- package/3.api/2.composables/use-request-headers.md +4 -4
- package/3.api/2.composables/use-request-url.md +1 -1
- package/3.api/2.composables/use-response-header.md +9 -10
- package/3.api/2.composables/use-route-announcer.md +4 -4
- package/3.api/2.composables/use-route.md +1 -1
- package/3.api/2.composables/use-router.md +10 -8
- package/3.api/2.composables/use-runtime-config.md +11 -11
- package/3.api/2.composables/use-runtime-hook.md +2 -2
- package/3.api/2.composables/use-seo-meta.md +4 -4
- package/3.api/2.composables/use-server-seo-meta.md +6 -6
- package/3.api/2.composables/use-state.md +5 -5
- package/3.api/3.utils/$fetch.md +10 -8
- package/3.api/3.utils/abort-navigation.md +3 -3
- package/3.api/3.utils/add-route-middleware.md +5 -5
- package/3.api/3.utils/call-once.md +6 -6
- package/3.api/3.utils/clear-error.md +3 -3
- package/3.api/3.utils/clear-nuxt-data.md +3 -3
- package/3.api/3.utils/clear-nuxt-state.md +3 -3
- package/3.api/3.utils/create-error.md +2 -2
- package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
- package/3.api/3.utils/define-nuxt-component.md +5 -5
- package/3.api/3.utils/define-nuxt-plugin.md +13 -13
- package/3.api/3.utils/define-nuxt-route-middleware.md +5 -5
- package/3.api/3.utils/define-page-meta.md +23 -23
- package/3.api/3.utils/define-route-rules.md +7 -7
- package/3.api/3.utils/navigate-to.md +11 -11
- package/3.api/3.utils/prefetch-components.md +1 -1
- package/3.api/3.utils/preload-components.md +1 -1
- package/3.api/3.utils/preload-route-components.md +2 -2
- package/3.api/3.utils/prerender-routes.md +3 -3
- package/3.api/3.utils/refresh-cookie.md +4 -4
- package/3.api/3.utils/refresh-nuxt-data.md +12 -7
- package/3.api/3.utils/reload-nuxt-app.md +3 -3
- package/3.api/3.utils/set-page-layout.md +1 -1
- package/3.api/3.utils/set-response-status.md +3 -3
- package/3.api/3.utils/show-error.md +5 -5
- package/3.api/3.utils/update-app-config.md +4 -3
- package/3.api/4.commands/add.md +1 -1
- package/3.api/4.commands/analyze.md +2 -1
- package/3.api/4.commands/build.md +2 -1
- package/3.api/4.commands/dev.md +5 -4
- package/3.api/4.commands/generate.md +3 -2
- package/3.api/4.commands/init.md +3 -2
- package/3.api/4.commands/module.md +4 -4
- package/3.api/4.commands/prepare.md +7 -2
- package/3.api/4.commands/preview.md +5 -4
- package/3.api/4.commands/test.md +40 -0
- package/3.api/4.commands/typecheck.md +5 -3
- package/3.api/4.commands/upgrade.md +3 -3
- package/3.api/5.kit/1.modules.md +123 -37
- package/3.api/5.kit/10.runtime-config.md +1 -1
- package/3.api/5.kit/10.templates.md +8 -6
- package/3.api/5.kit/11.nitro.md +66 -62
- package/3.api/5.kit/12.resolving.md +2 -2
- package/3.api/5.kit/14.builder.md +61 -4
- package/3.api/5.kit/15.examples.md +5 -7
- package/3.api/5.kit/16.layers.md +26 -26
- package/3.api/5.kit/3.compatibility.md +14 -14
- package/3.api/5.kit/4.autoimports.md +13 -13
- package/3.api/5.kit/5.components.md +8 -7
- package/3.api/5.kit/6.context.md +3 -3
- package/3.api/5.kit/7.pages.md +7 -7
- package/3.api/5.kit/8.layout.md +2 -2
- package/3.api/5.kit/9.head.md +132 -0
- package/3.api/5.kit/9.plugins.md +5 -4
- package/3.api/6.advanced/1.hooks.md +5 -5
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/3.api/6.nuxt-config.md +365 -859
- package/3.api/index.md +7 -7
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +3 -3
- package/5.community/4.contribution.md +11 -11
- package/5.community/5.framework-contribution.md +4 -4
- package/5.community/6.roadmap.md +2 -2
- package/6.bridge/1.overview.md +13 -13
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +3 -3
- package/6.bridge/3.bridge-composition-api.md +8 -8
- package/6.bridge/4.plugins-and-middleware.md +9 -9
- package/6.bridge/5.nuxt3-compatible-api.md +20 -17
- package/6.bridge/6.meta.md +20 -19
- package/6.bridge/7.runtime-config.md +1 -1
- package/6.bridge/8.nitro.md +3 -3
- package/6.bridge/9.vite.md +4 -4
- 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 +23 -21
- package/7.migration/20.module-authors.md +7 -7
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +21 -18
- package/7.migration/5.plugins-and-middleware.md +8 -8
- package/7.migration/6.pages-and-layouts.md +28 -24
- package/7.migration/7.component-options.md +18 -18
- package/7.migration/8.runtime-config.md +7 -7
- package/package.json +1 -1
- package/2.guide/2.directory-structure/0.output.md +0 -18
- /package/2.guide/{1.concepts → 2.concepts}/.navigation.yml +0 -0
- /package/2.guide/{1.concepts → 2.concepts}/9.code-style.md +0 -0
|
@@ -11,25 +11,25 @@ const count = ref(1) // ref is auto-imported
|
|
|
11
11
|
</script>
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
Thanks to its opinionated directory structure, Nuxt can auto-import your [`app/components/`](/docs/guide/directory-structure/app/components), [`app/composables/`](/docs/guide/directory-structure/app/composables) and [`app/utils/`](/docs/guide/directory-structure/app/utils).
|
|
14
|
+
Thanks to its opinionated directory structure, Nuxt can auto-import your [`app/components/`](/docs/4.x/guide/directory-structure/app/components), [`app/composables/`](/docs/4.x/guide/directory-structure/app/composables) and [`app/utils/`](/docs/4.x/guide/directory-structure/app/utils).
|
|
15
15
|
|
|
16
16
|
Contrary to a classic global declaration, Nuxt preserves typings, IDEs completions and hints, and **only includes what is used in your production code**.
|
|
17
17
|
|
|
18
18
|
::note
|
|
19
|
-
In the docs, every function that is not explicitly imported is auto-imported by Nuxt and can be used as-is in your code. You can find a reference for auto-imported components, composables and utilities in the [API section](/docs/api).
|
|
19
|
+
In the docs, every function that is not explicitly imported is auto-imported by Nuxt and can be used as-is in your code. You can find a reference for auto-imported components, composables and utilities in the [API section](/docs/4.x/api).
|
|
20
20
|
::
|
|
21
21
|
|
|
22
22
|
::note
|
|
23
|
-
In the [`server`](/docs/guide/directory-structure/server) directory, Nuxt auto-imports exported functions and variables from `server/utils/`.
|
|
23
|
+
In the [`server`](/docs/4.x/guide/directory-structure/server) directory, Nuxt auto-imports exported functions and variables from `server/utils/`.
|
|
24
24
|
::
|
|
25
25
|
|
|
26
26
|
::note
|
|
27
|
-
You can also auto-import functions exported from custom folders or third-party packages by configuring the [`imports`](/docs/api/nuxt-config#imports) section of your `nuxt.config` file.
|
|
27
|
+
You can also auto-import functions exported from custom folders or third-party packages by configuring the [`imports`](/docs/4.x/api/nuxt-config#imports) section of your `nuxt.config` file.
|
|
28
28
|
::
|
|
29
29
|
|
|
30
30
|
## Built-in Auto-imports
|
|
31
31
|
|
|
32
|
-
Nuxt auto-imports functions and composables to perform [data fetching](/docs/getting-started/data-fetching), get access to the [app context](/docs/api/composables/use-nuxt-app) and [runtime config](/docs/guide/going-further/runtime-config), manage [state](/docs/getting-started/state-management) or define components and plugins.
|
|
32
|
+
Nuxt auto-imports functions and composables to perform [data fetching](/docs/4.x/getting-started/data-fetching), get access to the [app context](/docs/4.x/api/composables/use-nuxt-app) and [runtime config](/docs/4.x/guide/going-further/runtime-config), manage [state](/docs/4.x/getting-started/state-management) or define components and plugins.
|
|
33
33
|
|
|
34
34
|
```vue twoslash
|
|
35
35
|
<script setup lang="ts">
|
|
@@ -66,7 +66,7 @@ If you get an error message like `Nuxt instance is unavailable` then it probably
|
|
|
66
66
|
When using a composable that requires the Nuxt context inside a non-SFC component, you need to wrap your component with `defineNuxtComponent` instead of `defineComponent`
|
|
67
67
|
::
|
|
68
68
|
|
|
69
|
-
::read-more{to="/docs/guide/going-further/experimental-features#asynccontext" icon="i-lucide-star"}
|
|
69
|
+
::read-more{to="/docs/4.x/guide/going-further/experimental-features#asynccontext" icon="i-lucide-star"}
|
|
70
70
|
Checkout the `asyncContext` experimental feature to use Nuxt composables in async functions.
|
|
71
71
|
::
|
|
72
72
|
|
|
@@ -101,11 +101,11 @@ export const useMyComposable = () => {
|
|
|
101
101
|
|
|
102
102
|
Nuxt directly auto-imports files created in defined directories:
|
|
103
103
|
|
|
104
|
-
- `app/components/` for [Vue components](/docs/guide/directory-structure/app/components).
|
|
105
|
-
- `app/composables/` for [Vue composables](/docs/guide/directory-structure/app/composables).
|
|
104
|
+
- `app/components/` for [Vue components](/docs/4.x/guide/directory-structure/app/components).
|
|
105
|
+
- `app/composables/` for [Vue composables](/docs/4.x/guide/directory-structure/app/composables).
|
|
106
106
|
- `app/utils/` for helper functions and other utilities.
|
|
107
107
|
|
|
108
|
-
:link-example{to="/docs/examples/features/auto-imports"}
|
|
108
|
+
:link-example{to="/docs/4.x/examples/features/auto-imports"}
|
|
109
109
|
|
|
110
110
|
::warning
|
|
111
111
|
**Auto-imported `ref` and `computed` won't be unwrapped in a component `<template>`.** :br
|
|
@@ -120,7 +120,7 @@ Nuxt exposes every auto-import with the `#imports` alias that can be used to mak
|
|
|
120
120
|
|
|
121
121
|
```vue
|
|
122
122
|
<script setup lang="ts">
|
|
123
|
-
import {
|
|
123
|
+
import { computed, ref } from '#imports'
|
|
124
124
|
|
|
125
125
|
const count = ref(1)
|
|
126
126
|
const double = computed(() => count.value * 2)
|
|
@@ -134,12 +134,12 @@ If you want to disable auto-importing composables and utilities, you can set `im
|
|
|
134
134
|
```ts twoslash [nuxt.config.ts]
|
|
135
135
|
export default defineNuxtConfig({
|
|
136
136
|
imports: {
|
|
137
|
-
autoImport: false
|
|
138
|
-
}
|
|
137
|
+
autoImport: false,
|
|
138
|
+
},
|
|
139
139
|
})
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
-
This will disable auto-imports completely but it's still possible to use [explicit imports](#explicit-imports) from `#imports`.
|
|
142
|
+
This will disable auto-imports completely but it's still possible to use [explicit imports](/docs/4.x/guide/concepts/auto-imports#explicit-imports) from `#imports`.
|
|
143
143
|
|
|
144
144
|
### Partially Disabling Auto-imports
|
|
145
145
|
|
|
@@ -148,8 +148,8 @@ If you want framework-specific functions like `ref` to remain auto-imported but
|
|
|
148
148
|
```ts
|
|
149
149
|
export default defineNuxtConfig({
|
|
150
150
|
imports: {
|
|
151
|
-
scan: false
|
|
152
|
-
}
|
|
151
|
+
scan: false,
|
|
152
|
+
},
|
|
153
153
|
})
|
|
154
154
|
```
|
|
155
155
|
|
|
@@ -167,15 +167,15 @@ With this configuration:
|
|
|
167
167
|
|
|
168
168
|
Nuxt also automatically imports components from your `~/components` directory, although this is configured separately from auto-importing composables and utility functions.
|
|
169
169
|
|
|
170
|
-
:read-more{to="/docs/guide/directory-structure/app/components"}
|
|
170
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/components"}
|
|
171
171
|
|
|
172
172
|
To disable auto-importing components from your own `~/components` directory, you can set `components.dirs` to an empty array (though note that this will not affect components added by modules).
|
|
173
173
|
|
|
174
174
|
```ts twoslash [nuxt.config.ts]
|
|
175
175
|
export default defineNuxtConfig({
|
|
176
176
|
components: {
|
|
177
|
-
dirs: []
|
|
178
|
-
}
|
|
177
|
+
dirs: [],
|
|
178
|
+
},
|
|
179
179
|
})
|
|
180
180
|
```
|
|
181
181
|
|
|
@@ -195,10 +195,10 @@ export default defineNuxtConfig({
|
|
|
195
195
|
presets: [
|
|
196
196
|
{
|
|
197
197
|
from: 'vue-i18n',
|
|
198
|
-
imports: ['useI18n']
|
|
199
|
-
}
|
|
200
|
-
]
|
|
201
|
-
}
|
|
198
|
+
imports: ['useI18n'],
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
202
|
})
|
|
203
203
|
```
|
|
204
204
|
|
|
@@ -22,7 +22,7 @@ When Nitro starts, it initializes and executes the plugins under the `/server/pl
|
|
|
22
22
|
Nitro plugins are executed only once when the server starts. In a serverless environment, the server boots on each incoming request, and so do the Nitro plugins. However, they are not awaited.
|
|
23
23
|
::
|
|
24
24
|
|
|
25
|
-
:read-more{to="/docs/guide/directory-structure/server#server-plugins"}
|
|
25
|
+
:read-more{to="/docs/4.x/guide/directory-structure/server#server-plugins"}
|
|
26
26
|
|
|
27
27
|
### Step 2: Nitro Server Middleware
|
|
28
28
|
|
|
@@ -32,7 +32,7 @@ After initializing the Nitro server, middleware under `server/middleware/` is ex
|
|
|
32
32
|
Returning a value from middleware will terminate the request and send the returned value as the response. This behavior should generally be avoided to ensure proper request handling!
|
|
33
33
|
::
|
|
34
34
|
|
|
35
|
-
:read-more{to="/docs/guide/directory-structure/server#server-middleware"}
|
|
35
|
+
:read-more{to="/docs/4.x/guide/directory-structure/server#server-middleware"}
|
|
36
36
|
|
|
37
37
|
### Step 3: Initialize Nuxt and Execute Nuxt App Plugins
|
|
38
38
|
|
|
@@ -40,13 +40,13 @@ The Vue and Nuxt instances are created first. Afterward, Nuxt executes its serve
|
|
|
40
40
|
- Built-in plugins, such as Vue Router and `unhead`.
|
|
41
41
|
- Custom plugins located in the `app/plugins/` directory, including those without a suffix (e.g., `myPlugin.ts`) and those with the `.server` suffix (e.g., `myServerPlugin.server.ts`).
|
|
42
42
|
|
|
43
|
-
Plugins execute in a specific order and may have dependencies on one another. For more details, including execution order and parallelism, refer to the [Plugins documentation](/docs/guide/directory-structure/plugins).
|
|
43
|
+
Plugins execute in a specific order and may have dependencies on one another. For more details, including execution order and parallelism, refer to the [Plugins documentation](/docs/4.x/guide/directory-structure/plugins).
|
|
44
44
|
|
|
45
45
|
::callout{icon="i-lucide-lightbulb"}
|
|
46
|
-
After this step, Nuxt calls the [`app:created`](/docs/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
|
|
46
|
+
After this step, Nuxt calls the [`app:created`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
|
|
47
47
|
::
|
|
48
48
|
|
|
49
|
-
:read-more{to="/docs/guide/directory-structure/plugins"}
|
|
49
|
+
:read-more{to="/docs/4.x/guide/directory-structure/plugins"}
|
|
50
50
|
|
|
51
51
|
### Step 4: Route Validation
|
|
52
52
|
|
|
@@ -55,9 +55,9 @@ After initializing plugins and before executing middleware, Nuxt calls the `vali
|
|
|
55
55
|
- The `validate` function should return `true` if the parameters are valid.
|
|
56
56
|
- If validation fails, it should return `false` or an object containing a `statusCode` and/or `statusMessage` to terminate the request.
|
|
57
57
|
|
|
58
|
-
For more information, see the [Route Validation documentation](/docs/getting-started/routing#route-validation).
|
|
58
|
+
For more information, see the [Route Validation documentation](/docs/4.x/getting-started/routing#route-validation).
|
|
59
59
|
|
|
60
|
-
:read-more{to="/docs/getting-started/routing#route-validation"}
|
|
60
|
+
:read-more{to="/docs/4.x/getting-started/routing#route-validation"}
|
|
61
61
|
|
|
62
62
|
### Step 5: Execute Nuxt App Middleware
|
|
63
63
|
|
|
@@ -70,11 +70,11 @@ In Nuxt, there are three types of middleware:
|
|
|
70
70
|
|
|
71
71
|
Nuxt executes all global middleware on the initial page load (both on server and client) and then again before any client-side navigation. Named and anonymous middleware are executed only on the routes specified in the middleware property of the page(route) meta defined in the corresponding page components.
|
|
72
72
|
|
|
73
|
-
For details about each type and examples, see the [Middleware documentation](/docs/guide/directory-structure/app/middleware).
|
|
73
|
+
For details about each type and examples, see the [Middleware documentation](/docs/4.x/guide/directory-structure/app/middleware).
|
|
74
74
|
|
|
75
75
|
Any redirection on the server will result in a `Location:` header being sent to the browser; the browser then makes a fresh request to this new location. All application state will be reset when this happens, unless persisted in a cookie.
|
|
76
76
|
|
|
77
|
-
:read-more{to="/docs/guide/directory-structure/app/middleware"}
|
|
77
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/middleware"}
|
|
78
78
|
|
|
79
79
|
### Step 6: Render Page and Components
|
|
80
80
|
|
|
@@ -99,11 +99,11 @@ Watch a video from Daniel Roe explaining Server Rendering and Global State.
|
|
|
99
99
|
After all required data is fetched and the components are rendered, Nuxt combines the rendered components with settings from `unhead` to generate a complete HTML document. This HTML, along with the associated data, is then sent back to the client to complete the SSR process.
|
|
100
100
|
|
|
101
101
|
::callout{icon="i-lucide-lightbulb"}
|
|
102
|
-
After rendering the Vue application to HTML, Nuxt calls the [`app:rendered`](/docs/api/advanced/hooks#app-hooks-runtime) hook.
|
|
102
|
+
After rendering the Vue application to HTML, Nuxt calls the [`app:rendered`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook.
|
|
103
103
|
::
|
|
104
104
|
|
|
105
105
|
::callout{icon="i-lucide-lightbulb"}
|
|
106
|
-
Before finalizing and sending the HTML, Nitro will call the [`render:html`](/docs/api/advanced/hooks#nitro-app-hooks-runtime-server-side) hook. This hook allows you to manipulate the generated HTML, such as injecting additional scripts or modifying meta tags.
|
|
106
|
+
Before finalizing and sending the HTML, Nitro will call the [`render:html`](/docs/4.x/api/advanced/hooks#nitro-app-hooks-runtime-server-side) hook. This hook allows you to manipulate the generated HTML, such as injecting additional scripts or modifying meta tags.
|
|
107
107
|
::
|
|
108
108
|
|
|
109
109
|
## Client (browser)
|
|
@@ -117,10 +117,10 @@ This step is similar to the server-side execution and includes both built-in and
|
|
|
117
117
|
Custom plugins in the `app/plugins/` directory, such as those without a suffix (e.g., `myPlugin.ts`) and with the `.client` suffix (e.g., `myClientPlugin.client.ts`), are executed on the client side.
|
|
118
118
|
|
|
119
119
|
::callout{icon="i-lucide-lightbulb"}
|
|
120
|
-
After this step, Nuxt calls the [`app:created`](/docs/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
|
|
120
|
+
After this step, Nuxt calls the [`app:created`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
|
|
121
121
|
::
|
|
122
122
|
|
|
123
|
-
:read-more{to="/docs/guide/directory-structure/plugins"}
|
|
123
|
+
:read-more{to="/docs/4.x/guide/directory-structure/plugins"}
|
|
124
124
|
|
|
125
125
|
### Step 2: Route Validation
|
|
126
126
|
|
|
@@ -130,20 +130,20 @@ This step is the same as the server-side execution and includes the `validate` m
|
|
|
130
130
|
|
|
131
131
|
Nuxt middleware runs on both the server and the client. If you want certain code to run in specific environments, consider splitting it by using `import.meta.client` for the client and `import.meta.server` for the server.
|
|
132
132
|
|
|
133
|
-
:read-more{to="/docs/guide/directory-structure/app/middleware#when-middleware-runs"}
|
|
133
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/middleware#when-middleware-runs"}
|
|
134
134
|
|
|
135
135
|
### Step 4: Mount Vue Application and Hydration
|
|
136
136
|
|
|
137
|
-
Calling `app.mount('#__nuxt')` mounts the Vue application to the DOM. If the application uses SSR or SSG mode, Vue performs a hydration step to make the client-side application interactive. During hydration, Vue recreates the application (excluding [Server Components](/docs/guide/directory-structure/app/components#server-components)), matches each component to its corresponding DOM nodes, and attaches DOM event listeners.
|
|
137
|
+
Calling `app.mount('#__nuxt')` mounts the Vue application to the DOM. If the application uses SSR or SSG mode, Vue performs a hydration step to make the client-side application interactive. During hydration, Vue recreates the application (excluding [Server Components](/docs/4.x/guide/directory-structure/app/components#server-components)), matches each component to its corresponding DOM nodes, and attaches DOM event listeners.
|
|
138
138
|
|
|
139
139
|
To ensure proper hydration, it's important to maintain consistency between the data on the server and the client. For API requests, it is recommended to use `useAsyncData`, `useFetch`, or other SSR-friendly composables. These methods ensure that the data fetched on the server side is reused during hydration, avoiding repeated requests. Any new requests should only be triggered after hydration, preventing hydration errors.
|
|
140
140
|
|
|
141
141
|
::callout{icon="i-lucide-lightbulb"}
|
|
142
|
-
Before mounting the Vue application, Nuxt calls the [`app:beforeMount`](/docs/api/advanced/hooks#app-hooks-runtime) hook.
|
|
142
|
+
Before mounting the Vue application, Nuxt calls the [`app:beforeMount`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook.
|
|
143
143
|
::
|
|
144
144
|
|
|
145
145
|
::callout{icon="i-lucide-lightbulb"}
|
|
146
|
-
After mounting the Vue application, Nuxt calls the [`app:mounted`](/docs/api/advanced/hooks#app-hooks-runtime) hook.
|
|
146
|
+
After mounting the Vue application, Nuxt calls the [`app:mounted`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook.
|
|
147
147
|
::
|
|
148
148
|
|
|
149
149
|
### Step 5: Vue Lifecycle
|
|
@@ -25,17 +25,17 @@ We chose to build Nuxt on top of Vue for these reasons:
|
|
|
25
25
|
|
|
26
26
|
### Auto-imports
|
|
27
27
|
|
|
28
|
-
Every Vue component created in the [`app/components/`](/docs/guide/directory-structure/app/components) directory of a Nuxt project will be available in your project without having to import it. If a component is not used anywhere, your production’s code will not include it.
|
|
28
|
+
Every Vue component created in the [`app/components/`](/docs/4.x/guide/directory-structure/app/components) directory of a Nuxt project will be available in your project without having to import it. If a component is not used anywhere, your production’s code will not include it.
|
|
29
29
|
|
|
30
|
-
:read-more{to="/docs/guide/concepts/auto-imports"}
|
|
30
|
+
:read-more{to="/docs/4.x/guide/concepts/auto-imports"}
|
|
31
31
|
|
|
32
32
|
### Vue Router
|
|
33
33
|
|
|
34
|
-
Most applications need multiple pages and a way to navigate between them. This is called **routing**. Nuxt uses an [`app/pages/`](/docs/guide/directory-structure/app/pages) directory and naming conventions to directly create routes mapped to your files using the official [Vue Router library](https://router.vuejs.org).
|
|
34
|
+
Most applications need multiple pages and a way to navigate between them. This is called **routing**. Nuxt uses an [`app/pages/`](/docs/4.x/guide/directory-structure/app/pages) directory and naming conventions to directly create routes mapped to your files using the official [Vue Router library](https://router.vuejs.org).
|
|
35
35
|
|
|
36
|
-
:read-more{to="/docs/getting-started/routing"}
|
|
36
|
+
:read-more{to="/docs/4.x/getting-started/routing"}
|
|
37
37
|
|
|
38
|
-
:link-example{to="/docs/examples/features/auto-imports"}
|
|
38
|
+
:link-example{to="/docs/4.x/examples/features/auto-imports"}
|
|
39
39
|
|
|
40
40
|
## Differences with Nuxt 2 / Vue 2
|
|
41
41
|
|
|
@@ -64,16 +64,16 @@ The only way to provide data and logic to components in Vue 2 was through the Op
|
|
|
64
64
|
```vue twoslash
|
|
65
65
|
<script>
|
|
66
66
|
export default {
|
|
67
|
-
data() {
|
|
67
|
+
data () {
|
|
68
68
|
return {
|
|
69
|
-
count: 0
|
|
69
|
+
count: 0,
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
methods: {
|
|
73
|
-
increment(){
|
|
73
|
+
increment () {
|
|
74
74
|
this.count++
|
|
75
|
-
}
|
|
76
|
-
}
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
77
|
}
|
|
78
78
|
</script>
|
|
79
79
|
```
|
|
@@ -91,13 +91,13 @@ const increment = () => count.value++
|
|
|
91
91
|
|
|
92
92
|
The goal of Nuxt is to provide a great developer experience around the Composition API.
|
|
93
93
|
|
|
94
|
-
- Use auto-imported [Reactivity functions](https://vuejs.org/api/reactivity-core.html) from Vue and Nuxt [built-in composables](/docs/api/composables/use-async-data).
|
|
95
|
-
- Write your own auto-imported reusable functions in the [`app/composables/` directory](/docs/guide/directory-structure/app/composables).
|
|
94
|
+
- Use auto-imported [Reactivity functions](https://vuejs.org/api/reactivity-core.html) from Vue and Nuxt [built-in composables](/docs/4.x/api/composables/use-async-data).
|
|
95
|
+
- Write your own auto-imported reusable functions in the [`app/composables/` directory](/docs/4.x/guide/directory-structure/app/composables).
|
|
96
96
|
|
|
97
97
|
### TypeScript Support
|
|
98
98
|
|
|
99
99
|
Both Vue 3 and Nuxt 3+ are written in TypeScript. A fully typed codebase prevents mistakes and documents APIs usage. This doesn’t mean that you have to write your application in TypeScript to take advantage of it. With Nuxt 3, you can opt-in by renaming your file from `.js` to `.ts` , or add `<script setup lang="ts">` in a component.
|
|
100
100
|
|
|
101
|
-
::read-more{to="/docs/guide/concepts/typescript"}
|
|
101
|
+
::read-more{to="/docs/4.x/guide/concepts/typescript"}
|
|
102
102
|
Read the details about TypeScript in Nuxt
|
|
103
103
|
::
|
|
@@ -3,11 +3,11 @@ 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/4.x/guide/concepts/rendering#universal-rendering), [client-side rendering](/docs/4.x/guide/concepts/rendering#client-side-rendering) but also offers [hybrid-rendering](/docs/4.x/guide/concepts/rendering#hybrid-rendering) and the possibility to render your application on [CDN Edge Servers](/docs/4.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
|
|
|
10
|
-
By default, Nuxt uses **universal rendering** to provide better user experience, performance and to optimize search engine indexing, but you can switch rendering modes in [one line of configuration](/docs/api/nuxt-config#ssr).
|
|
10
|
+
By default, Nuxt uses **universal rendering** to provide better user experience, performance and to optimize search engine indexing, but you can switch rendering modes in [one line of configuration](/docs/4.x/api/nuxt-config#ssr).
|
|
11
11
|
|
|
12
12
|
## Universal Rendering
|
|
13
13
|
|
|
@@ -25,24 +25,26 @@ It is normal to ask which parts of a Vue file runs on the server and/or the clie
|
|
|
25
25
|
|
|
26
26
|
```vue [app/app.vue]
|
|
27
27
|
<script setup lang="ts">
|
|
28
|
-
const counter = ref(0)
|
|
28
|
+
const counter = ref(0) // executes in server and client environments
|
|
29
29
|
|
|
30
30
|
const handleClick = () => {
|
|
31
|
-
counter.value
|
|
32
|
-
}
|
|
31
|
+
counter.value++ // executes only in a client environment
|
|
32
|
+
}
|
|
33
33
|
</script>
|
|
34
34
|
|
|
35
35
|
<template>
|
|
36
36
|
<div>
|
|
37
37
|
<p>Count: {{ counter }}</p>
|
|
38
|
-
<button @click="handleClick">
|
|
38
|
+
<button @click="handleClick">
|
|
39
|
+
Increment
|
|
40
|
+
</button>
|
|
39
41
|
</div>
|
|
40
42
|
</template>
|
|
41
43
|
```
|
|
42
44
|
|
|
43
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.
|
|
44
46
|
|
|
45
|
-
[Middlewares](/docs/guide/directory-structure/app/middleware) and [pages](/docs/guide/directory-structure/app/pages) run in the server and on the client during hydration. [Plugins](/docs/guide/directory-structure/plugins) can be rendered on the server or client or both. [Components](/docs/guide/directory-structure/app/components) can be forced to run on the client only as well. [Composables](/docs/guide/directory-structure/app/composables) and [utilities](/docs/guide/directory-structure/app/utils) are rendered based on the context of their usage.
|
|
47
|
+
[Middlewares](/docs/4.x/guide/directory-structure/app/middleware) and [pages](/docs/4.x/guide/directory-structure/app/pages) run in the server and on the client during hydration. [Plugins](/docs/4.x/guide/directory-structure/plugins) can be rendered on the server or client or both. [Components](/docs/4.x/guide/directory-structure/app/components) can be forced to run on the client only as well. [Composables](/docs/4.x/guide/directory-structure/app/composables) and [utilities](/docs/4.x/guide/directory-structure/app/utils) are rendered based on the context of their usage.
|
|
46
48
|
|
|
47
49
|
**Benefits of server-side rendering:**
|
|
48
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.
|
|
@@ -50,7 +52,7 @@ On the initial request, the `counter` ref is initialized in the server since it
|
|
|
50
52
|
|
|
51
53
|
**Downsides of server-side rendering:**
|
|
52
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.
|
|
53
|
-
- **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/4.x/guide/concepts/rendering#edge-side-rendering).
|
|
54
56
|
|
|
55
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.**
|
|
56
58
|
|
|
@@ -83,20 +85,20 @@ You can enable client-side only rendering with Nuxt in your `nuxt.config.ts`:
|
|
|
83
85
|
|
|
84
86
|
```ts [nuxt.config.ts]
|
|
85
87
|
export default defineNuxtConfig({
|
|
86
|
-
ssr: false
|
|
88
|
+
ssr: false,
|
|
87
89
|
})
|
|
88
90
|
```
|
|
89
91
|
|
|
90
92
|
::note
|
|
91
93
|
If you do use `ssr: false`, you should also place an HTML file in `~/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.
|
|
92
|
-
:read-more{title="SPA Loading Template" to="/docs/api/configuration/nuxt-config#spaloadingtemplate"}
|
|
94
|
+
:read-more{title="SPA Loading Template" to="/docs/4.x/api/configuration/nuxt-config#spaloadingtemplate"}
|
|
93
95
|
::
|
|
94
96
|
|
|
95
97
|
:video-accordion{title="Watch a video from Alexander Lichter about Building a plain SPA with Nuxt" videoId="7Lr0QTP1Ro8"}
|
|
96
98
|
|
|
97
99
|
### Deploying a Static Client-Rendered App
|
|
98
100
|
|
|
99
|
-
If you deploy your app to [static hosting](/docs/getting-started/deployment#static-hosting) with the `nuxt generate` or `nuxt build --prerender` commands, then by default, Nuxt will render every page as a separate static HTML file.
|
|
101
|
+
If you deploy your app to [static hosting](/docs/4.x/getting-started/deployment#static-hosting) with the `nuxt generate` or `nuxt build --prerender` commands, then by default, Nuxt will render every page as a separate static HTML file.
|
|
100
102
|
|
|
101
103
|
::warning
|
|
102
104
|
If you prerender your app with the `nuxt generate` or `nuxt build --prerender` commands, then you will not be able to use any server endpoints as no server will be included in your output folder. If you need server functionality, use `nuxt build` instead.
|
|
@@ -104,14 +106,14 @@ If you prerender your app with the `nuxt generate` or `nuxt build --prerender` c
|
|
|
104
106
|
|
|
105
107
|
If you are using purely client-side rendering, then this might be unnecessary. You might only need a single `index.html` file, plus `200.html` and `404.html` fallbacks, which you can tell your static web host to serve up for all requests.
|
|
106
108
|
|
|
107
|
-
In order to achieve this we can change how the routes are prerendered. Just add this to [your hooks](/docs/api/advanced/hooks#nuxt-hooks-build-time) in your `nuxt.config.ts`:
|
|
109
|
+
In order to achieve this we can change how the routes are prerendered. Just add this to [your hooks](/docs/4.x/api/advanced/hooks#nuxt-hooks-build-time) in your `nuxt.config.ts`:
|
|
108
110
|
|
|
109
111
|
```ts twoslash [nuxt.config.ts]
|
|
110
112
|
export default defineNuxtConfig({
|
|
111
113
|
hooks: {
|
|
112
114
|
'prerender:routes' ({ routes }) {
|
|
113
115
|
routes.clear() // Do not generate any routes (except the defaults)
|
|
114
|
-
}
|
|
116
|
+
},
|
|
115
117
|
},
|
|
116
118
|
})
|
|
117
119
|
```
|
|
@@ -126,21 +128,21 @@ The `200.html` and `404.html` might be useful for the hosting provider you are u
|
|
|
126
128
|
|
|
127
129
|
#### Skipping Client Fallback Generation
|
|
128
130
|
|
|
129
|
-
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/getting-started/prerendering#prerendergenerate-nitro-hook).
|
|
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/4.x/getting-started/prerendering#prerendergenerate-nitro-hook).
|
|
130
132
|
|
|
131
133
|
```ts twoslash [nuxt.config.ts]
|
|
132
134
|
export default defineNuxtConfig({
|
|
133
135
|
ssr: false,
|
|
134
136
|
nitro: {
|
|
135
137
|
hooks: {
|
|
136
|
-
'prerender:generate'(route) {
|
|
138
|
+
'prerender:generate' (route) {
|
|
137
139
|
const routesToSkip = ['/index.html', '/200.html', '/404.html']
|
|
138
140
|
if (routesToSkip.includes(route.route)) {
|
|
139
141
|
route.skip = true
|
|
140
142
|
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
144
146
|
})
|
|
145
147
|
```
|
|
146
148
|
|
|
@@ -172,8 +174,8 @@ export default defineNuxtConfig({
|
|
|
172
174
|
// Add cors headers on API routes
|
|
173
175
|
'/api/**': { cors: true },
|
|
174
176
|
// Redirects legacy urls
|
|
175
|
-
'/old-page': { redirect: '/new-page' }
|
|
176
|
-
}
|
|
177
|
+
'/old-page': { redirect: '/new-page' },
|
|
178
|
+
},
|
|
177
179
|
})
|
|
178
180
|
```
|
|
179
181
|
|
|
@@ -193,7 +195,7 @@ The different properties you can use are the following:
|
|
|
193
195
|
Whenever possible, route rules will be automatically applied to the deployment platform's native rules for optimal performances (Netlify and Vercel are currently supported).
|
|
194
196
|
|
|
195
197
|
::important
|
|
196
|
-
Note that Hybrid Rendering is not available when using [`nuxt generate`](/docs/api/commands/generate).
|
|
198
|
+
Note that Hybrid Rendering is not available when using [`nuxt generate`](/docs/4.x/api/commands/generate).
|
|
197
199
|
::
|
|
198
200
|
|
|
199
201
|
**Examples:**
|
|
@@ -219,7 +221,7 @@ With ESR, the rendering process is pushed to the 'edge' of the network - the CDN
|
|
|
219
221
|
|
|
220
222
|
When a request for a page is made, instead of going all the way to the original server, it's intercepted by the nearest edge server. This server generates the HTML for the page and sends it back to the user. This process minimizes the physical distance the data has to travel, **reducing latency and loading the page faster**.
|
|
221
223
|
|
|
222
|
-
Edge-side rendering is possible thanks to [Nitro](https://nitro.build/), the [server engine](/docs/guide/concepts/server-engine) that powers Nuxt. It offers cross-platform support for Node.js, Deno, Cloudflare Workers, and more.
|
|
224
|
+
Edge-side rendering is possible thanks to [Nitro](https://nitro.build/), the [server engine](/docs/4.x/guide/concepts/server-engine) that powers Nuxt. It offers cross-platform support for Node.js, Deno, Cloudflare Workers, and more.
|
|
223
225
|
|
|
224
226
|
The current platforms where you can leverage ESR are:
|
|
225
227
|
- [Cloudflare Pages](https://pages.cloudflare.com) with zero configuration using the git integration and the `nuxt build` command
|
|
@@ -16,7 +16,7 @@ It is shipped with many features:
|
|
|
16
16
|
|
|
17
17
|
## API Layer
|
|
18
18
|
|
|
19
|
-
Server [API endpoints](/docs/guide/directory-structure/server#
|
|
19
|
+
Server [API endpoints](/docs/4.x/guide/directory-structure/server#server-routes) and [Middleware](/docs/4.x/guide/directory-structure/server#server-middleware) are added by Nitro that internally uses [h3](https://github.com/h3js/h3).
|
|
20
20
|
|
|
21
21
|
Key features include:
|
|
22
22
|
|
|
@@ -26,15 +26,15 @@ Key features include:
|
|
|
26
26
|
|
|
27
27
|
Check out [the h3 docs](https://github.com/h3js/h3) for more information.
|
|
28
28
|
|
|
29
|
-
::read-more{to="/docs/guide/directory-structure/server#server-routes"}
|
|
29
|
+
::read-more{to="/docs/4.x/guide/directory-structure/server#server-routes"}
|
|
30
30
|
Learn more about the API layer in the `server/` directory.
|
|
31
31
|
::
|
|
32
32
|
|
|
33
33
|
## Direct API Calls
|
|
34
34
|
|
|
35
|
-
Nitro allows 'direct' calling of routes via the globally-available [`$fetch`](/docs/api/utils/dollarfetch) helper. This will make an API call to the server if run on the browser, but will directly call the relevant function if run on the server, **saving an additional API call**.
|
|
35
|
+
Nitro allows 'direct' calling of routes via the globally-available [`$fetch`](/docs/4.x/api/utils/dollarfetch) helper. This will make an API call to the server if run on the browser, but will directly call the relevant function if run on the server, **saving an additional API call**.
|
|
36
36
|
|
|
37
|
-
[`$fetch`](/docs/api/utils/dollarfetch) API is using [ofetch](https://github.com/unjs/ofetch), with key features including:
|
|
37
|
+
[`$fetch`](/docs/4.x/api/utils/dollarfetch) API is using [ofetch](https://github.com/unjs/ofetch), with key features including:
|
|
38
38
|
|
|
39
39
|
- Automatic parsing of JSON responses (with access to raw response if needed)
|
|
40
40
|
- Request body and params are automatically handled, with correct `Content-Type` headers
|
|
@@ -45,7 +45,7 @@ For more information on `$fetch` features, check out [ofetch](https://github.com
|
|
|
45
45
|
|
|
46
46
|
When using API routes (or middleware), Nitro will generate typings for these routes as long as you are returning a value instead of using `res.end()` to send a response.
|
|
47
47
|
|
|
48
|
-
You can access these types when using [`$fetch()`](/docs/api/utils/dollarfetch) or [`useFetch()`](/docs/api/composables/use-fetch).
|
|
48
|
+
You can access these types when using [`$fetch()`](/docs/4.x/api/utils/dollarfetch) or [`useFetch()`](/docs/4.x/api/composables/use-fetch).
|
|
49
49
|
|
|
50
50
|
## Standalone Server
|
|
51
51
|
|
|
@@ -53,7 +53,7 @@ Nitro produces a standalone server dist that is independent of `node_modules`.
|
|
|
53
53
|
|
|
54
54
|
The server in Nuxt 2 is not standalone and requires part of Nuxt core to be involved by running `nuxt start` (with the [`nuxt-start`](https://www.npmjs.com/package/nuxt-start) or [`nuxt`](https://www.npmjs.com/package/nuxt) distributions) or custom programmatic usage, which is fragile and prone to breakage and not suitable for serverless and service worker environments.
|
|
55
55
|
|
|
56
|
-
Nuxt generates this dist when running `nuxt build` into a [`.output`](/docs/guide/directory-structure/output) directory.
|
|
56
|
+
Nuxt generates this dist when running `nuxt build` into a [`.output`](/docs/4.x/guide/directory-structure/output) directory.
|
|
57
57
|
|
|
58
58
|
The output contains runtime code to run your Nuxt server in any environment (including experimental browser service workers!) and serve your static files, making it a true hybrid framework for the JAMstack. In addition, Nuxt implements a native storage layer, supporting multi-source drivers and local assets.
|
|
59
59
|
|
|
@@ -7,7 +7,7 @@ description: "Nuxt provides a module system to extend the framework core and sim
|
|
|
7
7
|
|
|
8
8
|
When developing production-grade applications with Nuxt you might find that the framework's core functionality is not enough. Nuxt can be extended with configuration options and plugins, but maintaining these customizations across multiple projects can be tedious, repetitive and time-consuming. On the other hand, supporting every project's needs out of the box would make Nuxt very complex and hard to use.
|
|
9
9
|
|
|
10
|
-
This is one of the reasons why Nuxt provides a module system that makes it possible to extend the core. Nuxt modules are async functions that sequentially run when starting Nuxt in development mode using [`nuxt dev`](/docs/api/commands/dev) or building a project for production with [`nuxt build`](/docs/api/commands/build). They can override templates, configure webpack loaders, add CSS libraries, and perform many other useful tasks.
|
|
10
|
+
This is one of the reasons why Nuxt provides a module system that makes it possible to extend the core. Nuxt modules are async functions that sequentially run when starting Nuxt in development mode using [`nuxt dev`](/docs/4.x/api/commands/dev) or building a project for production with [`nuxt build`](/docs/4.x/api/commands/build). They can override templates, configure webpack loaders, add CSS libraries, and perform many other useful tasks.
|
|
11
11
|
|
|
12
12
|
Best of all, Nuxt modules can be distributed in npm packages. This makes it possible for them to be reused across projects and shared with the community, helping create an ecosystem of high-quality add-ons.
|
|
13
13
|
|
|
@@ -17,7 +17,7 @@ Explore Nuxt Modules
|
|
|
17
17
|
|
|
18
18
|
## Add Nuxt Modules
|
|
19
19
|
|
|
20
|
-
Once you have installed the modules you can add them to your [`nuxt.config.ts`](/docs/guide/directory-structure/nuxt-config) file under the `modules` property. Module developers usually provide additional steps and details for usage.
|
|
20
|
+
Once you have installed the modules you can add them to your [`nuxt.config.ts`](/docs/4.x/guide/directory-structure/nuxt-config) file under the `modules` property. Module developers usually provide additional steps and details for usage.
|
|
21
21
|
|
|
22
22
|
```ts twoslash [nuxt.config.ts]
|
|
23
23
|
export default defineNuxtConfig({
|
|
@@ -32,8 +32,8 @@ export default defineNuxtConfig({
|
|
|
32
32
|
['./modules/example', { token: '123' }],
|
|
33
33
|
|
|
34
34
|
// Inline module definition
|
|
35
|
-
async (inlineOptions, nuxt) => { }
|
|
36
|
-
]
|
|
35
|
+
async (inlineOptions, nuxt) => { },
|
|
36
|
+
],
|
|
37
37
|
})
|
|
38
38
|
```
|
|
39
39
|
|
|
@@ -45,4 +45,4 @@ Nuxt modules are now build-time-only, and the `buildModules` property used in Nu
|
|
|
45
45
|
|
|
46
46
|
Everyone has the opportunity to develop modules and we cannot wait to see what you will build.
|
|
47
47
|
|
|
48
|
-
:read-more{to="/docs/guide/going-further/modules" title="Module Author Guide"}
|
|
48
|
+
:read-more{to="/docs/4.x/guide/going-further/modules" title="Module Author Guide"}
|