@nuxt/docs 0.0.0 → 3.17.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/.navigation.yml +2 -0
- package/1.getting-started/.navigation.yml +3 -0
- package/1.getting-started/01.introduction.md +81 -0
- package/1.getting-started/02.installation.md +109 -0
- package/1.getting-started/03.configuration.md +226 -0
- package/1.getting-started/04.views.md +163 -0
- package/1.getting-started/05.assets.md +48 -0
- package/1.getting-started/06.styling.md +565 -0
- package/1.getting-started/07.routing.md +149 -0
- package/1.getting-started/08.seo-meta.md +360 -0
- package/1.getting-started/09.transitions.md +473 -0
- package/1.getting-started/10.data-fetching.md +795 -0
- package/1.getting-started/11.state-management.md +223 -0
- package/1.getting-started/12.error-handling.md +233 -0
- package/1.getting-started/13.server.md +94 -0
- package/1.getting-started/14.layers.md +92 -0
- package/1.getting-started/15.prerendering.md +194 -0
- package/1.getting-started/16.deployment.md +130 -0
- package/1.getting-started/17.testing.md +728 -0
- package/1.getting-started/18.upgrade.md +997 -0
- package/2.guide/.navigation.yml +2 -0
- package/2.guide/0.index.md +22 -0
- package/2.guide/1.concepts/.navigation.yml +3 -0
- package/2.guide/1.concepts/1.auto-imports.md +205 -0
- package/2.guide/1.concepts/10.nuxt-lifecycle.md +141 -0
- package/2.guide/1.concepts/2.vuejs-development.md +103 -0
- package/2.guide/1.concepts/3.rendering.md +255 -0
- package/2.guide/1.concepts/4.server-engine.md +62 -0
- package/2.guide/1.concepts/5.modules.md +48 -0
- package/2.guide/1.concepts/7.esm.md +299 -0
- package/2.guide/1.concepts/8.typescript.md +97 -0
- package/2.guide/1.concepts/9.code-style.md +22 -0
- package/2.guide/2.directory-structure/.navigation.yml +3 -0
- package/2.guide/2.directory-structure/0.nuxt.md +20 -0
- package/2.guide/2.directory-structure/0.output.md +18 -0
- package/2.guide/2.directory-structure/1.assets.md +16 -0
- package/2.guide/2.directory-structure/1.components.md +608 -0
- package/2.guide/2.directory-structure/1.composables.md +121 -0
- package/2.guide/2.directory-structure/1.content.md +64 -0
- package/2.guide/2.directory-structure/1.layouts.md +180 -0
- package/2.guide/2.directory-structure/1.middleware.md +209 -0
- package/2.guide/2.directory-structure/1.modules.md +66 -0
- package/2.guide/2.directory-structure/1.node_modules.md +12 -0
- package/2.guide/2.directory-structure/1.pages.md +440 -0
- package/2.guide/2.directory-structure/1.plugins.md +299 -0
- package/2.guide/2.directory-structure/1.public.md +27 -0
- package/2.guide/2.directory-structure/1.server.md +546 -0
- package/2.guide/2.directory-structure/1.shared.md +104 -0
- package/2.guide/2.directory-structure/1.utils.md +49 -0
- package/2.guide/2.directory-structure/2.env.md +75 -0
- package/2.guide/2.directory-structure/2.gitignore.md +37 -0
- package/2.guide/2.directory-structure/2.nuxtignore.md +36 -0
- package/2.guide/2.directory-structure/2.nuxtrc.md +50 -0
- package/2.guide/2.directory-structure/3.app-config.md +177 -0
- package/2.guide/2.directory-structure/3.app.md +72 -0
- package/2.guide/2.directory-structure/3.error.md +55 -0
- package/2.guide/2.directory-structure/3.nuxt-config.md +34 -0
- package/2.guide/2.directory-structure/3.package.md +32 -0
- package/2.guide/2.directory-structure/3.tsconfig.md +24 -0
- package/2.guide/3.going-further/.navigation.yml +3 -0
- package/2.guide/3.going-further/1.experimental-features.md +689 -0
- package/2.guide/3.going-further/1.features.md +103 -0
- package/2.guide/3.going-further/1.internals.md +81 -0
- package/2.guide/3.going-further/10.runtime-config.md +174 -0
- package/2.guide/3.going-further/11.nightly-release-channel.md +68 -0
- package/2.guide/3.going-further/2.hooks.md +98 -0
- package/2.guide/3.going-further/3.modules.md +811 -0
- package/2.guide/3.going-further/4.kit.md +51 -0
- package/2.guide/3.going-further/6.nuxt-app.md +64 -0
- package/2.guide/3.going-further/7.layers.md +227 -0
- package/2.guide/3.going-further/9.debugging.md +115 -0
- package/2.guide/3.going-further/index.md +4 -0
- package/2.guide/4.recipes/.navigation.yml +3 -0
- package/2.guide/4.recipes/1.custom-routing.md +181 -0
- package/2.guide/4.recipes/2.vite-plugin.md +65 -0
- package/2.guide/4.recipes/3.custom-usefetch.md +125 -0
- package/2.guide/4.recipes/4.sessions-and-authentication.md +203 -0
- package/3.api/.navigation.yml +3 -0
- package/3.api/1.components/.navigation.yml +3 -0
- package/3.api/1.components/1.client-only.md +76 -0
- package/3.api/1.components/1.dev-only.md +51 -0
- package/3.api/1.components/1.nuxt-client-fallback.md +80 -0
- package/3.api/1.components/10.nuxt-picture.md +27 -0
- package/3.api/1.components/11.teleports.md +40 -0
- package/3.api/1.components/12.nuxt-route-announcer.md +56 -0
- package/3.api/1.components/13.nuxt-time.md +173 -0
- package/3.api/1.components/2.nuxt-page.md +154 -0
- package/3.api/1.components/3.nuxt-layout.md +156 -0
- package/3.api/1.components/4.nuxt-link.md +322 -0
- package/3.api/1.components/5.nuxt-loading-indicator.md +50 -0
- package/3.api/1.components/6.nuxt-error-boundary.md +65 -0
- package/3.api/1.components/7.nuxt-welcome.md +25 -0
- package/3.api/1.components/8.nuxt-island.md +70 -0
- package/3.api/1.components/9.nuxt-img.md +43 -0
- package/3.api/2.composables/.navigation.yml +3 -0
- package/3.api/2.composables/on-prehydrate.md +60 -0
- package/3.api/2.composables/use-app-config.md +19 -0
- package/3.api/2.composables/use-async-data.md +212 -0
- package/3.api/2.composables/use-cookie.md +233 -0
- package/3.api/2.composables/use-error.md +32 -0
- package/3.api/2.composables/use-fetch.md +217 -0
- package/3.api/2.composables/use-head-safe.md +55 -0
- package/3.api/2.composables/use-head.md +69 -0
- package/3.api/2.composables/use-hydration.md +68 -0
- package/3.api/2.composables/use-lazy-async-data.md +47 -0
- package/3.api/2.composables/use-lazy-fetch.md +55 -0
- package/3.api/2.composables/use-loading-indicator.md +77 -0
- package/3.api/2.composables/use-nuxt-app.md +294 -0
- package/3.api/2.composables/use-nuxt-data.md +112 -0
- package/3.api/2.composables/use-preview-mode.md +118 -0
- package/3.api/2.composables/use-request-event.md +23 -0
- package/3.api/2.composables/use-request-fetch.md +52 -0
- package/3.api/2.composables/use-request-header.md +34 -0
- package/3.api/2.composables/use-request-headers.md +37 -0
- package/3.api/2.composables/use-request-url.md +41 -0
- package/3.api/2.composables/use-response-header.md +48 -0
- package/3.api/2.composables/use-route-announcer.md +60 -0
- package/3.api/2.composables/use-route.md +52 -0
- package/3.api/2.composables/use-router.md +92 -0
- package/3.api/2.composables/use-runtime-config.md +142 -0
- package/3.api/2.composables/use-runtime-hook.md +43 -0
- package/3.api/2.composables/use-seo-meta.md +80 -0
- package/3.api/2.composables/use-server-seo-meta.md +27 -0
- package/3.api/2.composables/use-state.md +48 -0
- package/3.api/3.utils/$fetch.md +98 -0
- package/3.api/3.utils/.navigation.yml +3 -0
- package/3.api/3.utils/abort-navigation.md +73 -0
- package/3.api/3.utils/add-route-middleware.md +88 -0
- package/3.api/3.utils/call-once.md +92 -0
- package/3.api/3.utils/clear-error.md +29 -0
- package/3.api/3.utils/clear-nuxt-data.md +23 -0
- package/3.api/3.utils/clear-nuxt-state.md +23 -0
- package/3.api/3.utils/create-error.md +55 -0
- package/3.api/3.utils/define-nuxt-component.md +53 -0
- package/3.api/3.utils/define-nuxt-route-middleware.md +67 -0
- package/3.api/3.utils/define-page-meta.md +234 -0
- package/3.api/3.utils/define-route-rules.md +52 -0
- package/3.api/3.utils/navigate-to.md +230 -0
- package/3.api/3.utils/on-before-route-leave.md +11 -0
- package/3.api/3.utils/on-before-route-update.md +11 -0
- package/3.api/3.utils/on-nuxt-ready.md +25 -0
- package/3.api/3.utils/prefetch-components.md +28 -0
- package/3.api/3.utils/preload-components.md +23 -0
- package/3.api/3.utils/preload-route-components.md +41 -0
- package/3.api/3.utils/prerender-routes.md +46 -0
- package/3.api/3.utils/refresh-cookie.md +46 -0
- package/3.api/3.utils/refresh-nuxt-data.md +91 -0
- package/3.api/3.utils/reload-nuxt-app.md +74 -0
- package/3.api/3.utils/set-page-layout.md +24 -0
- package/3.api/3.utils/set-response-status.md +36 -0
- package/3.api/3.utils/show-error.md +31 -0
- package/3.api/3.utils/update-app-config.md +27 -0
- package/3.api/4.commands/.navigation.yml +3 -0
- package/3.api/4.commands/add.md +112 -0
- package/3.api/4.commands/analyze.md +41 -0
- package/3.api/4.commands/build-module.md +42 -0
- package/3.api/4.commands/build.md +46 -0
- package/3.api/4.commands/cleanup.md +38 -0
- package/3.api/4.commands/dev.md +59 -0
- package/3.api/4.commands/devtools.md +38 -0
- package/3.api/4.commands/generate.md +41 -0
- package/3.api/4.commands/info.md +33 -0
- package/3.api/4.commands/init.md +46 -0
- package/3.api/4.commands/module.md +84 -0
- package/3.api/4.commands/prepare.md +36 -0
- package/3.api/4.commands/preview.md +43 -0
- package/3.api/4.commands/typecheck.md +42 -0
- package/3.api/4.commands/upgrade.md +37 -0
- package/3.api/5.kit/.navigation.yml +3 -0
- package/3.api/5.kit/1.modules.md +172 -0
- package/3.api/5.kit/10.runtime-config.md +27 -0
- package/3.api/5.kit/10.templates.md +283 -0
- package/3.api/5.kit/11.nitro.md +409 -0
- package/3.api/5.kit/12.resolving.md +268 -0
- package/3.api/5.kit/13.logging.md +65 -0
- package/3.api/5.kit/14.builder.md +491 -0
- package/3.api/5.kit/15.examples.md +41 -0
- package/3.api/5.kit/2.programmatic.md +125 -0
- package/3.api/5.kit/3.compatibility.md +230 -0
- package/3.api/5.kit/4.autoimports.md +144 -0
- package/3.api/5.kit/5.components.md +127 -0
- package/3.api/5.kit/6.context.md +130 -0
- package/3.api/5.kit/7.pages.md +295 -0
- package/3.api/5.kit/8.layout.md +80 -0
- package/3.api/5.kit/9.plugins.md +263 -0
- package/3.api/6.advanced/.navigation.yml +1 -0
- package/3.api/6.advanced/1.hooks.md +105 -0
- package/3.api/6.advanced/2.import-meta.md +60 -0
- package/3.api/6.nuxt-config.md +12 -0
- package/3.api/index.md +31 -0
- package/5.community/.navigation.yml +3 -0
- package/5.community/2.getting-help.md +48 -0
- package/5.community/3.reporting-bugs.md +50 -0
- package/5.community/4.contribution.md +205 -0
- package/5.community/5.framework-contribution.md +142 -0
- package/5.community/6.roadmap.md +79 -0
- package/5.community/7.changelog.md +92 -0
- package/6.bridge/.navigation.yml +3 -0
- package/6.bridge/1.overview.md +137 -0
- package/6.bridge/10.configuration.md +96 -0
- package/6.bridge/2.typescript.md +46 -0
- package/6.bridge/3.bridge-composition-api.md +132 -0
- package/6.bridge/4.plugins-and-middleware.md +65 -0
- package/6.bridge/5.nuxt3-compatible-api.md +204 -0
- package/6.bridge/6.meta.md +117 -0
- package/6.bridge/7.runtime-config.md +38 -0
- package/6.bridge/8.nitro.md +102 -0
- package/6.bridge/9.vite.md +37 -0
- package/7.migration/.navigation.yml +3 -0
- package/7.migration/1.overview.md +24 -0
- package/7.migration/10.bundling.md +28 -0
- package/7.migration/11.server.md +17 -0
- package/7.migration/2.configuration.md +240 -0
- package/7.migration/20.module-authors.md +94 -0
- package/7.migration/3.auto-imports.md +18 -0
- package/7.migration/4.meta.md +127 -0
- package/7.migration/5.plugins-and-middleware.md +80 -0
- package/7.migration/6.pages-and-layouts.md +233 -0
- package/7.migration/7.component-options.md +156 -0
- package/7.migration/8.runtime-config.md +58 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/package.json +16 -4
- package/dist/.gitkeep +0 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Compatibility"
|
|
3
|
+
description: Nuxt Kit provides a set of utilities to help you check the compatibility of your modules with different Nuxt versions.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/kit/src/compatibility.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Nuxt Kit utilities can be used in Nuxt 3, Nuxt 2 with Bridge and even Nuxt 2 without Bridge. To make sure your module is compatible with all versions, you can use the `checkNuxtCompatibility`, `assertNuxtCompatibility` and `hasNuxtCompatibility` functions. They will check if the current Nuxt version meets the constraints you provide. Also you can use `isNuxt2`, `isNuxt3` and `getNuxtVersion` functions for more granular checks.
|
|
12
|
+
|
|
13
|
+
## `checkNuxtCompatibility`
|
|
14
|
+
|
|
15
|
+
Checks if constraints are met for the current Nuxt version. If not, returns an array of messages. Nuxt 2 version also checks for `bridge` support.
|
|
16
|
+
|
|
17
|
+
### Type
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
async function checkNuxtCompatibility(
|
|
21
|
+
constraints: NuxtCompatibility,
|
|
22
|
+
nuxt?: Nuxt
|
|
23
|
+
): Promise<NuxtCompatibilityIssues>;
|
|
24
|
+
|
|
25
|
+
interface NuxtCompatibility {
|
|
26
|
+
nuxt?: string;
|
|
27
|
+
bridge?: boolean;
|
|
28
|
+
builder?: {
|
|
29
|
+
// Set `false` if your module is not compatible with a builder
|
|
30
|
+
// or a semver-compatible string version constraint
|
|
31
|
+
vite?: false | string;
|
|
32
|
+
webpack?: false | string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface NuxtCompatibilityIssue {
|
|
37
|
+
name: string;
|
|
38
|
+
message: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface NuxtCompatibilityIssues extends Array<NuxtCompatibilityIssue> {
|
|
42
|
+
toString(): string;
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Parameters
|
|
47
|
+
|
|
48
|
+
#### `constraints`
|
|
49
|
+
|
|
50
|
+
**Type**: `NuxtCompatibility`
|
|
51
|
+
|
|
52
|
+
**Default**: `{}`
|
|
53
|
+
|
|
54
|
+
Constraints to check for. It accepts the following properties:
|
|
55
|
+
|
|
56
|
+
- `nuxt` (optional)
|
|
57
|
+
|
|
58
|
+
**Type**: `string`
|
|
59
|
+
|
|
60
|
+
Nuxt version in semver format. Versions may be defined in Node.js way, for example: `>=2.15.0 <3.0.0`.
|
|
61
|
+
|
|
62
|
+
- `bridge` (optional)
|
|
63
|
+
|
|
64
|
+
**Type**: `boolean`
|
|
65
|
+
|
|
66
|
+
If set to `true`, it will check if the current Nuxt version supports `bridge`.
|
|
67
|
+
|
|
68
|
+
#### `nuxt`
|
|
69
|
+
|
|
70
|
+
**Type**: `Nuxt`
|
|
71
|
+
|
|
72
|
+
**Default**: `useNuxt()`
|
|
73
|
+
|
|
74
|
+
Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
|
|
75
|
+
|
|
76
|
+
## `assertNuxtCompatibility`
|
|
77
|
+
|
|
78
|
+
Asserts that constraints are met for the current Nuxt version. If not, throws an error with the list of issues as string.
|
|
79
|
+
|
|
80
|
+
### Type
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
async function assertNuxtCompatibility(
|
|
84
|
+
constraints: NuxtCompatibility,
|
|
85
|
+
nuxt?: Nuxt
|
|
86
|
+
): Promise<true>;
|
|
87
|
+
|
|
88
|
+
interface NuxtCompatibility {
|
|
89
|
+
nuxt?: string;
|
|
90
|
+
bridge?: boolean;
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Parameters
|
|
95
|
+
|
|
96
|
+
#### `constraints`
|
|
97
|
+
|
|
98
|
+
**Type**: `NuxtCompatibility`
|
|
99
|
+
|
|
100
|
+
**Default**: `{}`
|
|
101
|
+
|
|
102
|
+
Constraints to check for. It accepts the following properties:
|
|
103
|
+
|
|
104
|
+
- `nuxt` (optional)
|
|
105
|
+
|
|
106
|
+
**Type**: `string`
|
|
107
|
+
|
|
108
|
+
Nuxt version in semver format. Versions may be defined in Node.js way, for example: `>=2.15.0 <3.0.0`.
|
|
109
|
+
|
|
110
|
+
- `bridge` (optional)
|
|
111
|
+
|
|
112
|
+
**Type**: `boolean`
|
|
113
|
+
|
|
114
|
+
If set to `true`, it will check if the current Nuxt version supports `bridge`.
|
|
115
|
+
|
|
116
|
+
#### `nuxt`
|
|
117
|
+
|
|
118
|
+
**Type**: `Nuxt`
|
|
119
|
+
|
|
120
|
+
**Default**: `useNuxt()`
|
|
121
|
+
|
|
122
|
+
Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
|
|
123
|
+
|
|
124
|
+
## `hasNuxtCompatibility`
|
|
125
|
+
|
|
126
|
+
Checks if constraints are met for the current Nuxt version. Return `true` if all constraints are met, otherwise returns `false`. Nuxt 2 version also checks for `bridge` support.
|
|
127
|
+
|
|
128
|
+
### Type
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
async function hasNuxtCompatibility(
|
|
132
|
+
constraints: NuxtCompatibility,
|
|
133
|
+
nuxt?: Nuxt
|
|
134
|
+
): Promise<boolean>;
|
|
135
|
+
|
|
136
|
+
interface NuxtCompatibility {
|
|
137
|
+
nuxt?: string;
|
|
138
|
+
bridge?: boolean;
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Parameters
|
|
143
|
+
|
|
144
|
+
#### `constraints`
|
|
145
|
+
|
|
146
|
+
**Type**: `NuxtCompatibility`
|
|
147
|
+
|
|
148
|
+
**Default**: `{}`
|
|
149
|
+
|
|
150
|
+
Constraints to check for. It accepts the following properties:
|
|
151
|
+
|
|
152
|
+
- `nuxt` (optional)
|
|
153
|
+
|
|
154
|
+
**Type**: `string`
|
|
155
|
+
|
|
156
|
+
Nuxt version in semver format. Versions may be defined in Node.js way, for example: `>=2.15.0 <3.0.0`.
|
|
157
|
+
|
|
158
|
+
- `bridge` (optional)
|
|
159
|
+
|
|
160
|
+
**Type**: `boolean`
|
|
161
|
+
|
|
162
|
+
If set to `true`, it will check if the current Nuxt version supports `bridge`.
|
|
163
|
+
|
|
164
|
+
#### `nuxt`
|
|
165
|
+
|
|
166
|
+
**Type**: `Nuxt`
|
|
167
|
+
|
|
168
|
+
**Default**: `useNuxt()`
|
|
169
|
+
|
|
170
|
+
Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
|
|
171
|
+
|
|
172
|
+
## `isNuxt2`
|
|
173
|
+
|
|
174
|
+
Checks if the current Nuxt version is 2.x.
|
|
175
|
+
|
|
176
|
+
### Type
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
function isNuxt2(nuxt?: Nuxt): boolean;
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Parameters
|
|
183
|
+
|
|
184
|
+
#### `nuxt`
|
|
185
|
+
|
|
186
|
+
**Type**: `Nuxt`
|
|
187
|
+
|
|
188
|
+
**Default**: `useNuxt()`
|
|
189
|
+
|
|
190
|
+
Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
|
|
191
|
+
|
|
192
|
+
## `isNuxt3`
|
|
193
|
+
|
|
194
|
+
Checks if the current Nuxt version is 3.x.
|
|
195
|
+
|
|
196
|
+
### Type
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
function isNuxt3(nuxt?: Nuxt): boolean;
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Parameters
|
|
203
|
+
|
|
204
|
+
#### `nuxt`
|
|
205
|
+
|
|
206
|
+
**Type**: `Nuxt`
|
|
207
|
+
|
|
208
|
+
**Default**: `useNuxt()`
|
|
209
|
+
|
|
210
|
+
Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
|
|
211
|
+
|
|
212
|
+
## `getNuxtVersion`
|
|
213
|
+
|
|
214
|
+
Returns the current Nuxt version.
|
|
215
|
+
|
|
216
|
+
### Type
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
function getNuxtVersion(nuxt?: Nuxt): string;
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Parameters
|
|
223
|
+
|
|
224
|
+
#### `nuxt`
|
|
225
|
+
|
|
226
|
+
**Type**: `Nuxt`
|
|
227
|
+
|
|
228
|
+
**Default**: `useNuxt()`
|
|
229
|
+
|
|
230
|
+
Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Auto-imports"
|
|
3
|
+
description: Nuxt Kit provides a set of utilities to help you work with auto-imports. These functions allow you to register your own utils, composables and Vue APIs.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/kit/src/imports.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Nuxt auto-imports helper functions, composables and Vue APIs to use across your application without explicitly importing them. Based on the directory structure, every Nuxt application can also use auto-imports for its own composables and plugins.
|
|
12
|
+
|
|
13
|
+
With Nuxt Kit you can also add your own auto-imports. `addImports` and `addImportsDir` allow you to add imports to the Nuxt application. `addImportsSources` allows you to add listed imports from 3rd party packages to the Nuxt application.
|
|
14
|
+
|
|
15
|
+
These utilities are powered by [`unimport`](https://github.com/unjs/unimport), which provides the underlying auto-import mechanism used in Nuxt.
|
|
16
|
+
|
|
17
|
+
::note
|
|
18
|
+
These functions are designed for registering your own utils, composables and Vue APIs. For pages, components and plugins, please refer to the specific sections: [Pages](/docs/api/kit/pages), [Components](/docs/api/kit/components), [Plugins](/docs/api/kit/plugins).
|
|
19
|
+
::
|
|
20
|
+
|
|
21
|
+
::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/expanding-nuxt-s-auto-imports?friend=nuxt" target="_blank"}
|
|
22
|
+
Watch Vue School video about Auto-imports Nuxt Kit utilities.
|
|
23
|
+
::
|
|
24
|
+
|
|
25
|
+
## `addImports`
|
|
26
|
+
|
|
27
|
+
Add imports to the Nuxt application. It makes your imports available in the Nuxt application without the need to import them manually.
|
|
28
|
+
|
|
29
|
+
### Usage
|
|
30
|
+
|
|
31
|
+
```ts twoslash
|
|
32
|
+
import { defineNuxtModule, addImports } from "@nuxt/kit";
|
|
33
|
+
|
|
34
|
+
export default defineNuxtModule({
|
|
35
|
+
setup(options, nuxt) {
|
|
36
|
+
const names = [
|
|
37
|
+
"useStoryblok",
|
|
38
|
+
"useStoryblokApi",
|
|
39
|
+
"useStoryblokBridge",
|
|
40
|
+
"renderRichText",
|
|
41
|
+
"RichTextSchema"
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
names.forEach((name) =>
|
|
45
|
+
addImports({ name, as: name, from: "@storyblok/vue" })
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Type
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
function addImports (imports: Import | Import[]): void
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Parameters
|
|
58
|
+
|
|
59
|
+
`imports`: An object or an array of objects with the following properties:
|
|
60
|
+
|
|
61
|
+
| Prop | Type | Required | Description |
|
|
62
|
+
| ------------------ | ---------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |
|
|
63
|
+
| `name` | `string` | `true` | Import name to be detected. |
|
|
64
|
+
| `from` | `string` | `true` | Module specifier to import from. |
|
|
65
|
+
| `priority` | `number` | `false` | Priority of the import; if multiple imports have the same name, the one with the highest priority will be used. |
|
|
66
|
+
| `disabled` | `boolean` | `false` | If this import is disabled. |
|
|
67
|
+
| `meta` | `Record<string, any>` | `false` | Metadata of the import. |
|
|
68
|
+
| `type` | `boolean` | `false` | If this import is a pure type import. |
|
|
69
|
+
| `typeFrom` | `string` | `false` | Use this as the `from` value when generating type declarations. |
|
|
70
|
+
| `as` | `string` | `false` | Import as this name. |
|
|
71
|
+
|
|
72
|
+
## `addImportsDir`
|
|
73
|
+
|
|
74
|
+
Add imports from a directory to the Nuxt application. It will automatically import all files from the directory and make them available in the Nuxt application without the need to import them manually.
|
|
75
|
+
|
|
76
|
+
### Usage
|
|
77
|
+
|
|
78
|
+
```ts twoslash
|
|
79
|
+
import { defineNuxtModule, addImportsDir, createResolver } from '@nuxt/kit'
|
|
80
|
+
|
|
81
|
+
export default defineNuxtModule({
|
|
82
|
+
meta: {
|
|
83
|
+
name: '@vueuse/motion',
|
|
84
|
+
configKey: 'motion',
|
|
85
|
+
},
|
|
86
|
+
setup(options, nuxt) {
|
|
87
|
+
const resolver = createResolver(import.meta.url)
|
|
88
|
+
addImportsDir(resolver.resolve('./runtime/composables'))
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Type
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
function addImportsDir (dirs: string | string[], options?: { prepend?: boolean }): void
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Parameters
|
|
100
|
+
|
|
101
|
+
| Prop | Type | Required | Description |
|
|
102
|
+
| ------------------ | ---------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |
|
|
103
|
+
| `dirs` | `string \| string[]`{lang="ts"} | `true` | A string or an array of strings with the path to the directory to import from. |
|
|
104
|
+
| `options` | `{ prepend?: boolean }`{lang="ts"} | `false` | Options to pass to the import. If `prepend` is set to `true`, the imports will be prepended to the list of imports. |
|
|
105
|
+
|
|
106
|
+
## `addImportsSources`
|
|
107
|
+
|
|
108
|
+
Add listed imports to the Nuxt application.
|
|
109
|
+
|
|
110
|
+
### Usage
|
|
111
|
+
|
|
112
|
+
```ts twoslash
|
|
113
|
+
import { defineNuxtModule, addImportsSources } from '@nuxt/kit'
|
|
114
|
+
|
|
115
|
+
export default defineNuxtModule({
|
|
116
|
+
setup() {
|
|
117
|
+
addImportsSources({
|
|
118
|
+
from: 'h3',
|
|
119
|
+
imports: [
|
|
120
|
+
'defineEventHandler',
|
|
121
|
+
'getQuery',
|
|
122
|
+
'getRouterParams',
|
|
123
|
+
'readBody',
|
|
124
|
+
'sendRedirect'
|
|
125
|
+
],
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Type
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
function addImportsSources (importSources: ImportSource | ImportSource[]): void
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Parameters
|
|
138
|
+
|
|
139
|
+
**importSources**: An object or an array of objects with the following properties:
|
|
140
|
+
|
|
141
|
+
| Prop | Type | Required | Description |
|
|
142
|
+
| ------------------ | ---------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |
|
|
143
|
+
| `from` | `string` | `true` | Module specifier to import from. |
|
|
144
|
+
| `imports` | `PresetImport \| ImportSource[]`{lang="ts"} | `true` | An object or an array of objects, which can be import names, import objects or import sources. |
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Components"
|
|
3
|
+
description: Nuxt Kit provides a set of utilities to help you work with components. You can register components globally or locally, and also add directories to be scanned for components.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/kit/src/components.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Components are the building blocks of your Nuxt application. They are reusable Vue instances that can be used to create a user interface. In Nuxt, components from the components directory are automatically imported by default. However, if you need to import components from an alternative directory or wish to selectively import them as needed, `@nuxt/kit` provides the `addComponentsDir` and `addComponent` methods. These utils allow you to customize the component configuration to better suit your needs.
|
|
12
|
+
|
|
13
|
+
::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/injecting-components-and-component-directories?friend=nuxt" target="_blank"}
|
|
14
|
+
Watch Vue School video about injecting components.
|
|
15
|
+
::
|
|
16
|
+
|
|
17
|
+
## `addComponentsDir`
|
|
18
|
+
|
|
19
|
+
Register a directory to be scanned for components and imported only when used. Keep in mind, that this does not register components globally, until you specify `global: true` option.
|
|
20
|
+
|
|
21
|
+
### Usage
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
export default defineNuxtModule({
|
|
25
|
+
meta: {
|
|
26
|
+
name: '@nuxt/ui',
|
|
27
|
+
configKey: 'ui',
|
|
28
|
+
},
|
|
29
|
+
setup() {
|
|
30
|
+
addComponentsDir({
|
|
31
|
+
path: resolve('./runtime/components'),
|
|
32
|
+
prefix: 'U',
|
|
33
|
+
pathPrefix: false
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Type
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
function addComponentsDir (dir: ComponentsDir, opts: { prepend?: boolean } = {}): void
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Parameters
|
|
46
|
+
|
|
47
|
+
`dir` An object with the following properties:
|
|
48
|
+
|
|
49
|
+
| Prop | Type | Required | Description |
|
|
50
|
+
| ------------------ | ---------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |
|
|
51
|
+
| `path` | `string` | `true` | Path (absolute or relative) to the directory containing your components. You can use Nuxt aliases (~ or @) to refer to directories inside project or directly use an npm package path similar to require. |
|
|
52
|
+
| `pattern` | `string \| string[]`{lang="ts"} | `false` | Accept Pattern that will be run against specified path. |
|
|
53
|
+
| `ignore` | `string[]` | `false` | Ignore patterns that will be run against specified path. |
|
|
54
|
+
| `prefix` | `string` | `false` | Prefix all matched components with this string. |
|
|
55
|
+
| `pathPrefix` | `boolean` | `false` | Prefix component name by its path. |
|
|
56
|
+
| `enabled` | `boolean` | `false` | Ignore scanning this directory if set to `true`. |
|
|
57
|
+
| `prefetch` | `boolean` | `false` | These properties (prefetch/preload) are used in production to configure how components with Lazy prefix are handled by webpack via its magic comments. Learn more on [webpack documentation](https://webpack.js.org/api/module-methods/#magic-comments) |
|
|
58
|
+
| `preload` | `boolean` | `false` | These properties (prefetch/preload) are used in production to configure how components with Lazy prefix are handled by webpack via its magic comments. Learn more on [webpack documentation](https://webpack.js.org/api/module-methods/#magic-comments) |
|
|
59
|
+
| `isAsync` | `boolean` | `false` | This flag indicates, component should be loaded async (with a separate chunk) regardless of using Lazy prefix or not. |
|
|
60
|
+
| `extendComponent` | `(component: Component) => Promise<Component \| void> \| (Component \| void)`{lang="ts"} | `false` | A function that will be called for each component found in the directory. It accepts a component object and should return a component object or a promise that resolves to a component object. |
|
|
61
|
+
| `global` | `boolean` | `false` | If enabled, registers components to be globally available. |
|
|
62
|
+
| `island` | `boolean` | `false` | If enabled, registers components as islands. You can read more about islands in [`<NuxtIsland/>`](/docs/api/components/nuxt-island#nuxtisland) component description. |
|
|
63
|
+
| `watch` | `boolean` | `false` | Watch specified path for changes, including file additions and file deletions. |
|
|
64
|
+
| `extensions` | `string[]` | `false` | Extensions supported by Nuxt builder. |
|
|
65
|
+
| `transpile` | `'auto' \| boolean`{lang="ts"} | `false` | Transpile specified path using build.transpile. If set to `'auto'`, it will set `transpile: true` if `node_modules/` is in path. |
|
|
66
|
+
|
|
67
|
+
`opts`
|
|
68
|
+
|
|
69
|
+
| Prop | Type | Required | Description |
|
|
70
|
+
| ------------------ | ---------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |
|
|
71
|
+
| `prepend` | `boolean` | `false` | If set to `true`, the directory will be prepended to the array with `unshift()` instead of `push()`. |
|
|
72
|
+
|
|
73
|
+
## `addComponent`
|
|
74
|
+
|
|
75
|
+
Register a component to be automatically imported.
|
|
76
|
+
|
|
77
|
+
### Usage
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { defineNuxtModule, createResolver, addComponent } from '@nuxt/kit'
|
|
81
|
+
|
|
82
|
+
export default defineNuxtModule({
|
|
83
|
+
meta: {
|
|
84
|
+
name: '@nuxt/image',
|
|
85
|
+
configKey: 'image',
|
|
86
|
+
},
|
|
87
|
+
async setup() {
|
|
88
|
+
const resolver = createResolver(import.meta.url)
|
|
89
|
+
|
|
90
|
+
addComponent({
|
|
91
|
+
name: 'NuxtImg',
|
|
92
|
+
filePath: resolver.resolve('./runtime/components/NuxtImg.vue'),
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
addComponent({
|
|
96
|
+
name: 'NuxtPicture',
|
|
97
|
+
filePath: resolver.resolve('./runtime/components/NuxtPicture.vue'),
|
|
98
|
+
})
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Type
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
function addComponent (options: AddComponentOptions): void
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Parameters
|
|
110
|
+
|
|
111
|
+
`options`: An object with the following properties:
|
|
112
|
+
|
|
113
|
+
| Prop | Type | Required | Description |
|
|
114
|
+
| ------------------ | ---------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |
|
|
115
|
+
| `name` | `string` | `true` | Component name. |
|
|
116
|
+
| `filePath` | `string` | `true` | Path to the component. |
|
|
117
|
+
| `pascalName` | `string` | `false` | Pascal case component name. If not provided, it will be generated from the component name. |
|
|
118
|
+
| `kebabName` | `string` | `false` | Kebab case component name. If not provided, it will be generated from the component name. |
|
|
119
|
+
| `export` | `string` | `false` | Specify named or default export. If not provided, it will be set to `'default'`. |
|
|
120
|
+
| `shortPath` | `string` | `false` | Short path to the component. If not provided, it will be generated from the component path. |
|
|
121
|
+
| `chunkName` | `string` | `false` | Chunk name for the component. If not provided, it will be generated from the component name. |
|
|
122
|
+
| `prefetch` | `boolean` | `false` | These properties (prefetch/preload) are used in production to configure how components with Lazy prefix are handled by webpack via its magic comments. Learn more on [webpack documentation](https://webpack.js.org/api/module-methods/#magic-comments) |
|
|
123
|
+
| `preload` | `boolean` | `false` | These properties (prefetch/preload) are used in production to configure how components with Lazy prefix are handled by webpack via its magic comments. Learn more on [webpack documentation](https://webpack.js.org/api/module-methods/#magic-comments) |
|
|
124
|
+
| `global` | `boolean` | `false` | If enabled, registers component to be globally available. |
|
|
125
|
+
| `island` | `boolean` | `false` | If enabled, registers component as island. You can read more about islands in [`<NuxtIsland/>`](/docs/api/components/nuxt-island#nuxtisland) component description. |
|
|
126
|
+
| `mode` | `'client' \| 'server' \| 'all'`{lang="ts"} | `false` | This options indicates if component should render on client, server or both. By default, it will render on both client and server. |
|
|
127
|
+
| `priority` | `number` | `false` | Priority of the component, if multiple components have the same name, the one with the highest priority will be used. |
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Context"
|
|
3
|
+
description: Nuxt Kit provides a set of utilities to help you work with context.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/kit/src/context.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Nuxt modules allow you to enhance Nuxt's capabilities. They offer a structured way to keep your code organized and modular. If you're looking to break down your module into smaller components, Nuxt offers the `useNuxt` and `tryUseNuxt` functions. These functions enable you to conveniently access the Nuxt instance from the context without having to pass it as argument.
|
|
12
|
+
|
|
13
|
+
::note
|
|
14
|
+
When you're working with the `setup` function in Nuxt modules, Nuxt is already provided as the second argument. This means you can directly utilize it without needing to call `useNuxt()`. You can look at [Nuxt Site Config](https://github.com/harlan-zw/nuxt-site-config) as an example of usage.
|
|
15
|
+
::
|
|
16
|
+
|
|
17
|
+
## `useNuxt`
|
|
18
|
+
|
|
19
|
+
Get the Nuxt instance from the context. It will throw an error if Nuxt is not available.
|
|
20
|
+
|
|
21
|
+
### Type
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
function useNuxt(): Nuxt
|
|
25
|
+
|
|
26
|
+
interface Nuxt {
|
|
27
|
+
options: NuxtOptions
|
|
28
|
+
hooks: Hookable<NuxtHooks>
|
|
29
|
+
hook: Nuxt['hooks']['hook']
|
|
30
|
+
callHook: Nuxt['hooks']['callHook']
|
|
31
|
+
addHooks: Nuxt['hooks']['addHooks']
|
|
32
|
+
ready: () => Promise<void>
|
|
33
|
+
close: () => Promise<void>
|
|
34
|
+
server?: any
|
|
35
|
+
vfs: Record<string, string>
|
|
36
|
+
apps: Record<string, NuxtApp>
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Examples
|
|
41
|
+
|
|
42
|
+
::code-group
|
|
43
|
+
|
|
44
|
+
```ts [setupTranspilation.ts]
|
|
45
|
+
// https://github.com/Lexpeartha/nuxt-xstate/blob/main/src/parts/transpile.ts
|
|
46
|
+
import { useNuxt } from '@nuxt/kit'
|
|
47
|
+
|
|
48
|
+
export const setupTranspilation = () => {
|
|
49
|
+
const nuxt = useNuxt()
|
|
50
|
+
|
|
51
|
+
nuxt.options.build.transpile = nuxt.options.build.transpile || []
|
|
52
|
+
|
|
53
|
+
if (nuxt.options.builder === '@nuxt/webpack-builder') {
|
|
54
|
+
nuxt.options.build.transpile.push(
|
|
55
|
+
'xstate',
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```ts [module.ts]
|
|
62
|
+
import { useNuxt } from '@nuxt/kit'
|
|
63
|
+
import { setupTranspilation } from './setupTranspilation'
|
|
64
|
+
|
|
65
|
+
export default defineNuxtModule({
|
|
66
|
+
setup() {
|
|
67
|
+
setupTranspilation()
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
::
|
|
73
|
+
|
|
74
|
+
## `tryUseNuxt`
|
|
75
|
+
|
|
76
|
+
Get the Nuxt instance from the context. It will return `null` if Nuxt is not available.
|
|
77
|
+
|
|
78
|
+
### Type
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
function tryUseNuxt(): Nuxt | null
|
|
82
|
+
|
|
83
|
+
interface Nuxt {
|
|
84
|
+
options: NuxtOptions
|
|
85
|
+
hooks: Hookable<NuxtHooks>
|
|
86
|
+
hook: Nuxt['hooks']['hook']
|
|
87
|
+
callHook: Nuxt['hooks']['callHook']
|
|
88
|
+
addHooks: Nuxt['hooks']['addHooks']
|
|
89
|
+
ready: () => Promise<void>
|
|
90
|
+
close: () => Promise<void>
|
|
91
|
+
server?: any
|
|
92
|
+
vfs: Record<string, string>
|
|
93
|
+
apps: Record<string, NuxtApp>
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Examples
|
|
98
|
+
|
|
99
|
+
::code-group
|
|
100
|
+
|
|
101
|
+
```ts [requireSiteConfig.ts]
|
|
102
|
+
// https://github.com/harlan-zw/nuxt-site-config/blob/main/test/assertions.test.ts
|
|
103
|
+
import { tryUseNuxt } from '@nuxt/kit'
|
|
104
|
+
|
|
105
|
+
interface SiteConfig {
|
|
106
|
+
title: string
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const requireSiteConfig = (): SiteConfig => {
|
|
110
|
+
const nuxt = tryUseNuxt()
|
|
111
|
+
if (!nuxt) {
|
|
112
|
+
return { title: null }
|
|
113
|
+
}
|
|
114
|
+
return nuxt.options.siteConfig
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```ts [module.ts]
|
|
119
|
+
import { useNuxt } from '@nuxt/kit'
|
|
120
|
+
import { requireSiteConfig } from './requireSiteConfig'
|
|
121
|
+
|
|
122
|
+
export default defineNuxtModule({
|
|
123
|
+
setup(_, nuxt) {
|
|
124
|
+
const config = requireSiteConfig()
|
|
125
|
+
nuxt.options.app.head.title = config.title
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
::
|