@nuxt/docs-nightly 4.5.1-29752449.30d24817 → 4.5.2-2610052030-052d82e
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 +8 -8
- package/1.getting-started/02.installation.md +2 -4
- package/1.getting-started/03.configuration.md +16 -16
- package/1.getting-started/04.views.md +8 -8
- package/1.getting-started/05.assets.md +10 -10
- package/1.getting-started/06.styling.md +10 -10
- package/1.getting-started/07.routing.md +15 -15
- package/1.getting-started/08.seo-meta.md +15 -15
- package/1.getting-started/09.transitions.md +10 -10
- package/1.getting-started/10.data-fetching.md +61 -47
- package/1.getting-started/11.state-management.md +11 -11
- package/1.getting-started/12.error-handling.md +20 -18
- package/1.getting-started/13.server.md +7 -7
- package/1.getting-started/14.layers.md +6 -6
- package/1.getting-started/15.prerendering.md +22 -28
- package/1.getting-started/16.deployment.md +22 -6
- package/1.getting-started/17.testing.md +200 -21
- package/1.getting-started/18.upgrade.md +78 -278
- package/2.directory-structure/0.nuxt.md +2 -2
- package/2.directory-structure/0.output.md +3 -3
- package/2.directory-structure/1.app/1.assets.md +3 -3
- package/2.directory-structure/1.app/1.components.md +26 -109
- package/2.directory-structure/1.app/1.composables.md +5 -5
- package/2.directory-structure/1.app/1.layouts.md +10 -10
- package/2.directory-structure/1.app/1.middleware.md +14 -10
- package/2.directory-structure/1.app/1.pages.md +25 -20
- package/2.directory-structure/1.app/1.plugins.md +7 -7
- package/2.directory-structure/1.app/1.utils.md +9 -5
- package/2.directory-structure/1.app/3.app-config.md +7 -7
- package/2.directory-structure/1.app/3.app.md +6 -6
- package/2.directory-structure/1.app/3.error.md +1 -1
- package/2.directory-structure/1.content.md +1 -1
- package/2.directory-structure/1.layers.md +13 -13
- package/2.directory-structure/1.modules.md +3 -3
- package/2.directory-structure/1.node_modules.md +1 -1
- package/2.directory-structure/1.server.md +33 -14
- package/2.directory-structure/1.shared.md +7 -5
- package/2.directory-structure/1.test.md +25 -0
- package/2.directory-structure/2.env.md +7 -7
- package/2.directory-structure/2.nuxtignore.md +3 -3
- package/2.directory-structure/2.nuxtrc.md +3 -3
- package/2.directory-structure/3.nuxt-config.md +2 -2
- package/2.directory-structure/3.tsconfig.md +21 -11
- package/2.directory-structure/index.md +29 -25
- package/3.guide/0.index.md +6 -6
- package/3.guide/1.concepts/1.rendering.md +76 -12
- package/3.guide/1.concepts/10.vuejs-development.md +73 -8
- package/3.guide/1.concepts/2.nuxt-lifecycle.md +18 -18
- package/3.guide/1.concepts/3.auto-imports.md +11 -11
- package/3.guide/1.concepts/4.server-engine.md +6 -6
- package/3.guide/1.concepts/5.modules.md +4 -4
- package/3.guide/1.concepts/6.server-components.md +198 -0
- package/3.guide/1.concepts/7.esm.md +5 -5
- package/3.guide/1.concepts/8.typescript.md +9 -9
- package/3.guide/2.best-practices/accessibility.md +155 -0
- package/3.guide/2.best-practices/hydration.md +5 -5
- package/3.guide/2.best-practices/performance.md +13 -9
- package/3.guide/3.ai/1.mcp.md +104 -19
- package/3.guide/4.modules/2.module-anatomy.md +5 -5
- package/3.guide/4.modules/3.recipes-basics.md +8 -8
- package/3.guide/4.modules/4.module-dependencies.md +1 -1
- package/3.guide/4.modules/5.recipes-advanced.md +6 -8
- package/3.guide/4.modules/6.testing.md +2 -2
- package/3.guide/4.modules/7.best-practices.md +2 -2
- package/3.guide/4.modules/9.server-compatibility.md +215 -0
- package/3.guide/4.modules/index.md +9 -9
- package/3.guide/5.recipes/1.custom-routing.md +15 -11
- package/3.guide/5.recipes/2.vite-plugin.md +3 -3
- package/3.guide/5.recipes/3.custom-usefetch.md +5 -5
- package/3.guide/5.recipes/4.sessions-and-authentication.md +2 -2
- package/3.guide/5.recipes/5.mostly-static-sites.md +127 -0
- package/3.guide/6.going-further/1.events.md +1 -1
- package/3.guide/6.going-further/1.experimental-features.md +254 -22
- package/3.guide/6.going-further/1.features.md +42 -6
- package/3.guide/6.going-further/1.internals.md +10 -10
- package/3.guide/6.going-further/10.runtime-config.md +28 -6
- package/3.guide/6.going-further/11.nightly-release-channel.md +1 -1
- package/3.guide/6.going-further/2.hooks.md +6 -6
- package/3.guide/6.going-further/4.kit.md +4 -4
- package/3.guide/6.going-further/5.server-imports.md +221 -0
- package/3.guide/6.going-further/6.nuxt-app.md +7 -7
- package/3.guide/6.going-further/7.layers.md +13 -13
- package/3.guide/6.going-further/8.builders.md +38 -14
- package/4.api/1.components/1.nuxt-client-fallback.md +1 -1
- package/4.api/1.components/10.nuxt-picture.md +1 -1
- package/4.api/1.components/11.teleports.md +1 -1
- package/4.api/1.components/12.nuxt-route-announcer.md +5 -3
- package/4.api/1.components/14.nuxt-announcer.md +3 -3
- package/4.api/1.components/2.nuxt-page.md +5 -5
- package/4.api/1.components/3.nuxt-layout.md +8 -8
- package/4.api/1.components/4.nuxt-link.md +6 -4
- package/4.api/1.components/5.nuxt-loading-indicator.md +3 -3
- package/4.api/1.components/6.nuxt-error-boundary.md +1 -1
- package/4.api/1.components/8.nuxt-island.md +5 -5
- package/4.api/2.composables/create-use-async-data.md +51 -8
- package/4.api/2.composables/create-use-fetch.md +126 -9
- package/4.api/2.composables/use-announcer.md +3 -3
- package/4.api/2.composables/use-app-config.md +1 -1
- package/4.api/2.composables/use-async-data.md +19 -11
- package/4.api/2.composables/use-cookie.md +22 -6
- package/4.api/2.composables/use-error.md +1 -1
- package/4.api/2.composables/use-fetch.md +14 -10
- package/4.api/2.composables/use-head-safe.md +2 -2
- package/4.api/2.composables/use-head.md +2 -2
- package/4.api/2.composables/use-hydration.md +1 -1
- package/4.api/2.composables/use-layout.md +1 -1
- package/4.api/2.composables/use-lazy-async-data.md +8 -8
- package/4.api/2.composables/use-lazy-fetch.md +11 -11
- package/4.api/2.composables/use-loading-indicator.md +2 -2
- package/4.api/2.composables/use-nuxt-app.md +13 -13
- package/4.api/2.composables/use-nuxt-data.md +1 -1
- package/4.api/2.composables/use-preview-mode.md +3 -3
- package/4.api/2.composables/use-request-event.md +29 -3
- package/4.api/2.composables/use-request-fetch.md +2 -2
- package/4.api/2.composables/use-request-header.md +1 -1
- package/4.api/2.composables/use-request-headers.md +1 -1
- package/4.api/2.composables/use-request-url.md +1 -1
- package/4.api/2.composables/use-response-header.md +2 -2
- package/4.api/2.composables/use-route-announcer.md +4 -2
- package/4.api/2.composables/use-route.md +2 -2
- package/4.api/2.composables/use-router.md +5 -5
- package/4.api/2.composables/use-runtime-config.md +5 -5
- package/4.api/2.composables/use-runtime-hook.md +1 -1
- package/4.api/2.composables/use-seo-meta.md +3 -3
- package/4.api/2.composables/use-server-seo-meta.md +5 -5
- package/4.api/2.composables/use-state.md +4 -4
- package/4.api/3.utils/$fetch.md +5 -5
- package/4.api/3.utils/abort-navigation.md +1 -1
- package/4.api/3.utils/add-route-middleware.md +2 -2
- package/4.api/3.utils/call-once.md +3 -3
- package/4.api/3.utils/clear-error.md +2 -2
- package/4.api/3.utils/clear-nuxt-data.md +1 -1
- package/4.api/3.utils/clear-nuxt-state.md +2 -2
- package/4.api/3.utils/create-error.md +19 -1
- package/4.api/3.utils/define-nuxt-plugin.md +2 -2
- package/4.api/3.utils/define-nuxt-route-middleware.md +3 -3
- package/4.api/3.utils/define-page-meta.md +12 -12
- package/4.api/3.utils/define-route-rules.md +4 -4
- package/4.api/3.utils/define-use-async-data-addon.md +57 -0
- package/4.api/3.utils/define-use-fetch-addon.md +168 -0
- package/4.api/3.utils/navigate-to.md +6 -2
- package/4.api/3.utils/prefetch-components.md +1 -1
- package/4.api/3.utils/preload-route-components.md +2 -2
- package/4.api/3.utils/prerender-routes.md +3 -3
- package/4.api/3.utils/refresh-cookie.md +1 -1
- package/4.api/3.utils/refresh-nuxt-data.md +3 -3
- package/4.api/3.utils/reload-nuxt-app.md +1 -1
- package/4.api/3.utils/set-page-layout.md +1 -1
- package/4.api/3.utils/set-response-status.md +2 -2
- package/4.api/3.utils/show-error.md +3 -3
- package/4.api/3.utils/update-app-config.md +2 -2
- package/4.api/4.commands/README.md +9 -0
- package/4.api/5.kit/1.modules.md +3 -3
- package/4.api/5.kit/10.runtime-config.md +1 -1
- package/4.api/5.kit/10.templates.md +42 -0
- package/4.api/5.kit/12.nitro.md +59 -18
- package/4.api/5.kit/14.logging.md +56 -2
- package/4.api/5.kit/15.builder.md +1 -1
- package/4.api/5.kit/18.dependencies.md +90 -0
- package/4.api/5.kit/2.programmatic.md +78 -1
- package/4.api/5.kit/3.compatibility.md +2 -2
- package/4.api/5.kit/4.autoimports.md +13 -13
- package/4.api/5.kit/5.components.md +3 -3
- package/4.api/5.kit/6.context.md +2 -2
- package/4.api/5.kit/7.pages.md +35 -4
- package/4.api/5.kit/8.layout.md +1 -1
- package/4.api/6.advanced/1.hooks.md +6 -3
- package/4.api/6.nuxt-config.md +44 -21
- package/4.api/index.md +7 -7
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +14 -12
- package/5.community/5.framework-contribution.md +4 -4
- package/5.community/6.roadmap.md +6 -6
- package/6.bridge/1.overview.md +12 -12
- package/6.bridge/2.typescript.md +1 -1
- package/6.bridge/3.bridge-composition-api.md +6 -6
- package/6.bridge/4.plugins-and-middleware.md +4 -4
- package/6.bridge/5.nuxt3-compatible-api.md +9 -9
- package/6.bridge/6.meta.md +5 -5
- package/6.bridge/7.runtime-config.md +1 -1
- package/6.bridge/8.nitro.md +1 -1
- package/6.bridge/9.vite.md +1 -1
- package/7.migration/1.overview.md +2 -2
- package/7.migration/10.bundling.md +1 -1
- package/7.migration/11.server.md +3 -3
- package/7.migration/2.configuration.md +6 -6
- package/7.migration/20.module-authors.md +7 -7
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +4 -4
- package/7.migration/5.plugins-and-middleware.md +3 -3
- package/7.migration/6.pages-and-layouts.md +13 -13
- package/7.migration/7.component-options.md +15 -15
- package/7.migration/8.runtime-config.md +4 -4
- package/README.md +1 -1
- package/errors/e8007.md +28 -0
- package/package.json +2 -2
- package/4.api/4.commands/.navigation.yml +0 -3
- package/4.api/4.commands/add.md +0 -112
- package/4.api/4.commands/analyze.md +0 -42
- package/4.api/4.commands/build-module.md +0 -42
- package/4.api/4.commands/build.md +0 -48
- package/4.api/4.commands/cleanup.md +0 -38
- package/4.api/4.commands/dev.md +0 -61
- package/4.api/4.commands/devtools.md +0 -38
- package/4.api/4.commands/generate.md +0 -43
- package/4.api/4.commands/info.md +0 -33
- package/4.api/4.commands/init.md +0 -50
- package/4.api/4.commands/module.md +0 -84
- package/4.api/4.commands/prepare.md +0 -41
- package/4.api/4.commands/preview.md +0 -44
- package/4.api/4.commands/test.md +0 -40
- package/4.api/4.commands/typecheck.md +0 -44
- package/4.api/4.commands/upgrade.md +0 -37
package/4.api/5.kit/12.nitro.md
CHANGED
|
@@ -8,7 +8,7 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
Nitro is an open source TypeScript framework to build ultra-fast web servers. Nuxt uses Nitro as its server engine. You can use `useNitro` to access the Nitro instance, `addServerHandler` to add a server handler, `addDevServerHandler` to add a server handler to be used only in development mode, `
|
|
11
|
+
Nitro is an open source TypeScript framework to build ultra-fast web servers. Nuxt uses Nitro as its server engine. You can use `useNitro` to access the Nitro instance (or `tryUseNitro` if your module should also work without Nitro), `addServerHandler` to add a server handler, `addDevServerHandler` to add a server handler to be used only in development mode, `addNitroPlugin` to add a plugin to extend Nitro's runtime behavior, and `addPrerenderRoutes` to add routes to be prerendered by Nitro.
|
|
12
12
|
|
|
13
13
|
## `addServerHandler`
|
|
14
14
|
|
|
@@ -34,7 +34,7 @@ export default defineNuxtModule({
|
|
|
34
34
|
### Type
|
|
35
35
|
|
|
36
36
|
```ts
|
|
37
|
-
function addServerHandler (handler:
|
|
37
|
+
function addServerHandler (handler: ServerHandlerInput): void
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
### Parameters
|
|
@@ -43,12 +43,18 @@ function addServerHandler (handler: NitroEventHandler): void
|
|
|
43
43
|
|
|
44
44
|
| Property | Type | Required | Description |
|
|
45
45
|
|--------------|-----------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------|
|
|
46
|
-
| `handler` | `string` | `true` | Path to event handler.
|
|
47
|
-
| `route` | `string` | `false` |
|
|
46
|
+
| `handler` | `string \| { nuxt?: string, nitro2?: string, nitro3?: string }` | `true` | Path to the event handler, or one path per server API. Nuxt registers the implementation the application's server can run. |
|
|
47
|
+
| `route` | `string` | `false` | The route to match, exactly. End it in `/**` to match the paths below it as well. If an empty string is used, the handler is registered as middleware. |
|
|
48
48
|
| `middleware` | `boolean` | `false` | Specifies this is a middleware handler. Middleware are called on every route and should normally return nothing to pass to the next handlers. |
|
|
49
49
|
| `lazy` | `boolean` | `false` | Use lazy loading to import the handler. This is useful when you only want to load the handler on demand. |
|
|
50
50
|
| `method` | `string` | `false` | Router method matcher. If handler name contains method name, it will be used as a default value. |
|
|
51
51
|
|
|
52
|
+
A route ending in `/**` matches its base path too, so `route: '/_fonts/**'` serves `/_fonts` and everything below it. On a Nitro 2 host, whose router matches only the paths below the base, Nuxt registers the base path as a second route so that one registration behaves the same on both.
|
|
53
|
+
|
|
54
|
+
::read-more{to="/docs/guide/modules/server-compatibility"}
|
|
55
|
+
Learn when to register one path per server API, and which key to write your handler against.
|
|
56
|
+
::
|
|
57
|
+
|
|
52
58
|
### Example
|
|
53
59
|
|
|
54
60
|
#### Basic Usage
|
|
@@ -115,11 +121,8 @@ export default defineNuxtModule({
|
|
|
115
121
|
|
|
116
122
|
### Type
|
|
117
123
|
|
|
118
|
-
```ts
|
|
119
|
-
|
|
120
|
-
import type { NitroDevEventHandler } from 'nitropack/types'
|
|
121
|
-
// ---cut---
|
|
122
|
-
function addDevServerHandler (handler: NitroDevEventHandler): void
|
|
124
|
+
```ts
|
|
125
|
+
function addDevServerHandler (handler: DevServerHandlerInput): void
|
|
123
126
|
```
|
|
124
127
|
|
|
125
128
|
### Parameters
|
|
@@ -189,10 +192,48 @@ export default defineNuxtModule({
|
|
|
189
192
|
function useNitro (): Nitro
|
|
190
193
|
```
|
|
191
194
|
|
|
192
|
-
## `
|
|
195
|
+
## `tryUseNitro`
|
|
196
|
+
|
|
197
|
+
Returns the Nitro instance, or `undefined` when there is none.
|
|
198
|
+
|
|
199
|
+
There is no Nitro instance before the `ready` hook has run, and none at all when the
|
|
200
|
+
configured [`server.builder`](/docs/api/nuxt-config#builder-1) does not use Nitro, such as a
|
|
201
|
+
builder that outputs a client-only SPA. Use this rather than `useNitro()` for anything that
|
|
202
|
+
should keep working without a server: server routes, route rules and prerendering are all
|
|
203
|
+
absent in that case.
|
|
204
|
+
|
|
205
|
+
### Usage
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
import { defineNuxtModule, tryUseNitro } from '@nuxt/kit'
|
|
209
|
+
|
|
210
|
+
export default defineNuxtModule({
|
|
211
|
+
setup (options, nuxt) {
|
|
212
|
+
nuxt.hook('ready', () => {
|
|
213
|
+
const nitro = tryUseNitro()
|
|
214
|
+
if (!nitro) {
|
|
215
|
+
// no server: skip anything that would only run there
|
|
216
|
+
return
|
|
217
|
+
}
|
|
218
|
+
})
|
|
219
|
+
},
|
|
220
|
+
})
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Type
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
function tryUseNitro (): Nitro | undefined
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## `addNitroPlugin`
|
|
193
230
|
|
|
194
231
|
Add plugin to extend Nitro's runtime behavior.
|
|
195
232
|
|
|
233
|
+
::note
|
|
234
|
+
This was named `addServerPlugin` before Nuxt v4.6.
|
|
235
|
+
::
|
|
236
|
+
|
|
196
237
|
::tip
|
|
197
238
|
You can read more about Nitro plugins in the [Nitro documentation](https://nitro.build/guide/plugins).
|
|
198
239
|
::
|
|
@@ -204,12 +245,12 @@ It is necessary to explicitly import `defineNitroPlugin` from `nitropack/runtime
|
|
|
204
245
|
### Usage
|
|
205
246
|
|
|
206
247
|
```ts twoslash
|
|
207
|
-
import {
|
|
248
|
+
import { addNitroPlugin, createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
208
249
|
|
|
209
250
|
export default defineNuxtModule({
|
|
210
251
|
setup () {
|
|
211
252
|
const { resolve } = createResolver(import.meta.url)
|
|
212
|
-
|
|
253
|
+
addNitroPlugin(resolve('./runtime/plugin.ts'))
|
|
213
254
|
},
|
|
214
255
|
})
|
|
215
256
|
```
|
|
@@ -217,26 +258,26 @@ export default defineNuxtModule({
|
|
|
217
258
|
### Type
|
|
218
259
|
|
|
219
260
|
```ts
|
|
220
|
-
function
|
|
261
|
+
function addNitroPlugin (plugin: string | { nitro2?: string, nitro3?: string }): void
|
|
221
262
|
```
|
|
222
263
|
|
|
223
264
|
### Parameters
|
|
224
265
|
|
|
225
266
|
| Property | Type | Required | Description |
|
|
226
267
|
|----------|----------|----------|---------------------------------------------------------------------------------------------------------------|
|
|
227
|
-
| `plugin` | `string` | `true` | Path to the plugin. The plugin must export a default function that accepts the Nitro instance as an argument. |
|
|
268
|
+
| `plugin` | `string \| { nitro2?: string, nitro3?: string }` | `true` | Path to the plugin, or one path per nitro major for a module shipping an implementation for each. The plugin must export a default function that accepts the Nitro instance as an argument. |
|
|
228
269
|
|
|
229
270
|
### Example
|
|
230
271
|
|
|
231
272
|
::code-group
|
|
232
273
|
|
|
233
274
|
```ts [module.ts]
|
|
234
|
-
import {
|
|
275
|
+
import { addNitroPlugin, createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
235
276
|
|
|
236
277
|
export default defineNuxtModule({
|
|
237
278
|
setup () {
|
|
238
279
|
const { resolve } = createResolver(import.meta.url)
|
|
239
|
-
|
|
280
|
+
addNitroPlugin(resolve('./runtime/plugin.ts'))
|
|
240
281
|
},
|
|
241
282
|
})
|
|
242
283
|
```
|
|
@@ -302,7 +343,7 @@ function addPrerenderRoutes (routes: string | string[]): void
|
|
|
302
343
|
Add imports to the server. It makes your imports available in Nitro without the need to import them manually.
|
|
303
344
|
|
|
304
345
|
::warning
|
|
305
|
-
If you want to provide a utility that works in both server and client contexts and is usable in the [`shared/`](/docs/
|
|
346
|
+
If you want to provide a utility that works in both server and client contexts and is usable in the [`shared/`](/docs/directory-structure/shared) directory, the function must be imported from the same source file for both [`addImports`](/docs/api/kit/autoimports#addimports) and `addServerImports` and should have identical signature. That source file should not import anything context-specific (i.e., Nitro context, Nuxt app context) or else it might cause errors during type-checking.
|
|
306
347
|
::
|
|
307
348
|
|
|
308
349
|
### Usage
|
|
@@ -330,7 +371,7 @@ export default defineNuxtModule({
|
|
|
330
371
|
### Type
|
|
331
372
|
|
|
332
373
|
```ts
|
|
333
|
-
function addServerImports (dirs:
|
|
374
|
+
function addServerImports (dirs: NuxtImport | NuxtImport[]): void
|
|
334
375
|
```
|
|
335
376
|
|
|
336
377
|
### Parameters
|
|
@@ -31,14 +31,14 @@ export default defineNuxtModule({
|
|
|
31
31
|
### Type
|
|
32
32
|
|
|
33
33
|
```ts
|
|
34
|
-
function useLogger (tag?: string, options?:
|
|
34
|
+
function useLogger (tag?: string, options?: NuxtLoggerOptions): NuxtLogger
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
### Parameters
|
|
38
38
|
|
|
39
39
|
**`tag`**: A tag to suffix all log messages with, displayed on the right near the timestamp.
|
|
40
40
|
|
|
41
|
-
**`options`**:
|
|
41
|
+
**`options`**: Logger options, such as `level`, `reporters`, `defaults` and `formatOptions`.
|
|
42
42
|
|
|
43
43
|
### Example
|
|
44
44
|
|
|
@@ -53,3 +53,57 @@ export default defineNuxtModule({
|
|
|
53
53
|
},
|
|
54
54
|
})
|
|
55
55
|
```
|
|
56
|
+
|
|
57
|
+
## `useTerminal`
|
|
58
|
+
|
|
59
|
+
Returns a set of primitives for interacting with the user's terminal. When Nuxt is running inside an interactive host such as the `nuxt dev` terminal UI, prompts, tasks and notifications are handed to it, so they are answerable and rendered in one place. Otherwise they fall back to logging.
|
|
60
|
+
|
|
61
|
+
### Usage
|
|
62
|
+
|
|
63
|
+
```ts twoslash
|
|
64
|
+
declare function runPackageInstall (name: string): Promise<void>
|
|
65
|
+
// ---cut---
|
|
66
|
+
import { defineNuxtModule, useTerminal } from '@nuxt/kit'
|
|
67
|
+
|
|
68
|
+
export default defineNuxtModule({
|
|
69
|
+
async setup () {
|
|
70
|
+
const terminal = useTerminal()
|
|
71
|
+
|
|
72
|
+
const install = await terminal.prompt('Do you want to install `my-module`?', { type: 'confirm' })
|
|
73
|
+
if (!install) {
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const task = terminal.startTask('Installing `my-module`...')
|
|
78
|
+
// run your actual task
|
|
79
|
+
await runPackageInstall('my-module')
|
|
80
|
+
task.stop('Installed `my-module`')
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Type
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
function useTerminal (): NuxtTerminal
|
|
89
|
+
|
|
90
|
+
interface NuxtTerminal {
|
|
91
|
+
readonly interactive: boolean
|
|
92
|
+
withTerminal: <T>(work: () => Promise<T>) => Promise<T>
|
|
93
|
+
prompt: (message: string, options?: NuxtPromptOptions) => Promise<any>
|
|
94
|
+
startTask: (label: string) => NuxtTerminalTask
|
|
95
|
+
notify: (notification: NuxtTerminalNotification) => NuxtTerminalNotice
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Properties
|
|
100
|
+
|
|
101
|
+
**`interactive`**: Whether an interactive host is present. When `false`, the primitives below log to the current process streams instead.
|
|
102
|
+
|
|
103
|
+
**`withTerminal`**: Borrows the terminal for the duration of `work`, suspending any host UI and releasing `stdin`. Use it when you need to write to the terminal or read from `stdin` directly. Concurrent callers are serialised, and a nested call from within a borrow runs immediately.
|
|
104
|
+
|
|
105
|
+
**`prompt`**: Asks the user a question, borrowing the terminal for as long as the prompt is open. Takes the same options as `logger.prompt`.
|
|
106
|
+
|
|
107
|
+
**`startTask`**: Starts a long-running task, rendered on the host's status surface where available. Finish it with `task.stop(message?, outcome?)`, or change its label with `task.update(label)`.
|
|
108
|
+
|
|
109
|
+
**`notify`**: Shows a message and holds it on screen until the user acknowledges it or `notice.dismiss()` is called. `notice.dismissed` settles once the notice is gone.
|
|
@@ -330,7 +330,7 @@ function addBuildPlugin (pluginFactory: AddBuildPluginFactory, options?: ExtendC
|
|
|
330
330
|
|
|
331
331
|
Set a build output provider for the given key. Build outputs are the contract between builders (Vite, webpack, Rspack, or a custom builder) and the Nitro server runtime: each key maps to a `nuxt/*` subpath import the server runtime resolves at build time. This is typically called from inside a builder, or from a module that participates in the build.
|
|
332
332
|
|
|
333
|
-
::read-more{to="/docs/
|
|
333
|
+
::read-more{to="/docs/guide/going-further/builders#the-build-output-contract"}
|
|
334
334
|
Learn how the build output contract works.
|
|
335
335
|
::
|
|
336
336
|
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Dependencies"
|
|
3
|
+
description: Nuxt Kit provides utilities to check that optional dependencies are installed and to tell users how to install them.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/kit/src/dependency.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Modules often depend on a package that only some projects need, or that the user is expected to install themselves. Rather than assuming the package is there, or printing an install command for a package manager the user does not use, Nuxt Kit can check whether a dependency is resolvable and offer to install it with the project's own package manager.
|
|
12
|
+
|
|
13
|
+
## `ensureDependencyInstalled`
|
|
14
|
+
|
|
15
|
+
Check that one or more dependencies are installed, prompting the user to install any that are missing.
|
|
16
|
+
|
|
17
|
+
### Usage
|
|
18
|
+
|
|
19
|
+
```ts twoslash
|
|
20
|
+
import { defineNuxtModule, ensureDependencyInstalled } from '@nuxt/kit'
|
|
21
|
+
|
|
22
|
+
export default defineNuxtModule({
|
|
23
|
+
async setup () {
|
|
24
|
+
if (!await ensureDependencyInstalled('sass')) {
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Type
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
function ensureDependencyInstalled (names: string, options?: EnsureDependencyInstalledOptions): Promise<boolean>
|
|
35
|
+
function ensureDependencyInstalled (names: string[], options?: EnsureDependencyInstalledOptions): Promise<true | string[]>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Parameters
|
|
39
|
+
|
|
40
|
+
**`names`**: One or more package names to check, and to install if they are missing.
|
|
41
|
+
|
|
42
|
+
**`options`**:
|
|
43
|
+
|
|
44
|
+
| Property | Type | Default | Description |
|
|
45
|
+
| ------------- | ---------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
46
|
+
| `rootDir` | `string` | `nuxt.options.rootDir` | Directory to resolve packages from and to install into. |
|
|
47
|
+
| `searchPaths` | `string[]` | `nuxt.options.modulesDir` | Additional directories to resolve packages from. |
|
|
48
|
+
| `from` | `string` | `undefined` | An extra URL or path to resolve packages from, such as `import.meta.url`. Useful when your own package ships the dependency as a peer dependency. |
|
|
49
|
+
| `prompt` | `boolean` | `undefined` | Whether to prompt before installing. `true` always prompts, `false` never prompts (and installs automatically on StackBlitz), and leaving it unset prompts everywhere except StackBlitz. |
|
|
50
|
+
|
|
51
|
+
### Return Value
|
|
52
|
+
|
|
53
|
+
Passing a single package name returns `true` if it is available and `false` if it is not. Passing an array returns `true` if every package is available, or an array of the package names that are still missing (because the user declined, the install failed, or there was no interactive terminal).
|
|
54
|
+
|
|
55
|
+
::note
|
|
56
|
+
Nothing is installed in CI or when there is no interactive terminal. In that case the missing packages are reported as a diagnostic that includes the install command, and the function reports them as missing so your module can degrade gracefully.
|
|
57
|
+
::
|
|
58
|
+
|
|
59
|
+
## `getAddDependencyCommand`
|
|
60
|
+
|
|
61
|
+
Get the command a user should run to add dependencies to their project, using the package manager detected from `cwd` and falling back to `npm`. Use it whenever you print an install instruction, so the command matches the project's package manager.
|
|
62
|
+
|
|
63
|
+
### Usage
|
|
64
|
+
|
|
65
|
+
```ts twoslash
|
|
66
|
+
import { defineNuxtModule, getAddDependencyCommand, useLogger } from '@nuxt/kit'
|
|
67
|
+
|
|
68
|
+
export default defineNuxtModule({
|
|
69
|
+
async setup (options, nuxt) {
|
|
70
|
+
const logger = useLogger('my-module')
|
|
71
|
+
const command = await getAddDependencyCommand('sass', nuxt.options.rootDir, { dev: true })
|
|
72
|
+
|
|
73
|
+
logger.warn(`\`sass\` is required. Run \`${command}\` to install it.`)
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Type
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
function getAddDependencyCommand (names: string | string[], cwd: string, options?: { dev?: boolean }): Promise<string>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Parameters
|
|
85
|
+
|
|
86
|
+
**`names`**: One or more package names to install.
|
|
87
|
+
|
|
88
|
+
**`cwd`**: Directory to detect the package manager from.
|
|
89
|
+
|
|
90
|
+
**`options.dev`**: Whether the command should install the packages as dev dependencies.
|
|
@@ -55,7 +55,84 @@ function loadNuxtConfig (options: LoadNuxtConfigOptions): Promise<NuxtOptions>
|
|
|
55
55
|
|
|
56
56
|
### Parameters
|
|
57
57
|
|
|
58
|
-
**`options`**: Options
|
|
58
|
+
**`options`**: Options controlling how configuration is located, merged and loaded.
|
|
59
|
+
|
|
60
|
+
| Property | Type | Default | Description |
|
|
61
|
+
| ------------------- | --------------------------------------------------- | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
62
|
+
| `cwd` | `string` | `process.cwd()` | Directory to load `nuxt.config` from. |
|
|
63
|
+
| `configFile` | `string` | `'nuxt.config'` | Name of the config file to load, without an extension. |
|
|
64
|
+
| `rcFile` | `string \| false` | `'.nuxtrc'` | Name of the `.rc` file to load alongside the config file, or `false` to load none. |
|
|
65
|
+
| `globalRc` | `boolean` | `true` | Also load the user-level and workspace-level `.nuxtrc` files. |
|
|
66
|
+
| `overrides` | `NuxtConfig` | `undefined` | Configuration applied above every layer, including the root project's own `nuxt.config`. |
|
|
67
|
+
| `defaults` | `NuxtConfig` | `undefined` | Configuration applied below every layer, before schema defaults. |
|
|
68
|
+
| `dotenv` | `boolean \| NuxtDotenvOptions` | `true` | Load `.env` files into `process.env` before resolving configuration. Set to `false` when the environment has already been populated. |
|
|
69
|
+
| `envName` | `string \| false` | `undefined` | Environment name used to select `$env.*` configuration overrides. Takes precedence over `envName` set in `nuxt.config`. |
|
|
70
|
+
| `resolve` | `(source, context) => ResolvedNuxtLayer \| nullish` | `undefined` | Resolve an `extends` entry to a layer yourself. Return a nullish value to fall back to the default resolution for that source. |
|
|
71
|
+
| `import` | `(id: string) => Promise<unknown>` | `undefined` | Import config files with a custom loader rather than the default one, for example to load TypeScript config without Nuxt reaching for `jiti`. |
|
|
72
|
+
| `onConfigResolved` | `(context: ResolvedNuxtConfigContext) => void` | `undefined` | Called once, and awaited, after configuration has loaded successfully. Not called if loading throws. |
|
|
73
|
+
|
|
74
|
+
### `onConfigResolved`
|
|
75
|
+
|
|
76
|
+
The context passed to `onConfigResolved` describes what was loaded:
|
|
77
|
+
|
|
78
|
+
| Property | Type | Description |
|
|
79
|
+
| ------------ | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
80
|
+
| `rawConfig` | `NuxtConfig` | User configuration merged across all layers, with no schema defaults applied and with `overrides`, `defaults` and `defaultConfig` excluded, so repeated loads of an unchanged project produce an unchanged snapshot. |
|
|
81
|
+
| `layers` | `NuxtConfigLayer[]` | Resolved config layers, highest priority first. |
|
|
82
|
+
| `configFile` | `string?` | Absolute path of the root `nuxt.config` file, if one was found. |
|
|
83
|
+
| `cwd` | `string` | Directory the configuration was loaded from. |
|
|
84
|
+
|
|
85
|
+
## `diffNuxtConfig`
|
|
86
|
+
|
|
87
|
+
Compare two `rawConfig` snapshots (as provided to `onConfigResolved`) and return the differences between them. This is useful when you watch config files yourself and need to know which keys changed before deciding whether to restart.
|
|
88
|
+
|
|
89
|
+
### Type
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
function diffNuxtConfig (oldConfig: NuxtConfig, newConfig: NuxtConfig): NuxtConfigDiffEntry[]
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Parameters
|
|
96
|
+
|
|
97
|
+
**`oldConfig`**: The previous `rawConfig` snapshot.
|
|
98
|
+
|
|
99
|
+
**`newConfig`**: The current `rawConfig` snapshot.
|
|
100
|
+
|
|
101
|
+
### Return Value
|
|
102
|
+
|
|
103
|
+
An array of entries, one per difference. Each entry has:
|
|
104
|
+
|
|
105
|
+
| Property | Type | Description |
|
|
106
|
+
| ---------- | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
107
|
+
| `type` | `'added' \| 'removed' \| 'changed'` | How the value changed. |
|
|
108
|
+
| `path` | `Array<string \| number>` | Property path of the changed value, with array indices as numbers, such as `['runtimeConfig', 'public', 'foo']`. Prefer this when reading the value back out of a config object. |
|
|
109
|
+
| `label` | `string` | `path` written as a property accessor, for display or for matching against a known key, such as `runtimeConfig.public.foo` or `modules[0]`. |
|
|
110
|
+
| `newValue` | `unknown` | Present for `added` and `changed` entries. |
|
|
111
|
+
| `oldValue` | `unknown` | Present for `removed` and `changed` entries. |
|
|
112
|
+
|
|
113
|
+
Functions whose source is unchanged are not reported as changes, so a config that declares inline functions does not diff against itself on every load.
|
|
114
|
+
|
|
115
|
+
### Example
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import { diffNuxtConfig, loadNuxtConfig } from '@nuxt/kit'
|
|
119
|
+
|
|
120
|
+
let previous
|
|
121
|
+
|
|
122
|
+
async function load () {
|
|
123
|
+
await loadNuxtConfig({
|
|
124
|
+
cwd: process.cwd(),
|
|
125
|
+
onConfigResolved ({ rawConfig }) {
|
|
126
|
+
if (previous) {
|
|
127
|
+
for (const entry of diffNuxtConfig(previous, rawConfig)) {
|
|
128
|
+
console.log(`${entry.label} was ${entry.type}`)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
previous = rawConfig
|
|
132
|
+
},
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
```
|
|
59
136
|
|
|
60
137
|
## `writeTypes`
|
|
61
138
|
|
|
@@ -63,7 +63,7 @@ function assertNuxtCompatibility (constraints: NuxtCompatibility, nuxt?: Nuxt):
|
|
|
63
63
|
|
|
64
64
|
### Parameters
|
|
65
65
|
|
|
66
|
-
**`constraints`**: Version and builder constraints to check against. Refer to the [constraints table in `checkNuxtCompatibility`](/docs/
|
|
66
|
+
**`constraints`**: Version and builder constraints to check against. Refer to the [constraints table in `checkNuxtCompatibility`](/docs/api/kit/compatibility#parameters) for details.
|
|
67
67
|
|
|
68
68
|
**`nuxt`**: Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
|
|
69
69
|
|
|
@@ -96,7 +96,7 @@ function hasNuxtCompatibility (constraints: NuxtCompatibility, nuxt?: Nuxt): Pro
|
|
|
96
96
|
|
|
97
97
|
### Parameters
|
|
98
98
|
|
|
99
|
-
**`constraints`**: Version and builder constraints to check against. Refer to the [constraints table in `checkNuxtCompatibility`](/docs/
|
|
99
|
+
**`constraints`**: Version and builder constraints to check against. Refer to the [constraints table in `checkNuxtCompatibility`](/docs/api/kit/compatibility#parameters) for details.
|
|
100
100
|
|
|
101
101
|
**`nuxt`**: Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
|
|
102
102
|
|
|
@@ -15,7 +15,7 @@ With Nuxt Kit you can also add your own auto-imports. `addImports` and `addImpor
|
|
|
15
15
|
These utilities are powered by [`unimport`](https://github.com/unjs/unimport), which provides the underlying auto-import mechanism used in Nuxt.
|
|
16
16
|
|
|
17
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/
|
|
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
19
|
::
|
|
20
20
|
|
|
21
21
|
::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/expanding-nuxt-s-auto-imports?friend=nuxt" target="_blank"}
|
|
@@ -27,7 +27,7 @@ Watch Vue School video about Auto-imports Nuxt Kit utilities.
|
|
|
27
27
|
Add imports to the Nuxt application. It makes your imports available in the Nuxt app context without the need to import them manually.
|
|
28
28
|
|
|
29
29
|
::tip
|
|
30
|
-
To add imports for the Nitro server context, refer to the [`addServerImports`](/docs/
|
|
30
|
+
To add imports for the Nitro server context, refer to the [`addServerImports`](/docs/api/kit/nitro#addserverimports) function.
|
|
31
31
|
::
|
|
32
32
|
|
|
33
33
|
### Usage
|
|
@@ -55,7 +55,7 @@ export default defineNuxtModule({
|
|
|
55
55
|
### Type
|
|
56
56
|
|
|
57
57
|
```ts
|
|
58
|
-
function addImports (imports:
|
|
58
|
+
function addImports (imports: NuxtImport | NuxtImport[]): void
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
### Parameters
|
|
@@ -138,22 +138,22 @@ export default defineNuxtModule({
|
|
|
138
138
|
### Type
|
|
139
139
|
|
|
140
140
|
```ts
|
|
141
|
-
function addImportsSources (importSources:
|
|
141
|
+
function addImportsSources (importSources: NuxtImportPresetSource | NuxtImportPresetSource[]): void
|
|
142
142
|
```
|
|
143
143
|
|
|
144
144
|
### Parameters
|
|
145
145
|
|
|
146
146
|
**importSources**: An object or an array of objects with the following properties:
|
|
147
147
|
|
|
148
|
-
-
|
|
148
|
+
- `NuxtImportPreset`
|
|
149
149
|
|
|
150
|
-
| Property | Type
|
|
151
|
-
|
|
152
|
-
| `from` | `string`
|
|
153
|
-
| `imports` | `
|
|
150
|
+
| Property | Type | Required | Description |
|
|
151
|
+
|-----------|------------------------------------------------------|----------|-----------------------------------------------------------------------------------|
|
|
152
|
+
| `from` | `string` | `true` | Module specifier to import from. |
|
|
153
|
+
| `imports` | `(NuxtImportEntry \| NuxtImportPreset)[]`{lang="ts"} | `true` | An array of entries, which can be import names, import objects or nested presets. |
|
|
154
154
|
|
|
155
|
-
-
|
|
155
|
+
- `NuxtPackageImportPreset`
|
|
156
156
|
|
|
157
|
-
| Property | Type
|
|
158
|
-
|
|
159
|
-
| `package` | `string`
|
|
157
|
+
| Property | Type | Required | Description |
|
|
158
|
+
|-----------|----------|----------|----------------------|
|
|
159
|
+
| `package` | `string` | `true` | Name of the package. |
|
|
@@ -58,7 +58,7 @@ function addComponentsDir (dir: ComponentsDir, opts: { prepend?: boolean } = {})
|
|
|
58
58
|
| `isAsync` | `boolean` | `false` | This flag indicates, component should be loaded async (with a separate chunk) regardless of using Lazy prefix or not. |
|
|
59
59
|
| `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. |
|
|
60
60
|
| `global` | `boolean` | `false` | If enabled, registers components to be globally available. |
|
|
61
|
-
| `island` | `boolean` | `false` | If enabled, registers components as islands. You can read more about islands in [`<NuxtIsland/>`](/docs/
|
|
61
|
+
| `island` | `boolean` | `false` | If enabled, registers components as islands. You can read more about islands in [`<NuxtIsland/>`](/docs/api/components/nuxt-island) component description. |
|
|
62
62
|
| `watch` | `boolean` | `false` | Watch specified path for changes, including file additions and file deletions. |
|
|
63
63
|
| `extensions` | `string[]` | `false` | Extensions supported by Nuxt builder. |
|
|
64
64
|
| `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. |
|
|
@@ -113,7 +113,7 @@ function addComponent (options: AddComponentOptions): void
|
|
|
113
113
|
|-------------------|--------------------------------------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
114
114
|
| `name` | `string` | `true` | Component name. |
|
|
115
115
|
| `filePath` | `string` | `true` | Path to the component. |
|
|
116
|
-
| `declarationPath` | `string` | `false` | Path to component's declaration file. It is used to generate components' [type templates](/docs/
|
|
116
|
+
| `declarationPath` | `string` | `false` | Path to component's declaration file. It is used to generate components' [type templates](/docs/api/kit/templates#addtypetemplate); if not provided, `filePath` is used instead. |
|
|
117
117
|
| `pascalName` | `string` | `false` | Pascal case component name. If not provided, it will be generated from the component name. |
|
|
118
118
|
| `kebabName` | `string` | `false` | Kebab case component name. If not provided, it will be generated from the component name. |
|
|
119
119
|
| `export` | `string` | `false` | Specify named or default export. If not provided, it will be set to `'default'`. |
|
|
@@ -122,7 +122,7 @@ function addComponent (options: AddComponentOptions): void
|
|
|
122
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
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
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/
|
|
125
|
+
| `island` | `boolean` | `false` | If enabled, registers component as island. You can read more about islands in [`<NuxtIsland/>`](/docs/api/components/nuxt-island) component description. |
|
|
126
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
127
|
| `priority` | `number` | `false` | Priority of the component, if multiple components have the same name, the one with the highest priority will be used. |
|
|
128
128
|
|
package/4.api/5.kit/6.context.md
CHANGED
|
@@ -47,10 +47,10 @@ The `useNuxt` function returns the Nuxt instance, which contains all the options
|
|
|
47
47
|
| Property | Type | Description |
|
|
48
48
|
| ---------- | ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
|
|
49
49
|
| `options` | `NuxtOptions` | The resolved Nuxt configuration. |
|
|
50
|
-
| `hooks` | `
|
|
50
|
+
| `hooks` | `NuxtHookRegistry<NuxtHooks>` | The Nuxt hook system. Allows registering and listening to lifecycle events. |
|
|
51
51
|
| `hook` | `(name: string, (...args: any[]) => Promise<void> \| void) => () => void` | Shortcut for `nuxt.hooks.hook`. Registers a single callback for a specific lifecycle hook. |
|
|
52
52
|
| `callHook` | `(name: string, ...args: any[]) => Promise<any>` | Shortcut for `nuxt.hooks.callHook`. Triggers a lifecycle hook manually and runs all registered callbacks. |
|
|
53
|
-
| `addHooks` | `(configHooks:
|
|
53
|
+
| `addHooks` | `(configHooks: NuxtNestedHooks) => () => void` | Shortcut for `nuxt.hooks.addHooks`. Registers multiple hooks at once. |
|
|
54
54
|
|
|
55
55
|
### Example
|
|
56
56
|
|
package/4.api/5.kit/7.pages.md
CHANGED
|
@@ -51,11 +51,42 @@ function extendPages (callback: (pages: NuxtPage[]) => void): void
|
|
|
51
51
|
| `name` | `string` | `false` | The name of the route. Useful for programmatic navigation and identifying routes. |
|
|
52
52
|
| `path` | `string` | `false` | The route URL path. If not set, Nuxt will infer it from the file location. |
|
|
53
53
|
| `file` | `string` | `false` | Path to the Vue file that should be used as the component for the route. |
|
|
54
|
-
| `meta` | `
|
|
54
|
+
| `meta` | `NuxtPageMeta`{lang="ts"} | `false` | Custom metadata for the route. Can be used in layouts, middlewares, or navigation guards. |
|
|
55
55
|
| `alias` | `string[] \| string`{lang="ts"} | `false` | One or more alias paths for the route. Useful for supporting multiple URLs. |
|
|
56
56
|
| `redirect` | `RouteLocationRaw`{lang="ts"} | `false` | Redirect rule for the route. Supports named routes, objects, or string paths. |
|
|
57
57
|
| `children` | `NuxtPage[]`{lang="ts"} | `false` | Nested child routes under this route for layout or view nesting. |
|
|
58
58
|
|
|
59
|
+
### Typing Custom Page Metadata
|
|
60
|
+
|
|
61
|
+
You can augment the `NuxtPageMeta` interface to add type-safe custom metadata for pages when using `extendPages` or the `pages:extend` hook:
|
|
62
|
+
|
|
63
|
+
```ts [index.d.ts]
|
|
64
|
+
declare module '@nuxt/schema' {
|
|
65
|
+
interface NuxtPageMeta {
|
|
66
|
+
requiresAuth?: boolean
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export {}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```ts [modules/auth.ts]
|
|
74
|
+
import { defineNuxtModule, extendPages } from '@nuxt/kit'
|
|
75
|
+
|
|
76
|
+
export default defineNuxtModule({
|
|
77
|
+
setup () {
|
|
78
|
+
extendPages((pages) => {
|
|
79
|
+
for (const page of pages) {
|
|
80
|
+
// requiresAuth is now typed as boolean | undefined
|
|
81
|
+
if (page.meta?.requiresAuth) {
|
|
82
|
+
// ...
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
```
|
|
89
|
+
|
|
59
90
|
## `extendRouteRules`
|
|
60
91
|
|
|
61
92
|
Nuxt is powered by the [Nitro](https://nitro.build/) server engine. With Nitro, you can incorporate high-level logic directly into your configuration, which is useful for actions like redirects, proxying, caching, and appending headers to routes. This configuration works by associating route patterns with specific route settings.
|
|
@@ -113,7 +144,7 @@ function extendRouteRules (route: string, rule: NitroRouteConfig, options?: Exte
|
|
|
113
144
|
**rule**: A route rule configuration to apply to the matched route.
|
|
114
145
|
|
|
115
146
|
::tip
|
|
116
|
-
About route rules configurations, you can get more detail in [Hybrid Rendering > Route Rules](/docs/
|
|
147
|
+
About route rules configurations, you can get more detail in [Hybrid Rendering > Route Rules](/docs/guide/concepts/rendering#route-rules).
|
|
117
148
|
::
|
|
118
149
|
|
|
119
150
|
**options**: An object to pass to the route configuration. If `override` is set to `true`, it will override the existing route configuration.
|
|
@@ -126,10 +157,10 @@ About route rules configurations, you can get more detail in [Hybrid Rendering >
|
|
|
126
157
|
|
|
127
158
|
Registers route middlewares to be available for all routes or for specific routes.
|
|
128
159
|
|
|
129
|
-
Route middlewares can be also defined in plugins via [`addRouteMiddleware`](/docs/
|
|
160
|
+
Route middlewares can be also defined in plugins via [`addRouteMiddleware`](/docs/api/utils/add-route-middleware) composable.
|
|
130
161
|
|
|
131
162
|
::tip
|
|
132
|
-
Read more about route middlewares in the [Route middleware documentation](/docs/
|
|
163
|
+
Read more about route middlewares in the [Route middleware documentation](/docs/getting-started/routing#route-middleware).
|
|
133
164
|
::
|
|
134
165
|
|
|
135
166
|
::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/adding-route-rules-and-route-middlewares?friend=nuxt" target="_blank"}
|
package/4.api/5.kit/8.layout.md
CHANGED
|
@@ -15,7 +15,7 @@ Layouts is used to be a wrapper around your pages. It can be used to wrap your p
|
|
|
15
15
|
Register template as layout and add it to the layouts.
|
|
16
16
|
|
|
17
17
|
::note
|
|
18
|
-
In Nuxt 2 `error` layout can also be registered using this utility. In Nuxt 3+ `error` layout [replaced](/docs/
|
|
18
|
+
In Nuxt 2 `error` layout can also be registered using this utility. In Nuxt 3+ `error` layout [replaced](/docs/getting-started/error-handling#error-page) with `error.vue` page in project root.
|
|
19
19
|
::
|
|
20
20
|
|
|
21
21
|
### Usage
|