@nuxt/docs-nightly 4.0.0-29102016.0f2ddb79 → 4.0.0-29102890.1505fb54
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/07.routing.md +1 -1
- package/3.api/5.kit/1.modules.md +100 -92
- package/3.api/5.kit/10.runtime-config.md +2 -0
- package/3.api/5.kit/10.templates.md +178 -164
- package/3.api/5.kit/11.nitro.md +197 -167
- package/3.api/5.kit/12.resolving.md +79 -133
- package/3.api/5.kit/13.logging.md +19 -29
- package/3.api/5.kit/14.builder.md +114 -376
- package/3.api/5.kit/2.programmatic.md +11 -64
- package/3.api/5.kit/3.compatibility.md +82 -133
- package/3.api/5.kit/4.autoimports.md +3 -3
- package/3.api/5.kit/5.components.md +22 -3
- package/3.api/5.kit/6.context.md +62 -46
- package/3.api/5.kit/7.pages.md +93 -197
- package/3.api/5.kit/8.layout.md +68 -49
- package/3.api/5.kit/9.plugins.md +140 -139
- package/package.json +1 -1
|
@@ -131,7 +131,7 @@ definePageMeta({
|
|
|
131
131
|
|
|
132
132
|
Nuxt offers route validation via the `validate` property in [`definePageMeta()`](/docs/api/utils/define-page-meta) in each page you wish to validate.
|
|
133
133
|
|
|
134
|
-
The `validate` property accepts the `route` as an argument. You can return a boolean value to determine whether or not this is a valid route to be rendered with this page. If you return `false`,
|
|
134
|
+
The `validate` property accepts the `route` as an argument. You can return a boolean value to determine whether or not this is a valid route to be rendered with this page. If you return `false`, this will cause a 404 error. You can also directly return an object with `statusCode`/`statusMessage` to customize the error returned.
|
|
135
135
|
|
|
136
136
|
If you have a more complex use case, then you can use anonymous route middleware instead.
|
|
137
137
|
|
package/3.api/5.kit/1.modules.md
CHANGED
|
@@ -14,87 +14,52 @@ Modules are the building blocks of Nuxt. Kit provides a set of utilities to help
|
|
|
14
14
|
|
|
15
15
|
Define a Nuxt module, automatically merging defaults with user provided options, installing any hooks that are provided, and calling an optional setup function for full control.
|
|
16
16
|
|
|
17
|
-
###
|
|
17
|
+
### Usage
|
|
18
18
|
|
|
19
|
-
```ts
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
getOptions?: (inlineOptions?: T, nuxt?: Nuxt) => Promise<T>
|
|
35
|
-
getMeta?: () => Promise<ModuleMeta>
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
interface ModuleSetupReturn {
|
|
39
|
-
timings?: {
|
|
40
|
-
setup?: number
|
|
41
|
-
[key: string]: number | undefined
|
|
19
|
+
```ts twoslash
|
|
20
|
+
import { defineNuxtModule } from '@nuxt/kit'
|
|
21
|
+
|
|
22
|
+
export default defineNuxtModule({
|
|
23
|
+
meta: {
|
|
24
|
+
name: 'my-module',
|
|
25
|
+
configKey: 'myModule'
|
|
26
|
+
},
|
|
27
|
+
defaults: {
|
|
28
|
+
enabled: true
|
|
29
|
+
},
|
|
30
|
+
setup (options) {
|
|
31
|
+
if (options.enabled) {
|
|
32
|
+
console.log('My Nuxt module is enabled!')
|
|
33
|
+
}
|
|
42
34
|
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
interface ModuleMeta {
|
|
46
|
-
name?: string
|
|
47
|
-
version?: string
|
|
48
|
-
configKey?: string
|
|
49
|
-
compatibility?: NuxtCompatibility
|
|
50
|
-
[key: string]: unknown
|
|
51
|
-
}
|
|
35
|
+
})
|
|
52
36
|
```
|
|
53
37
|
|
|
54
|
-
###
|
|
55
|
-
|
|
56
|
-
#### `definition`
|
|
57
|
-
|
|
58
|
-
**Type**: `ModuleDefinition<T> | NuxtModule<T>`
|
|
59
|
-
|
|
60
|
-
**Required**: `true`
|
|
61
|
-
|
|
62
|
-
A module definition object or a module function.
|
|
63
|
-
|
|
64
|
-
- `meta` (optional)
|
|
65
|
-
|
|
66
|
-
**Type**: `ModuleMeta`
|
|
67
|
-
|
|
68
|
-
Metadata of the module. It defines the module name, version, config key and compatibility.
|
|
69
|
-
|
|
70
|
-
- `defaults` (optional)
|
|
71
|
-
|
|
72
|
-
**Type**: `T | ((nuxt: Nuxt) => T)`
|
|
73
|
-
|
|
74
|
-
Default options for the module. If a function is provided, it will be called with the Nuxt instance as the first argument.
|
|
75
|
-
|
|
76
|
-
- `schema` (optional)
|
|
77
|
-
|
|
78
|
-
**Type**: `T`
|
|
79
|
-
|
|
80
|
-
Schema for the module options. If provided, options will be applied to the schema.
|
|
38
|
+
### Type
|
|
81
39
|
|
|
82
|
-
|
|
40
|
+
```ts twoslash
|
|
41
|
+
function defineNuxtModule (definition: ModuleDefinition | NuxtModule): NuxtModule
|
|
42
|
+
```
|
|
83
43
|
|
|
84
|
-
|
|
44
|
+
### Parameters
|
|
85
45
|
|
|
86
|
-
|
|
46
|
+
**definition**: A module definition object or a module function. The module definition object should contain the following properties:
|
|
87
47
|
|
|
88
|
-
|
|
48
|
+
| Property | Type | Required | Description |
|
|
49
|
+
| ------------------ | -------------------------------------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |
|
|
50
|
+
| `meta` | `ModuleMeta` | `false` | Metadata of the module. It defines the module name, version, config key and compatibility. |
|
|
51
|
+
| `defaults` | `T \| ((nuxt: Nuxt) => T)`{lang="ts"} | `false` | Default options for the module. If a function is provided, it will be called with the Nuxt instance as the first argument. |
|
|
52
|
+
| `schema` | `T` | `false` | Schema for the module options. If provided, options will be applied to the schema. |
|
|
53
|
+
| `hooks` | `Partial<NuxtHooks>`{lang="ts"} | `false` | Hooks to be installed for the module. If provided, the module will install the hooks. |
|
|
54
|
+
| `setup` | `(this: void, resolvedOptions: T, nuxt: Nuxt) => Awaitable<void \| false \| ModuleSetupInstallResult>`{lang="ts"} | `false` | Setup function for the module. If provided, the module will call the setup function. |
|
|
89
55
|
|
|
90
|
-
|
|
56
|
+
### Examples
|
|
91
57
|
|
|
92
|
-
|
|
58
|
+
#### Using `configKey` to Make Your Module Configurable
|
|
93
59
|
|
|
94
|
-
|
|
60
|
+
When defining a Nuxt module, you can set a `configKey` to specify how users should configure the module in their `nuxt.config`.
|
|
95
61
|
|
|
96
62
|
```ts
|
|
97
|
-
// https://github.com/nuxt/starter/tree/module
|
|
98
63
|
import { defineNuxtModule } from '@nuxt/kit'
|
|
99
64
|
|
|
100
65
|
export default defineNuxtModule({
|
|
@@ -103,51 +68,94 @@ export default defineNuxtModule({
|
|
|
103
68
|
configKey: 'myModule'
|
|
104
69
|
},
|
|
105
70
|
defaults: {
|
|
106
|
-
|
|
71
|
+
// Module options
|
|
72
|
+
enabled: true
|
|
107
73
|
},
|
|
108
|
-
setup (options
|
|
109
|
-
|
|
110
|
-
console.log('My module is
|
|
111
|
-
}
|
|
74
|
+
setup (options) {
|
|
75
|
+
if (options.enabled) {
|
|
76
|
+
console.log('My Nuxt module is enabled!')
|
|
77
|
+
}
|
|
112
78
|
}
|
|
113
79
|
})
|
|
114
80
|
```
|
|
115
81
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
Install specified Nuxt module programmatically. This is helpful when your module depends on other modules. You can pass the module options as an object to `inlineOptions` and they will be passed to the module's `setup` function.
|
|
119
|
-
|
|
120
|
-
### Type
|
|
82
|
+
Users can provide options for this module under the corresponding key in `nuxt.config`.
|
|
121
83
|
|
|
122
84
|
```ts
|
|
123
|
-
|
|
85
|
+
export default defineNuxtConfig({
|
|
86
|
+
myModule: {
|
|
87
|
+
enabled: false
|
|
88
|
+
}
|
|
89
|
+
})
|
|
124
90
|
```
|
|
125
91
|
|
|
126
|
-
|
|
92
|
+
#### Defining Module Compatibility Requirements
|
|
93
|
+
|
|
94
|
+
If you're developing a Nuxt module and using APIs that are only supported in specific Nuxt versions, it's highly recommended to include `compatibility.nuxt`.
|
|
127
95
|
|
|
128
|
-
|
|
96
|
+
```ts
|
|
97
|
+
export default defineNuxtModule({
|
|
98
|
+
meta: {
|
|
99
|
+
name: '@nuxt/icon',
|
|
100
|
+
configKey: 'icon',
|
|
101
|
+
compatibility: {
|
|
102
|
+
// Required nuxt version in semver format.
|
|
103
|
+
nuxt: '>=3.0.0', // or use '^3.0.0'
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
async setup() {
|
|
107
|
+
const resolver = createResolver(import.meta.url)
|
|
108
|
+
// Implement
|
|
109
|
+
},
|
|
110
|
+
})
|
|
111
|
+
```
|
|
129
112
|
|
|
130
|
-
|
|
113
|
+
If the user tries to use your module with an incompatible Nuxt version, they will receive a warning in the console.
|
|
131
114
|
|
|
132
|
-
|
|
115
|
+
```terminal
|
|
116
|
+
WARN Module @nuxt/icon is disabled due to incompatibility issues:
|
|
117
|
+
- [nuxt] Nuxt version ^3.1.0 is required but currently using 3.0.0
|
|
118
|
+
```
|
|
133
119
|
|
|
134
|
-
|
|
120
|
+
## `installModule`
|
|
135
121
|
|
|
136
|
-
|
|
122
|
+
Install specified Nuxt module programmatically. This is helpful when your module depends on other modules. You can pass the module options as an object to `inlineOptions` and they will be passed to the module's `setup` function.
|
|
137
123
|
|
|
138
|
-
|
|
124
|
+
### Usage
|
|
139
125
|
|
|
140
|
-
|
|
126
|
+
```ts twoslash
|
|
127
|
+
import { defineNuxtModule, installModule } from '@nuxt/kit'
|
|
141
128
|
|
|
142
|
-
|
|
129
|
+
export default defineNuxtModule({
|
|
130
|
+
async setup () {
|
|
131
|
+
// will install @nuxtjs/fontaine with Roboto font and Impact fallback
|
|
132
|
+
await installModule('@nuxtjs/fontaine', {
|
|
133
|
+
// module configuration
|
|
134
|
+
fonts: [
|
|
135
|
+
{
|
|
136
|
+
family: 'Roboto',
|
|
137
|
+
fallbacks: ['Impact'],
|
|
138
|
+
fallbackName: 'fallback-a',
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
```
|
|
143
145
|
|
|
144
|
-
|
|
146
|
+
### Type
|
|
145
147
|
|
|
146
|
-
|
|
148
|
+
```ts
|
|
149
|
+
async function installModule (moduleToInstall: string | NuxtModule, inlineOptions?: any, nuxt?: Nuxt)
|
|
150
|
+
```
|
|
147
151
|
|
|
148
|
-
|
|
152
|
+
### Parameters
|
|
149
153
|
|
|
150
|
-
|
|
154
|
+
| Property | Type | Required | Description |
|
|
155
|
+
| ------------------ | -------------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |
|
|
156
|
+
| `moduleToInstall` | `string \| NuxtModule`{lang="ts"} | `true` | The module to install. Can be either a string with the module name or a module object itself. |
|
|
157
|
+
| `inlineOptions` | `any` | `false` | An object with the module options to be passed to the module's `setup` function. |
|
|
158
|
+
| `nuxt` | `Nuxt` | `false` | Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call. |
|
|
151
159
|
|
|
152
160
|
### Examples
|
|
153
161
|
|
|
@@ -22,6 +22,8 @@ function useRuntimeConfig (): Record<string, unknown>
|
|
|
22
22
|
|
|
23
23
|
It is also possible to update runtime configuration. This will be merged with the existing runtime configuration, and if Nitro has already been initialized it will trigger an HMR event to reload the Nitro runtime config.
|
|
24
24
|
|
|
25
|
+
### Type
|
|
26
|
+
|
|
25
27
|
```ts
|
|
26
28
|
function updateRuntimeConfig (config: Record<string, unknown>): void | Promise<void>
|
|
27
29
|
```
|