@nuxt/docs 3.19.2 → 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 +41 -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 -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.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 +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/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
|
@@ -74,10 +74,10 @@ export default defineNuxtConfig({
|
|
|
74
74
|
'/api/*': { cache: { maxAge: 60 * 60 } },
|
|
75
75
|
// Redirection to avoid 404
|
|
76
76
|
'/old-page': {
|
|
77
|
-
redirect: { to: '/new-page', statusCode: 302 }
|
|
78
|
-
}
|
|
77
|
+
redirect: { to: '/new-page', statusCode: 302 },
|
|
78
|
+
},
|
|
79
79
|
// ...
|
|
80
|
-
}
|
|
80
|
+
},
|
|
81
81
|
})
|
|
82
82
|
```
|
|
83
83
|
|
|
@@ -9,8 +9,8 @@ One of the core features of Nuxt is the layers and extending support. You can ex
|
|
|
9
9
|
## Use Cases
|
|
10
10
|
|
|
11
11
|
- Share reusable configuration presets across projects using `nuxt.config` and `app.config`
|
|
12
|
-
- Create a component library using [`components/`](/docs/guide/directory-structure/components) directory
|
|
13
|
-
- Create utility and composable library using [`composables/`](/docs/guide/directory-structure/composables) and [`utils/`](/docs/guide/directory-structure/utils) directories
|
|
12
|
+
- Create a component library using [`components/`](/docs/3.x/guide/directory-structure/components) directory
|
|
13
|
+
- Create utility and composable library using [`composables/`](/docs/3.x/guide/directory-structure/composables) and [`utils/`](/docs/3.x/guide/directory-structure/utils) directories
|
|
14
14
|
- Create Nuxt module presets
|
|
15
15
|
- Share standard setup across projects
|
|
16
16
|
- Create Nuxt themes
|
|
@@ -30,15 +30,18 @@ In addition, named layer aliases to the `srcDir` of each of these layers will au
|
|
|
30
30
|
Named layer aliases were introduced in Nuxt v3.16.0.
|
|
31
31
|
::
|
|
32
32
|
|
|
33
|
-
In addition, you can extend from a layer by adding the [extends](/docs/api/nuxt-config#extends) property to your [`nuxt.config`](/docs/guide/directory-structure/nuxt-config) file.
|
|
33
|
+
In addition, you can extend from a layer by adding the [extends](/docs/3.x/api/nuxt-config#extends) property to your [`nuxt.config`](/docs/3.x/guide/directory-structure/nuxt-config) file.
|
|
34
34
|
|
|
35
35
|
```ts [nuxt.config.ts]
|
|
36
36
|
export default defineNuxtConfig({
|
|
37
37
|
extends: [
|
|
38
|
-
|
|
39
|
-
'
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
// Extend from a local layer
|
|
39
|
+
'../base',
|
|
40
|
+
// Extend from an installed npm package
|
|
41
|
+
'@my-themes/awesome',
|
|
42
|
+
// Extend from a git repository
|
|
43
|
+
'github:my-themes/awesome#v1',
|
|
44
|
+
],
|
|
42
45
|
})
|
|
43
46
|
```
|
|
44
47
|
|
|
@@ -48,8 +51,8 @@ You can also pass an authentication token if you are extending from a private Gi
|
|
|
48
51
|
export default defineNuxtConfig({
|
|
49
52
|
extends: [
|
|
50
53
|
// per layer configuration
|
|
51
|
-
['github:my-themes/private-awesome', { auth: process.env.GITHUB_TOKEN }]
|
|
52
|
-
]
|
|
54
|
+
['github:my-themes/private-awesome', { auth: process.env.GITHUB_TOKEN }],
|
|
55
|
+
],
|
|
53
56
|
})
|
|
54
57
|
```
|
|
55
58
|
|
|
@@ -61,13 +64,13 @@ export default defineNuxtConfig({
|
|
|
61
64
|
extends: [
|
|
62
65
|
[
|
|
63
66
|
'github:my-themes/awesome',
|
|
64
|
-
{
|
|
67
|
+
{
|
|
65
68
|
meta: {
|
|
66
69
|
name: 'my-awesome-theme',
|
|
67
70
|
},
|
|
68
71
|
},
|
|
69
72
|
],
|
|
70
|
-
]
|
|
73
|
+
],
|
|
71
74
|
})
|
|
72
75
|
```
|
|
73
76
|
|
|
@@ -86,10 +89,13 @@ When using multiple layers, it's important to understand how they override each
|
|
|
86
89
|
```ts [nuxt.config.ts]
|
|
87
90
|
export default defineNuxtConfig({
|
|
88
91
|
extends: [
|
|
89
|
-
|
|
90
|
-
'
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
// Highest priority (among extends)
|
|
93
|
+
'../base',
|
|
94
|
+
// Medium priority
|
|
95
|
+
'@my-themes/awesome',
|
|
96
|
+
// Lower priority
|
|
97
|
+
'github:my-themes/awesome#v1',
|
|
98
|
+
],
|
|
93
99
|
// Your project has the highest priority
|
|
94
100
|
})
|
|
95
101
|
```
|
|
@@ -10,7 +10,7 @@ Nuxt allows for select pages from your application to be rendered at build time.
|
|
|
10
10
|
|
|
11
11
|
## Crawl-based Pre-rendering
|
|
12
12
|
|
|
13
|
-
Use the [`nuxt generate` command](/docs/api/commands/generate) to build and pre-render your application using the [Nitro](/docs/guide/concepts/server-engine) crawler. This command is similar to `nuxt build` with the `nitro.static` option set to `true`, or running `nuxt build --prerender`.
|
|
13
|
+
Use the [`nuxt generate` command](/docs/3.x/api/commands/generate) to build and pre-render your application using the [Nitro](/docs/3.x/guide/concepts/server-engine) crawler. This command is similar to `nuxt build` with the `nitro.static` option set to `true`, or running `nuxt build --prerender`.
|
|
14
14
|
|
|
15
15
|
This will build your site, stand up a nuxt instance, and, by default, prerender the root page `/` along with any of your site's pages it links to, any of your site's pages they link to, and so on.
|
|
16
16
|
|
|
@@ -51,17 +51,17 @@ Read more about the `nuxt generate` command.
|
|
|
51
51
|
|
|
52
52
|
### Selective Pre-rendering
|
|
53
53
|
|
|
54
|
-
You can manually specify routes that [Nitro](/docs/guide/concepts/server-engine) will fetch and pre-render during the build or ignore routes that you don't want to pre-render like `/dynamic` in the `nuxt.config` file:
|
|
54
|
+
You can manually specify routes that [Nitro](/docs/3.x/guide/concepts/server-engine) will fetch and pre-render during the build or ignore routes that you don't want to pre-render like `/dynamic` in the `nuxt.config` file:
|
|
55
55
|
|
|
56
56
|
```ts twoslash [nuxt.config.ts]
|
|
57
57
|
export default defineNuxtConfig({
|
|
58
58
|
nitro: {
|
|
59
59
|
prerender: {
|
|
60
|
-
routes: [
|
|
61
|
-
ignore: [
|
|
60
|
+
routes: ['/user/1', '/user/2'],
|
|
61
|
+
ignore: ['/dynamic'],
|
|
62
62
|
},
|
|
63
63
|
},
|
|
64
|
-
})
|
|
64
|
+
})
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
You can combine this with the `crawlLinks` option to pre-render a set of routes that the crawler can't discover like your `/sitemap.xml` or `/robots.txt`:
|
|
@@ -71,10 +71,10 @@ export default defineNuxtConfig({
|
|
|
71
71
|
nitro: {
|
|
72
72
|
prerender: {
|
|
73
73
|
crawlLinks: true,
|
|
74
|
-
routes: [
|
|
74
|
+
routes: ['/sitemap.xml', '/robots.txt'],
|
|
75
75
|
},
|
|
76
76
|
},
|
|
77
|
-
})
|
|
77
|
+
})
|
|
78
78
|
```
|
|
79
79
|
|
|
80
80
|
Setting `nitro.prerender` to `true` is similar to `nitro.prerender.crawlLinks` to `true`.
|
|
@@ -89,21 +89,21 @@ Lastly, you can manually configure this using routeRules.
|
|
|
89
89
|
export default defineNuxtConfig({
|
|
90
90
|
routeRules: {
|
|
91
91
|
// Set prerender to true to configure it to be prerendered
|
|
92
|
-
|
|
92
|
+
'/rss.xml': { prerender: true },
|
|
93
93
|
// Set it to false to configure it to be skipped for prerendering
|
|
94
|
-
|
|
94
|
+
'/this-DOES-NOT-get-prerendered': { prerender: false },
|
|
95
95
|
// Everything under /blog gets prerendered as long as it
|
|
96
96
|
// is linked to from another page
|
|
97
|
-
|
|
97
|
+
'/blog/**': { prerender: true },
|
|
98
98
|
},
|
|
99
|
-
})
|
|
99
|
+
})
|
|
100
100
|
```
|
|
101
101
|
|
|
102
102
|
::read-more{to="https://nitro.build/config#routerules"}
|
|
103
103
|
Read more about Nitro's `routeRules` configuration.
|
|
104
104
|
::
|
|
105
105
|
|
|
106
|
-
As a shorthand, you can also configure this in a page file using [`defineRouteRules`](/docs/api/utils/define-route-rules).
|
|
106
|
+
As a shorthand, you can also configure this in a page file using [`defineRouteRules`](/docs/3.x/api/utils/define-route-rules).
|
|
107
107
|
|
|
108
108
|
::read-more{to="/docs/guide/going-further/experimental-features#inlinerouterules" icon="i-lucide-star"}
|
|
109
109
|
This feature is experimental and in order to use it you must enable the `experimental.inlineRouteRules` option in your `nuxt.config`.
|
|
@@ -114,7 +114,7 @@ This feature is experimental and in order to use it you must enable the `experim
|
|
|
114
114
|
// Or set at the page level
|
|
115
115
|
defineRouteRules({
|
|
116
116
|
prerender: true,
|
|
117
|
-
})
|
|
117
|
+
})
|
|
118
118
|
</script>
|
|
119
119
|
|
|
120
120
|
<template>
|
|
@@ -130,21 +130,21 @@ This will be translated to:
|
|
|
130
130
|
```ts [nuxt.config.ts]
|
|
131
131
|
export default defineNuxtConfig({
|
|
132
132
|
routeRules: {
|
|
133
|
-
|
|
133
|
+
'/': { prerender: true },
|
|
134
134
|
},
|
|
135
|
-
})
|
|
135
|
+
})
|
|
136
136
|
```
|
|
137
137
|
|
|
138
138
|
## Runtime Prerender Configuration
|
|
139
139
|
|
|
140
140
|
### `prerenderRoutes`
|
|
141
141
|
|
|
142
|
-
You can use this at runtime within a [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context) to add more routes for Nitro to prerender.
|
|
142
|
+
You can use this at runtime within a [Nuxt context](/docs/3.x/guide/going-further/nuxt-app#the-nuxt-context) to add more routes for Nitro to prerender.
|
|
143
143
|
|
|
144
144
|
```vue [pages/index.vue]
|
|
145
145
|
<script setup>
|
|
146
|
-
prerenderRoutes([
|
|
147
|
-
prerenderRoutes(
|
|
146
|
+
prerenderRoutes(['/some/other/url'])
|
|
147
|
+
prerenderRoutes('/api/content/article/my-article')
|
|
148
148
|
</script>
|
|
149
149
|
|
|
150
150
|
<template>
|
|
@@ -163,16 +163,16 @@ This is called before prerendering for additional routes to be registered.
|
|
|
163
163
|
```ts [nuxt.config.ts]
|
|
164
164
|
export default defineNuxtConfig({
|
|
165
165
|
hooks: {
|
|
166
|
-
async
|
|
167
|
-
const { pages } = await fetch(
|
|
168
|
-
|
|
169
|
-
)
|
|
166
|
+
async 'prerender:routes' (ctx) {
|
|
167
|
+
const { pages } = await fetch('https://api.some-cms.com/pages').then(
|
|
168
|
+
res => res.json(),
|
|
169
|
+
)
|
|
170
170
|
for (const page of pages) {
|
|
171
|
-
ctx.routes.add(`/${page.name}`)
|
|
171
|
+
ctx.routes.add(`/${page.name}`)
|
|
172
172
|
}
|
|
173
173
|
},
|
|
174
174
|
},
|
|
175
|
-
})
|
|
175
|
+
})
|
|
176
176
|
```
|
|
177
177
|
|
|
178
178
|
### `prerender:generate` Nitro hook
|
|
@@ -183,12 +183,12 @@ This is called for each route during prerendering. You can use this for fine-gra
|
|
|
183
183
|
export default defineNuxtConfig({
|
|
184
184
|
nitro: {
|
|
185
185
|
hooks: {
|
|
186
|
-
|
|
187
|
-
if (route.route?.includes(
|
|
188
|
-
route.skip = true
|
|
186
|
+
'prerender:generate' (route) {
|
|
187
|
+
if (route.route?.includes('private')) {
|
|
188
|
+
route.skip = true
|
|
189
189
|
}
|
|
190
190
|
},
|
|
191
191
|
},
|
|
192
192
|
},
|
|
193
|
-
})
|
|
193
|
+
})
|
|
194
194
|
```
|
|
@@ -48,9 +48,9 @@ module.exports = {
|
|
|
48
48
|
port: '3000',
|
|
49
49
|
exec_mode: 'cluster',
|
|
50
50
|
instances: 'max',
|
|
51
|
-
script: './.output/server/index.mjs'
|
|
52
|
-
}
|
|
53
|
-
]
|
|
51
|
+
script: './.output/server/index.mjs',
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
54
|
}
|
|
55
55
|
```
|
|
56
56
|
|
|
@@ -71,7 +71,7 @@ By default, the workload gets distributed to the workers with the round robin st
|
|
|
71
71
|
There are two ways to deploy a Nuxt application to any static hosting services:
|
|
72
72
|
|
|
73
73
|
- Static site generation (SSG) with `ssr: true` pre-renders routes of your application at build time. (This is the default behavior when running `nuxt generate`.) It will also generate `/200.html` and `/404.html` single-page app fallback pages, which can render dynamic routes or 404 errors on the client (though you may need to configure this on your static host).
|
|
74
|
-
- Alternatively, you can prerender your site with `ssr: false` (static single-page app). This will produce HTML pages with an empty `<div id="__nuxt"></div>` where your Vue app would normally be rendered. You will lose many SEO benefits of prerendering your site, so it is suggested instead to use [`<ClientOnly>`](/docs/api/components/client-only) to wrap the portions of your site that cannot be server rendered (if any).
|
|
74
|
+
- Alternatively, you can prerender your site with `ssr: false` (static single-page app). This will produce HTML pages with an empty `<div id="__nuxt"></div>` where your Vue app would normally be rendered. You will lose many SEO benefits of prerendering your site, so it is suggested instead to use [`<ClientOnly>`](/docs/3.x/api/components/client-only) to wrap the portions of your site that cannot be server rendered (if any).
|
|
75
75
|
|
|
76
76
|
:read-more{title="Nuxt prerendering" to="/docs/getting-started/prerendering"}
|
|
77
77
|
|
|
@@ -81,7 +81,7 @@ If you don't want to pre-render your routes, another way of using static hosting
|
|
|
81
81
|
|
|
82
82
|
```ts twoslash [nuxt.config.ts]
|
|
83
83
|
export default defineNuxtConfig({
|
|
84
|
-
ssr: false
|
|
84
|
+
ssr: false,
|
|
85
85
|
})
|
|
86
86
|
```
|
|
87
87
|
|
|
@@ -95,13 +95,13 @@ Nuxt can be deployed to several cloud providers with a minimal amount of configu
|
|
|
95
95
|
|
|
96
96
|
In addition to Node.js servers and static hosting services, a Nuxt project can be deployed with several well-tested presets and minimal amount of configuration.
|
|
97
97
|
|
|
98
|
-
You can explicitly set the desired preset in the [`nuxt.config.ts`](/docs/guide/directory-structure/nuxt-config) file:
|
|
98
|
+
You can explicitly set the desired preset in the [`nuxt.config.ts`](/docs/3.x/guide/directory-structure/nuxt-config) file:
|
|
99
99
|
|
|
100
|
-
```
|
|
100
|
+
```ts twoslash [nuxt.config.ts]
|
|
101
101
|
export default defineNuxtConfig({
|
|
102
102
|
nitro: {
|
|
103
|
-
preset: 'node-server'
|
|
104
|
-
}
|
|
103
|
+
preset: 'node-server',
|
|
104
|
+
},
|
|
105
105
|
})
|
|
106
106
|
```
|
|
107
107
|
|
|
@@ -5,7 +5,7 @@ navigation.icon: i-lucide-circle-check
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
::tip
|
|
8
|
-
If you are a module author, you can find more specific information in the [Module Author's guide](/docs/guide/going-further/modules#testing).
|
|
8
|
+
If you are a module author, you can find more specific information in the [Module Author's guide](/docs/3.x/guide/going-further/modules#testing).
|
|
9
9
|
::
|
|
10
10
|
|
|
11
11
|
Nuxt offers first-class support for end-to-end and unit testing of your Nuxt application via `@nuxt/test-utils`, a library of test utilities and configuration that currently powers the [tests we use on Nuxt itself](https://github.com/nuxt/nuxt/tree/main/test) and tests throughout the module ecosystem.
|
|
@@ -46,8 +46,8 @@ We currently ship an environment for unit testing code that needs a [Nuxt](https
|
|
|
46
46
|
```ts twoslash
|
|
47
47
|
export default defineNuxtConfig({
|
|
48
48
|
modules: [
|
|
49
|
-
'@nuxt/test-utils/module'
|
|
50
|
-
]
|
|
49
|
+
'@nuxt/test-utils/module',
|
|
50
|
+
],
|
|
51
51
|
})
|
|
52
52
|
```
|
|
53
53
|
|
|
@@ -115,7 +115,7 @@ export default defineVitestConfig({
|
|
|
115
115
|
// }
|
|
116
116
|
// }
|
|
117
117
|
// }
|
|
118
|
-
}
|
|
118
|
+
},
|
|
119
119
|
})
|
|
120
120
|
```
|
|
121
121
|
|
|
@@ -199,10 +199,10 @@ export default defineVitestConfig({
|
|
|
199
199
|
mock: {
|
|
200
200
|
intersectionObserver: true,
|
|
201
201
|
indexedDb: true,
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
206
|
})
|
|
207
207
|
```
|
|
208
208
|
|
|
@@ -222,8 +222,9 @@ For example:
|
|
|
222
222
|
|
|
223
223
|
```ts twoslash
|
|
224
224
|
// @noErrors
|
|
225
|
-
import {
|
|
225
|
+
import { expect, it } from 'vitest'
|
|
226
226
|
import type { Component } from 'vue'
|
|
227
|
+
|
|
227
228
|
declare module '#components' {
|
|
228
229
|
export const SomeComponent: Component
|
|
229
230
|
}
|
|
@@ -233,17 +234,16 @@ import { mountSuspended } from '@nuxt/test-utils/runtime'
|
|
|
233
234
|
import { SomeComponent } from '#components'
|
|
234
235
|
|
|
235
236
|
it('can mount some component', async () => {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
237
|
+
const component = await mountSuspended(SomeComponent)
|
|
238
|
+
expect(component.text()).toMatchInlineSnapshot(
|
|
239
|
+
'"This is an auto-imported component"',
|
|
240
|
+
)
|
|
240
241
|
})
|
|
241
|
-
|
|
242
242
|
```
|
|
243
243
|
|
|
244
244
|
```ts twoslash
|
|
245
245
|
// @noErrors
|
|
246
|
-
import {
|
|
246
|
+
import { expect, it } from 'vitest'
|
|
247
247
|
// ---cut---
|
|
248
248
|
// tests/components/SomeComponents.nuxt.spec.ts
|
|
249
249
|
import { mountSuspended } from '@nuxt/test-utils/runtime'
|
|
@@ -251,8 +251,8 @@ import App from '~/app.vue'
|
|
|
251
251
|
|
|
252
252
|
// tests/App.nuxt.spec.ts
|
|
253
253
|
it('can also mount an app', async () => {
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
const component = await mountSuspended(App, { route: '/test' })
|
|
255
|
+
expect(component.html()).toMatchInlineSnapshot(`
|
|
256
256
|
"<div>This is an auto-imported component</div>
|
|
257
257
|
<div> I am a global component </div>
|
|
258
258
|
<div>/</div>
|
|
@@ -275,8 +275,9 @@ Examples:
|
|
|
275
275
|
|
|
276
276
|
```ts twoslash
|
|
277
277
|
// @noErrors
|
|
278
|
-
import {
|
|
278
|
+
import { expect, it } from 'vitest'
|
|
279
279
|
import type { Component } from 'vue'
|
|
280
|
+
|
|
280
281
|
declare module '#components' {
|
|
281
282
|
export const SomeComponent: Component
|
|
282
283
|
}
|
|
@@ -294,7 +295,7 @@ it('can render some component', async () => {
|
|
|
294
295
|
|
|
295
296
|
```ts twoslash
|
|
296
297
|
// @noErrors
|
|
297
|
-
import {
|
|
298
|
+
import { expect, it } from 'vitest'
|
|
298
299
|
// ---cut---
|
|
299
300
|
// tests/App.nuxt.spec.ts
|
|
300
301
|
import { renderSuspended } from '@nuxt/test-utils/runtime'
|
|
@@ -341,8 +342,8 @@ import { mockNuxtImport } from '@nuxt/test-utils/runtime'
|
|
|
341
342
|
const { useStorageMock } = vi.hoisted(() => {
|
|
342
343
|
return {
|
|
343
344
|
useStorageMock: vi.fn(() => {
|
|
344
|
-
return { value: 'mocked storage'}
|
|
345
|
-
})
|
|
345
|
+
return { value: 'mocked storage' }
|
|
346
|
+
}),
|
|
346
347
|
}
|
|
347
348
|
})
|
|
348
349
|
|
|
@@ -369,20 +370,20 @@ import { mockComponent } from '@nuxt/test-utils/runtime'
|
|
|
369
370
|
|
|
370
371
|
mockComponent('MyComponent', {
|
|
371
372
|
props: {
|
|
372
|
-
value: String
|
|
373
|
+
value: String,
|
|
373
374
|
},
|
|
374
|
-
setup(props) {
|
|
375
|
+
setup (props) {
|
|
375
376
|
// ...
|
|
376
|
-
}
|
|
377
|
+
},
|
|
377
378
|
})
|
|
378
379
|
|
|
379
380
|
// relative path or alias also works
|
|
380
|
-
mockComponent('~/components/my-component.vue',
|
|
381
|
+
mockComponent('~/components/my-component.vue', () => {
|
|
381
382
|
// or a factory function
|
|
382
383
|
return defineComponent({
|
|
383
|
-
setup(props) {
|
|
384
|
+
setup (props) {
|
|
384
385
|
// ...
|
|
385
|
-
}
|
|
386
|
+
},
|
|
386
387
|
})
|
|
387
388
|
})
|
|
388
389
|
|
|
@@ -401,10 +402,10 @@ mockComponent('MyComponent', async () => {
|
|
|
401
402
|
const { ref, h } = await import('vue')
|
|
402
403
|
|
|
403
404
|
return defineComponent({
|
|
404
|
-
setup(props) {
|
|
405
|
+
setup (props) {
|
|
405
406
|
const counter = ref(0)
|
|
406
407
|
return () => h('div', null, counter.value)
|
|
407
|
-
}
|
|
408
|
+
},
|
|
408
409
|
})
|
|
409
410
|
})
|
|
410
411
|
```
|
|
@@ -422,7 +423,7 @@ For example, to mock `/test/` endpoint, you can do:
|
|
|
422
423
|
import { registerEndpoint } from '@nuxt/test-utils/runtime'
|
|
423
424
|
|
|
424
425
|
registerEndpoint('/test/', () => ({
|
|
425
|
-
test: 'test-field'
|
|
426
|
+
test: 'test-field',
|
|
426
427
|
}))
|
|
427
428
|
```
|
|
428
429
|
|
|
@@ -433,11 +434,11 @@ import { registerEndpoint } from '@nuxt/test-utils/runtime'
|
|
|
433
434
|
|
|
434
435
|
registerEndpoint('/test/', {
|
|
435
436
|
method: 'POST',
|
|
436
|
-
handler: () => ({ test: 'test-field' })
|
|
437
|
+
handler: () => ({ test: 'test-field' }),
|
|
437
438
|
})
|
|
438
439
|
```
|
|
439
440
|
|
|
440
|
-
> **Note**: If your requests in a component go to an external API, you can use `baseURL` and then make it empty using [Nuxt Environment Override Config](/docs/getting-started/configuration#environment-overrides) (`$test`) so all your requests will go to Nitro server.
|
|
441
|
+
> **Note**: If your requests in a component go to an external API, you can use `baseURL` and then make it empty using [Nuxt Environment Override Config](/docs/3.x/getting-started/configuration#environment-overrides) (`$test`) so all your requests will go to Nitro server.
|
|
441
442
|
|
|
442
443
|
#### Conflict with End-To-End Testing
|
|
443
444
|
|
|
@@ -455,13 +456,12 @@ mockNuxtImport('useStorage', () => {
|
|
|
455
456
|
return { value: 'mocked storage' }
|
|
456
457
|
}
|
|
457
458
|
})
|
|
458
|
-
|
|
459
459
|
```
|
|
460
460
|
|
|
461
461
|
`app.e2e.spec.ts`
|
|
462
462
|
|
|
463
463
|
```ts twoslash
|
|
464
|
-
import {
|
|
464
|
+
import { $fetch, setup } from '@nuxt/test-utils/e2e'
|
|
465
465
|
|
|
466
466
|
await setup({
|
|
467
467
|
setupTimeout: 10000,
|
|
@@ -502,7 +502,7 @@ If you prefer to use `@vue/test-utils` on its own for unit testing in Nuxt, and
|
|
|
502
502
|
test: {
|
|
503
503
|
environment: 'happy-dom',
|
|
504
504
|
},
|
|
505
|
-
})
|
|
505
|
+
})
|
|
506
506
|
```
|
|
507
507
|
|
|
508
508
|
3. Add a new command for test in your `package.json`
|
|
@@ -527,7 +527,7 @@ If you prefer to use `@vue/test-utils` on its own for unit testing in Nuxt, and
|
|
|
527
527
|
5. Create a simple unit test for this newly created component `~/components/HelloWorld.spec.ts`
|
|
528
528
|
|
|
529
529
|
```ts twoslash
|
|
530
|
-
import { describe,
|
|
530
|
+
import { describe, expect, it } from 'vitest'
|
|
531
531
|
import { mount } from '@vue/test-utils'
|
|
532
532
|
|
|
533
533
|
import HelloWorld from './HelloWorld.vue'
|
|
@@ -569,7 +569,7 @@ In each `describe` block where you are taking advantage of the `@nuxt/test-utils
|
|
|
569
569
|
|
|
570
570
|
```ts twoslash [test/my-test.spec.ts]
|
|
571
571
|
import { describe, test } from 'vitest'
|
|
572
|
-
import {
|
|
572
|
+
import { $fetch, setup } from '@nuxt/test-utils/e2e'
|
|
573
573
|
|
|
574
574
|
describe('My test', async () => {
|
|
575
575
|
await setup({
|
|
@@ -648,8 +648,8 @@ For local development or automated deploy pipelines, testing against a separate
|
|
|
648
648
|
To utilize a separate target host for end-to-end tests, simply provide the `host` property of the `setup` function with the desired URL.
|
|
649
649
|
|
|
650
650
|
```ts twoslash
|
|
651
|
-
import {
|
|
652
|
-
import { describe,
|
|
651
|
+
import { createPage, setup } from '@nuxt/test-utils/e2e'
|
|
652
|
+
import { describe, expect, it } from 'vitest'
|
|
653
653
|
|
|
654
654
|
describe('login page', async () => {
|
|
655
655
|
await setup({
|
|
@@ -742,8 +742,8 @@ import type { ConfigOptions } from '@nuxt/test-utils/playwright'
|
|
|
742
742
|
export default defineConfig<ConfigOptions>({
|
|
743
743
|
use: {
|
|
744
744
|
nuxt: {
|
|
745
|
-
rootDir: fileURLToPath(new URL('.', import.meta.url))
|
|
746
|
-
}
|
|
745
|
+
rootDir: fileURLToPath(new URL('.', import.meta.url)),
|
|
746
|
+
},
|
|
747
747
|
},
|
|
748
748
|
// ...
|
|
749
749
|
})
|
|
@@ -770,8 +770,8 @@ import { expect, test } from '@nuxt/test-utils/playwright'
|
|
|
770
770
|
|
|
771
771
|
test.use({
|
|
772
772
|
nuxt: {
|
|
773
|
-
rootDir: fileURLToPath(new URL('..', import.meta.url))
|
|
774
|
-
}
|
|
773
|
+
rootDir: fileURLToPath(new URL('..', import.meta.url)),
|
|
774
|
+
},
|
|
775
775
|
})
|
|
776
776
|
|
|
777
777
|
test('test', async ({ page, goto }) => {
|