@nuxt/docs 3.19.1 → 3.19.3
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 +2 -2
- package/1.getting-started/02.installation.md +1 -0
- package/1.getting-started/03.configuration.md +29 -29
- package/1.getting-started/04.views.md +7 -7
- package/1.getting-started/05.assets.md +15 -9
- package/1.getting-started/06.styling.md +55 -45
- package/1.getting-started/07.routing.md +12 -12
- package/1.getting-started/08.seo-meta.md +55 -42
- package/1.getting-started/09.transitions.md +47 -42
- package/1.getting-started/10.data-fetching.md +90 -67
- package/1.getting-started/11.state-management.md +22 -15
- package/1.getting-started/12.error-handling.md +11 -9
- package/1.getting-started/13.server.md +3 -3
- package/1.getting-started/14.layers.md +21 -15
- package/1.getting-started/15.prerendering.md +28 -28
- package/1.getting-started/16.deployment.md +9 -9
- package/1.getting-started/17.testing.md +43 -43
- package/1.getting-started/18.upgrade.md +58 -57
- package/2.guide/0.index.md +3 -3
- 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/{2.directory-structure → 1.directory-structure}/0.output.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.assets.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.components.md +45 -24
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.composables.md +11 -11
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.content.md +7 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.layouts.md +16 -12
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.middleware.md +28 -22
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.modules.md +6 -6
- 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.pages.md +33 -31
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.plugins.md +25 -25
- 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 +34 -34
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.shared.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.utils.md +5 -5
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.env.md +5 -5
- 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 +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtrc.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.app-config.md +12 -12
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.app.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.error.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.nuxt-config.md +2 -2
- 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 +18 -18
- package/2.guide/{1.concepts → 2.concepts}/10.nuxt-lifecycle.md +10 -10
- package/2.guide/{1.concepts → 2.concepts}/2.vuejs-development.md +9 -9
- package/2.guide/{1.concepts → 2.concepts}/3.rendering.md +21 -19
- package/2.guide/{1.concepts → 2.concepts}/4.server-engine.md +5 -5
- package/2.guide/{1.concepts → 2.concepts}/5.modules.md +4 -4
- package/2.guide/{1.concepts → 2.concepts}/7.esm.md +15 -13
- package/2.guide/{1.concepts → 2.concepts}/8.typescript.md +11 -11
- package/2.guide/3.going-further/1.events.md +2 -2
- package/2.guide/3.going-further/1.experimental-features.md +80 -80
- package/2.guide/3.going-further/1.features.md +15 -15
- package/2.guide/3.going-further/1.internals.md +25 -25
- package/2.guide/3.going-further/10.runtime-config.md +11 -11
- package/2.guide/3.going-further/2.hooks.md +11 -11
- package/2.guide/3.going-further/3.modules.md +89 -87
- package/2.guide/3.going-further/4.kit.md +5 -5
- package/2.guide/3.going-further/6.nuxt-app.md +5 -5
- package/2.guide/3.going-further/7.layers.md +61 -52
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +31 -31
- package/2.guide/4.recipes/2.vite-plugin.md +4 -4
- package/2.guide/4.recipes/3.custom-usefetch.md +12 -12
- package/2.guide/4.recipes/4.sessions-and-authentication.md +34 -20
- package/2.guide/5.best-practices/hydration.md +4 -4
- package/2.guide/5.best-practices/performance.md +12 -12
- package/3.api/1.components/1.client-only.md +6 -3
- package/3.api/1.components/1.nuxt-client-fallback.md +9 -6
- package/3.api/1.components/10.nuxt-picture.md +1 -1
- package/3.api/1.components/11.teleports.md +4 -1
- package/3.api/1.components/12.nuxt-route-announcer.md +9 -9
- package/3.api/1.components/13.nuxt-time.md +44 -17
- package/3.api/1.components/2.nuxt-page.md +4 -4
- package/3.api/1.components/3.nuxt-layout.md +11 -6
- package/3.api/1.components/4.nuxt-link.md +40 -20
- package/3.api/1.components/5.nuxt-loading-indicator.md +2 -2
- package/3.api/1.components/6.nuxt-error-boundary.md +11 -9
- package/3.api/2.composables/on-prehydrate.md +2 -2
- package/3.api/2.composables/use-async-data.md +17 -17
- package/3.api/2.composables/use-cookie.md +28 -20
- package/3.api/2.composables/use-error.md +1 -1
- package/3.api/2.composables/use-fetch.md +55 -29
- package/3.api/2.composables/use-head-safe.md +7 -7
- package/3.api/2.composables/use-head.md +4 -4
- package/3.api/2.composables/use-hydration.md +6 -6
- package/3.api/2.composables/use-lazy-async-data.md +2 -2
- package/3.api/2.composables/use-lazy-fetch.md +2 -2
- package/3.api/2.composables/use-loading-indicator.md +12 -12
- package/3.api/2.composables/use-nuxt-app.md +19 -19
- 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 +9 -7
- package/3.api/2.composables/use-runtime-config.md +6 -6
- package/3.api/2.composables/use-runtime-hook.md +2 -2
- package/3.api/2.composables/use-seo-meta.md +2 -2
- package/3.api/2.composables/use-server-seo-meta.md +4 -4
- package/3.api/2.composables/use-state.md +4 -4
- package/3.api/3.utils/$fetch.md +9 -7
- 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 +4 -4
- package/3.api/3.utils/clear-error.md +2 -2
- 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 +1 -1
- 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 +12 -12
- package/3.api/3.utils/define-nuxt-route-middleware.md +5 -5
- package/3.api/3.utils/define-page-meta.md +21 -21
- package/3.api/3.utils/define-route-rules.md +5 -5
- package/3.api/3.utils/navigate-to.md +10 -10
- 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/prerender-routes.md +3 -3
- package/3.api/3.utils/refresh-cookie.md +3 -3
- package/3.api/3.utils/refresh-nuxt-data.md +11 -6
- package/3.api/3.utils/reload-nuxt-app.md +2 -2
- package/3.api/3.utils/set-page-layout.md +1 -1
- package/3.api/3.utils/set-response-status.md +2 -2
- package/3.api/3.utils/show-error.md +4 -4
- package/3.api/3.utils/update-app-config.md +3 -2
- 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 +2 -1
- 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 +4 -2
- package/3.api/4.commands/upgrade.md +3 -3
- package/3.api/5.kit/1.modules.md +36 -36
- 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 +62 -62
- package/3.api/5.kit/12.resolving.md +2 -2
- package/3.api/5.kit/14.builder.md +1 -0
- package/3.api/5.kit/15.examples.md +2 -2
- package/3.api/5.kit/16.layers.md +26 -26
- package/3.api/5.kit/3.compatibility.md +12 -12
- package/3.api/5.kit/4.autoimports.md +13 -13
- package/3.api/5.kit/5.components.md +7 -8
- 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.plugins.md +6 -5
- package/3.api/6.advanced/1.hooks.md +2 -2
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +6 -6
- package/5.community/5.framework-contribution.md +3 -3
- package/5.community/6.roadmap.md +1 -1
- package/6.bridge/1.overview.md +13 -13
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +2 -2
- package/6.bridge/3.bridge-composition-api.md +6 -6
- package/6.bridge/4.plugins-and-middleware.md +9 -9
- package/6.bridge/5.nuxt3-compatible-api.md +19 -16
- package/6.bridge/6.meta.md +21 -20
- 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/2.configuration.md +22 -20
- package/7.migration/20.module-authors.md +6 -6
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +20 -17
- package/7.migration/5.plugins-and-middleware.md +5 -5
- package/7.migration/6.pages-and-layouts.md +23 -19
- package/7.migration/7.component-options.md +14 -14
- package/7.migration/8.runtime-config.md +6 -6
- package/package.json +1 -1
- /package/2.guide/{1.concepts → 2.concepts}/.navigation.yml +0 -0
- /package/2.guide/{1.concepts → 2.concepts}/9.code-style.md +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: "app.vue"
|
|
3
3
|
description: "The app.vue file is the main component of your Nuxt application."
|
|
4
4
|
head.title: "app.vue"
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-file-type-vue
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
::tip
|
|
@@ -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/guide/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.
|
|
16
|
+
With Nuxt, the [`pages/`](/docs/3.x/guide/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>
|
|
@@ -25,7 +25,7 @@ With Nuxt, the [`pages/`](/docs/guide/directory-structure/pages) directory is op
|
|
|
25
25
|
|
|
26
26
|
### Usage with Pages
|
|
27
27
|
|
|
28
|
-
When you have a [`pages/`](/docs/guide/directory-structure/pages) directory, you need to use the [`<NuxtPage>`](/docs/api/components/nuxt-page) component to display the current page:
|
|
28
|
+
When you have a [`pages/`](/docs/3.x/guide/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>
|
|
@@ -57,7 +57,7 @@ Learn more about how to structure your pages using the `pages/` directory.
|
|
|
57
57
|
|
|
58
58
|
### Usage with Layouts
|
|
59
59
|
|
|
60
|
-
When your application requires different layouts for different pages, you can use the `layouts/` directory with the [`<NuxtLayout>`](/docs/api/components/nuxt-layout) component. This allows you to define multiple layouts and apply them per page.
|
|
60
|
+
When your application requires different layouts for different pages, you can use the `layouts/` directory with the [`<NuxtLayout>`](/docs/3.x/api/components/nuxt-layout) component. This allows you to define multiple layouts and apply them per page.
|
|
61
61
|
|
|
62
62
|
```vue [app.vue]
|
|
63
63
|
<template>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: "error.vue"
|
|
3
3
|
description: "The error.vue file is the error page in your Nuxt application."
|
|
4
4
|
head.title: "error.vue"
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-file-type-vue
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
During the lifespan of your application, some errors may appear unexpectedly at runtime. In such case, we can use the `error.vue` file to override the default error files and display the error nicely.
|
|
@@ -12,7 +12,7 @@ During the lifespan of your application, some errors may appear unexpectedly at
|
|
|
12
12
|
import type { NuxtError } from '#app'
|
|
13
13
|
|
|
14
14
|
const props = defineProps({
|
|
15
|
-
error: Object as () => NuxtError
|
|
15
|
+
error: Object as () => NuxtError,
|
|
16
16
|
})
|
|
17
17
|
</script>
|
|
18
18
|
|
|
@@ -25,14 +25,14 @@ const props = defineProps({
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
::note
|
|
28
|
-
Although it is called an 'error page' it's not a route and shouldn't be placed in your `~/pages` directory. For the same reason, you shouldn't use `definePageMeta` within this page. That being said, you can still use layouts in the error file, by utilizing the [`NuxtLayout`](/docs/api/components/nuxt-layout) component and specifying the name of the layout.
|
|
28
|
+
Although it is called an 'error page' it's not a route and shouldn't be placed in your `~/pages` directory. For the same reason, you shouldn't use `definePageMeta` within this page. That being said, you can still use layouts in the error file, by utilizing the [`NuxtLayout`](/docs/3.x/api/components/nuxt-layout) component and specifying the name of the layout.
|
|
29
29
|
::
|
|
30
30
|
|
|
31
31
|
The error page has a single prop - `error` which contains an error for you to handle.
|
|
32
32
|
|
|
33
33
|
The `error` object provides the following fields:
|
|
34
34
|
```ts
|
|
35
|
-
{
|
|
35
|
+
interface NuxtError {
|
|
36
36
|
statusCode: number
|
|
37
37
|
fatal: boolean
|
|
38
38
|
unhandled: boolean
|
|
@@ -49,7 +49,7 @@ throw createError({
|
|
|
49
49
|
statusCode: 404,
|
|
50
50
|
statusMessage: 'Page Not Found',
|
|
51
51
|
data: {
|
|
52
|
-
myCustomField: true
|
|
53
|
-
}
|
|
52
|
+
myCustomField: true,
|
|
53
|
+
},
|
|
54
54
|
})
|
|
55
55
|
```
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: "nuxt.config.ts"
|
|
3
3
|
description: "Nuxt can be easily configured with a single nuxt.config file."
|
|
4
4
|
head.title: "nuxt.config.ts"
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-file-type-nuxt
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
The `nuxt.config` file extension can either be `.js`, `.ts` or `.mjs`.
|
|
@@ -31,4 +31,4 @@ export default defineNuxtConfig({
|
|
|
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/guide/directory-structure/env), [`.nuxtignore`](/docs/guide/directory-structure/nuxtignore) and [`.nuxtrc`](/docs/guide/directory-structure/nuxtrc) dotfiles.
|
|
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/guide/directory-structure/env), [`.nuxtignore`](/docs/3.x/guide/directory-structure/nuxtignore) and [`.nuxtrc`](/docs/3.x/guide/directory-structure/nuxtrc) dotfiles.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: package.json
|
|
3
3
|
head.title: package.json
|
|
4
4
|
description: The package.json file contains all the dependencies and scripts for your application.
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-file-type-npm
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
The minimal `package.json` of your Nuxt application should looks like:
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
title: "tsconfig.json"
|
|
3
3
|
description: "Nuxt generates a .nuxt/tsconfig.json file with sensible defaults and your aliases."
|
|
4
4
|
head.title: "tsconfig.json"
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-file-type-tsconfig
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
Nuxt [automatically generates](/docs/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.
|
|
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
|
You can benefit from this by creating a `tsconfig.json` in the root of your project with the following content:
|
|
11
11
|
|
|
@@ -20,5 +20,5 @@ As you need to, you can customize the contents of this file. However, it is reco
|
|
|
20
20
|
::
|
|
21
21
|
|
|
22
22
|
::note
|
|
23
|
-
If you need to customize your `paths`, this will override the auto-generated path aliases. Instead, we recommend that you add any path aliases you need to the [`alias`](/docs/api/nuxt-config#alias) property within your `nuxt.config`, where they will get picked up and added to the auto-generated `tsconfig`.
|
|
23
|
+
If you need to customize your `paths`, this will override the auto-generated path aliases. Instead, we recommend that you add any path aliases you need to the [`alias`](/docs/3.x/api/nuxt-config#alias) property within your `nuxt.config`, where they will get picked up and added to the auto-generated `tsconfig`.
|
|
24
24
|
::
|
|
@@ -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 [`components/`](/docs/guide/directory-structure/components), [`composables/`](/docs/guide/directory-structure/composables) and [`utils/`](/docs/guide/directory-structure/utils).
|
|
14
|
+
Thanks to its opinionated directory structure, Nuxt can auto-import your [`components/`](/docs/3.x/guide/directory-structure/components), [`composables/`](/docs/3.x/guide/directory-structure/composables) and [`utils/`](/docs/3.x/guide/directory-structure/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/3.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/3.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/3.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/3.x/getting-started/data-fetching), get access to the [app context](/docs/3.x/api/composables/use-nuxt-app) and [runtime config](/docs/3.x/guide/going-further/runtime-config), manage [state](/docs/3.x/getting-started/state-management) or define components and plugins.
|
|
33
33
|
|
|
34
34
|
```vue twoslash
|
|
35
35
|
<script setup lang="ts">
|
|
@@ -101,8 +101,8 @@ export const useMyComposable = () => {
|
|
|
101
101
|
|
|
102
102
|
Nuxt directly auto-imports files created in defined directories:
|
|
103
103
|
|
|
104
|
-
- `components/` for [Vue components](/docs/guide/directory-structure/components).
|
|
105
|
-
- `composables/` for [Vue composables](/docs/guide/directory-structure/composables).
|
|
104
|
+
- `components/` for [Vue components](/docs/3.x/guide/directory-structure/components).
|
|
105
|
+
- `composables/` for [Vue composables](/docs/3.x/guide/directory-structure/composables).
|
|
106
106
|
- `utils/` for helper functions and other utilities.
|
|
107
107
|
|
|
108
108
|
:link-example{to="/docs/examples/features/auto-imports"}
|
|
@@ -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,8 +134,8 @@ 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
|
|
|
@@ -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
|
|
|
@@ -174,8 +174,8 @@ To disable auto-importing components from your own `~/components` directory, you
|
|
|
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
|
|
|
@@ -40,10 +40,10 @@ 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 `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/3.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/3.x/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
|
|
47
47
|
::
|
|
48
48
|
|
|
49
49
|
:read-more{to="/docs/guide/directory-structure/plugins"}
|
|
@@ -55,7 +55,7 @@ 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/3.x/getting-started/routing#route-validation).
|
|
59
59
|
|
|
60
60
|
:read-more{to="/docs/getting-started/routing#route-validation"}
|
|
61
61
|
|
|
@@ -70,7 +70,7 @@ 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/middleware).
|
|
73
|
+
For details about each type and examples, see the [Middleware documentation](/docs/3.x/guide/directory-structure/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
|
|
|
@@ -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/3.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/3.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,7 +117,7 @@ This step is similar to the server-side execution and includes both built-in and
|
|
|
117
117
|
Custom plugins in the `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/3.x/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
|
|
121
121
|
::
|
|
122
122
|
|
|
123
123
|
:read-more{to="/docs/guide/directory-structure/plugins"}
|
|
@@ -134,16 +134,16 @@ Nuxt middleware runs on both the server and the client. If you want certain code
|
|
|
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/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/3.x/guide/directory-structure/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/3.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/3.x/api/advanced/hooks#app-hooks-runtime) hook.
|
|
147
147
|
::
|
|
148
148
|
|
|
149
149
|
### Step 5: Vue Lifecycle
|
|
@@ -25,13 +25,13 @@ 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 [`components/`](/docs/guide/directory-structure/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 [`components/`](/docs/3.x/guide/directory-structure/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
30
|
:read-more{to="/docs/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 a [`pages/`](/docs/guide/directory-structure/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 a [`pages/`](/docs/3.x/guide/directory-structure/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
36
|
:read-more{to="/docs/getting-started/routing"}
|
|
37
37
|
|
|
@@ -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,8 +91,8 @@ 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 [`composables/` directory](/docs/guide/directory-structure/composables).
|
|
94
|
+
- Use auto-imported [Reactivity functions](https://vuejs.org/api/reactivity-core.html) from Vue and Nuxt [built-in composables](/docs/3.x/api/composables/use-async-data).
|
|
95
|
+
- Write your own auto-imported reusable functions in the [`composables/` directory](/docs/3.x/guide/directory-structure/composables).
|
|
96
96
|
|
|
97
97
|
### TypeScript Support
|
|
98
98
|
|
|
@@ -7,7 +7,7 @@ Nuxt supports different rendering modes, [universal rendering](#universal-render
|
|
|
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/3.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.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/middleware) and [pages](/docs/guide/directory-structure/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/components) can be forced to run on the client only as well. [Composables](/docs/guide/directory-structure/composables) and [utilities](/docs/guide/directory-structure/utils) are rendered based on the context of their usage.
|
|
47
|
+
[Middlewares](/docs/3.x/guide/directory-structure/middleware) and [pages](/docs/3.x/guide/directory-structure/pages) run in the server and on the client during hydration. [Plugins](/docs/3.x/guide/directory-structure/plugins) can be rendered on the server or client or both. [Components](/docs/3.x/guide/directory-structure/components) can be forced to run on the client only as well. [Composables](/docs/3.x/guide/directory-structure/composables) and [utilities](/docs/3.x/guide/directory-structure/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.
|
|
@@ -83,7 +85,7 @@ 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
|
|
|
@@ -96,7 +98,7 @@ If you do use `ssr: false`, you should also place an HTML file in `~/app/spa-loa
|
|
|
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/3.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/3.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/3.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/3.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/3.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#api-routes) and [Middleware](/docs/guide/directory-structure/server#server-middleware) are added by Nitro that internally uses [h3](https://github.com/h3js/h3).
|
|
19
|
+
Server [API endpoints](/docs/3.x/guide/directory-structure/server#api-routes) and [Middleware](/docs/3.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
|
|
|
@@ -32,9 +32,9 @@ Learn more about the API layer in the `server/` directory.
|
|
|
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/3.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/3.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/3.x/api/utils/dollarfetch) or [`useFetch()`](/docs/3.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/3.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/3.x/api/commands/dev) or building a project for production with [`nuxt build`](/docs/3.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/3.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
|
|
|
@@ -32,7 +32,7 @@ export { a }
|
|
|
32
32
|
|
|
33
33
|
Before ECMAScript Modules (ESM) became a standard (it took more than 10 years!), tooling like
|
|
34
34
|
[webpack](https://webpack.js.org/guides/ecma-script-modules) and even languages like TypeScript started supporting so-called **ESM syntax**.
|
|
35
|
-
However, there are some key differences with actual spec; here's [a helpful explainer](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive).
|
|
35
|
+
However, there are some key differences with actual spec; here's [a helpful explainer](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/).
|
|
36
36
|
|
|
37
37
|
### What is 'Native' ESM?
|
|
38
38
|
|
|
@@ -120,8 +120,8 @@ In the meantime, you can tell Nuxt not to try to import these libraries by addin
|
|
|
120
120
|
```ts twoslash
|
|
121
121
|
export default defineNuxtConfig({
|
|
122
122
|
build: {
|
|
123
|
-
transpile: ['sample-library']
|
|
124
|
-
}
|
|
123
|
+
transpile: ['sample-library'],
|
|
124
|
+
},
|
|
125
125
|
})
|
|
126
126
|
```
|
|
127
127
|
|
|
@@ -134,8 +134,8 @@ In some cases, you may also need to manually alias the library to the CJS versio
|
|
|
134
134
|
```ts twoslash
|
|
135
135
|
export default defineNuxtConfig({
|
|
136
136
|
alias: {
|
|
137
|
-
'sample-library': 'sample-library/dist/sample-library.cjs.js'
|
|
138
|
-
}
|
|
137
|
+
'sample-library': 'sample-library/dist/sample-library.cjs.js',
|
|
138
|
+
},
|
|
139
139
|
})
|
|
140
140
|
```
|
|
141
141
|
|
|
@@ -182,6 +182,8 @@ import('cjs-pkg').then(console.log) // [Module: null prototype] { default: { tes
|
|
|
182
182
|
|
|
183
183
|
In this case, we need to manually interop the default export:
|
|
184
184
|
|
|
185
|
+
<!-- eslint-disable import/no-named-default -->
|
|
186
|
+
|
|
185
187
|
```js
|
|
186
188
|
// Static import
|
|
187
189
|
import { default as pkg } from 'cjs-pkg'
|
|
@@ -219,16 +221,16 @@ The initial step from CJS to ESM is updating any usage of `require` to use `impo
|
|
|
219
221
|
|
|
220
222
|
::code-group
|
|
221
223
|
|
|
222
|
-
```
|
|
223
|
-
module.exports = ...
|
|
224
|
+
```ts [Before]
|
|
225
|
+
module.exports = function () { /* ... */ }
|
|
224
226
|
|
|
225
|
-
exports.hello =
|
|
227
|
+
exports.hello = 'world'
|
|
226
228
|
```
|
|
227
229
|
|
|
228
|
-
```
|
|
229
|
-
export default ...
|
|
230
|
+
```ts [After]
|
|
231
|
+
export default function () { /* ... */ }
|
|
230
232
|
|
|
231
|
-
export const hello =
|
|
233
|
+
export const hello = 'world'
|
|
232
234
|
```
|
|
233
235
|
|
|
234
236
|
::
|
|
@@ -242,7 +244,7 @@ const myLib = require('my-lib')
|
|
|
242
244
|
```js [After]
|
|
243
245
|
import myLib from 'my-lib'
|
|
244
246
|
// or
|
|
245
|
-
const
|
|
247
|
+
const dynamicMyLib = await import('my-lib').then(lib => lib.default || lib)
|
|
246
248
|
```
|
|
247
249
|
|
|
248
250
|
::
|
|
@@ -253,7 +255,7 @@ and should be replaced with `import()` and `import.meta.filename`.
|
|
|
253
255
|
::code-group
|
|
254
256
|
|
|
255
257
|
```js [Before]
|
|
256
|
-
|
|
258
|
+
const { join } = require('node:path')
|
|
257
259
|
|
|
258
260
|
const newDir = join(__dirname, 'new-dir')
|
|
259
261
|
```
|