@nuxt/docs 3.17.1 → 3.17.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/1.getting-started/01.introduction.md +1 -1
- package/1.getting-started/02.installation.md +8 -0
- package/1.getting-started/03.configuration.md +1 -1
- package/1.getting-started/07.routing.md +1 -1
- package/1.getting-started/15.prerendering.md +2 -2
- package/1.getting-started/16.deployment.md +2 -2
- package/1.getting-started/18.upgrade.md +42 -3
- package/2.guide/1.concepts/1.auto-imports.md +1 -1
- package/2.guide/1.concepts/3.rendering.md +2 -2
- package/2.guide/1.concepts/4.server-engine.md +1 -1
- package/2.guide/2.directory-structure/1.server.md +6 -6
- package/2.guide/3.going-further/1.events.md +82 -0
- package/2.guide/3.going-further/11.nightly-release-channel.md +1 -3
- package/2.guide/3.going-further/2.hooks.md +1 -20
- package/2.guide/3.going-further/3.modules.md +1 -1
- package/3.api/2.composables/use-request-url.md +2 -2
- package/3.api/3.utils/navigate-to.md +1 -1
- package/3.api/5.kit/1.modules.md +105 -92
- package/3.api/5.kit/10.runtime-config.md +2 -0
- package/3.api/5.kit/10.templates.md +187 -163
- package/3.api/5.kit/11.nitro.md +207 -168
- 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 +140 -373
- package/3.api/5.kit/2.programmatic.md +11 -64
- package/3.api/5.kit/3.compatibility.md +88 -135
- 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 +92 -48
- package/3.api/5.kit/7.pages.md +95 -197
- package/3.api/5.kit/8.layout.md +68 -49
- package/3.api/5.kit/9.plugins.md +140 -139
- package/3.api/6.advanced/1.hooks.md +1 -1
- package/package.json +1 -1
|
@@ -14,58 +14,42 @@ Sometimes you need to resolve a paths: relative to the current module, with unkn
|
|
|
14
14
|
|
|
15
15
|
Resolves full path to a file or directory respecting Nuxt alias and extensions options. If path could not be resolved, normalized input path will be returned.
|
|
16
16
|
|
|
17
|
-
###
|
|
17
|
+
### Usage
|
|
18
18
|
|
|
19
19
|
```ts
|
|
20
|
-
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### Parameters
|
|
24
|
-
|
|
25
|
-
#### `path`
|
|
26
|
-
|
|
27
|
-
**Type**: `string`
|
|
28
|
-
|
|
29
|
-
**Required**: `true`
|
|
30
|
-
|
|
31
|
-
Path to resolve.
|
|
32
|
-
|
|
33
|
-
#### `options`
|
|
34
|
-
|
|
35
|
-
**Type**: `ResolvePathOptions`
|
|
36
|
-
|
|
37
|
-
**Default**: `{}`
|
|
38
|
-
|
|
39
|
-
Options to pass to the resolver. This object can have the following properties:
|
|
40
|
-
|
|
41
|
-
- `cwd` (optional)
|
|
42
|
-
|
|
43
|
-
**Type**: `string`
|
|
44
|
-
|
|
45
|
-
**Default**: `process.cwd()`
|
|
46
|
-
|
|
47
|
-
Current working directory.
|
|
48
|
-
|
|
49
|
-
- `alias` (optional)
|
|
20
|
+
import { defineNuxtModule, resolvePath } from '@nuxt/kit'
|
|
50
21
|
|
|
51
|
-
|
|
22
|
+
export default defineNuxtModule({
|
|
23
|
+
async setup () {
|
|
24
|
+
const entrypoint = await resolvePath('@unhead/vue')
|
|
25
|
+
console.log(`Unhead entrypoint is ${entrypoint}`)
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
```
|
|
52
29
|
|
|
53
|
-
|
|
30
|
+
### Type
|
|
54
31
|
|
|
55
|
-
|
|
32
|
+
```ts
|
|
33
|
+
function resolvePath (path: string, options?: ResolvePathOptions): Promise<string>
|
|
34
|
+
```
|
|
56
35
|
|
|
57
|
-
|
|
36
|
+
### Parameters
|
|
58
37
|
|
|
59
|
-
|
|
38
|
+
**`path`**: A path to resolve.
|
|
60
39
|
|
|
61
|
-
|
|
40
|
+
**`options`**: Options to pass to the resolver. This object can have the following properties:
|
|
62
41
|
|
|
63
|
-
|
|
42
|
+
| Property | Type | Required | Description |
|
|
43
|
+
| -------------------- | ----------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
44
|
+
| `cwd` | `string` | `false` | Base for resolving paths from. Default is Nuxt rootDir. |
|
|
45
|
+
| `alias` | `Record<string, string>`{lang="ts"} | `false` | An object of aliases. Default is Nuxt configured aliases. |
|
|
46
|
+
| `extensions` | `string[]` | `false` | The file extensions to try. Default is Nuxt configured extensions. |
|
|
47
|
+
| `virtual` | `boolean` | `false` | Whether to resolve files that exist in the Nuxt VFS (for example, as a Nuxt template). |
|
|
48
|
+
| `fallbackToOriginal` | `boolean` | `false` | Whether to fallback to the original path if the resolved path does not exist instead of returning the normalized input path. |
|
|
64
49
|
|
|
65
50
|
### Examples
|
|
66
51
|
|
|
67
52
|
```ts
|
|
68
|
-
// https://github.com/P4sca1/nuxt-headlessui
|
|
69
53
|
import { defineNuxtModule, resolvePath } from '@nuxt/kit'
|
|
70
54
|
import { join } from 'pathe'
|
|
71
55
|
|
|
@@ -79,8 +63,8 @@ const headlessComponents: ComponentGroup[] = [
|
|
|
79
63
|
'ComboboxButton',
|
|
80
64
|
'ComboboxInput',
|
|
81
65
|
'ComboboxOptions',
|
|
82
|
-
'ComboboxOption'
|
|
83
|
-
]
|
|
66
|
+
'ComboboxOption',
|
|
67
|
+
],
|
|
84
68
|
},
|
|
85
69
|
]
|
|
86
70
|
|
|
@@ -90,7 +74,7 @@ export default defineNuxtModule({
|
|
|
90
74
|
configKey: 'headlessui',
|
|
91
75
|
},
|
|
92
76
|
defaults: {
|
|
93
|
-
prefix: 'Headless'
|
|
77
|
+
prefix: 'Headless',
|
|
94
78
|
},
|
|
95
79
|
async setup (options) {
|
|
96
80
|
const entrypoint = await resolvePath('@headlessui/vue')
|
|
@@ -104,12 +88,12 @@ export default defineNuxtModule({
|
|
|
104
88
|
export: e,
|
|
105
89
|
filePath: join(root, group.relativePath),
|
|
106
90
|
chunkName: group.chunkName,
|
|
107
|
-
mode: 'all'
|
|
108
|
-
}
|
|
91
|
+
mode: 'all',
|
|
92
|
+
},
|
|
109
93
|
)
|
|
110
94
|
}
|
|
111
95
|
}
|
|
112
|
-
}
|
|
96
|
+
},
|
|
113
97
|
})
|
|
114
98
|
```
|
|
115
99
|
|
|
@@ -125,87 +109,50 @@ function resolveAlias (path: string, alias?: Record<string, string>): string
|
|
|
125
109
|
|
|
126
110
|
### Parameters
|
|
127
111
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
**Type**: `string`
|
|
112
|
+
**`path`**: A path to resolve.
|
|
131
113
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
Path to resolve.
|
|
135
|
-
|
|
136
|
-
#### `alias`
|
|
137
|
-
|
|
138
|
-
**Type**: `Record<string, string>`
|
|
139
|
-
|
|
140
|
-
**Default**: `{}`
|
|
141
|
-
|
|
142
|
-
Alias map. If not provided, it will be read from `nuxt.options.alias`.
|
|
114
|
+
**`alias`**: An object of aliases. If not provided, it will be read from `nuxt.options.alias`.
|
|
143
115
|
|
|
144
116
|
## `findPath`
|
|
145
117
|
|
|
146
118
|
Try to resolve first existing file in given paths.
|
|
147
119
|
|
|
148
|
-
###
|
|
120
|
+
### Usage
|
|
149
121
|
|
|
150
122
|
```ts
|
|
151
|
-
|
|
123
|
+
import { defineNuxtModule, findPath } from '@nuxt/kit'
|
|
124
|
+
import { join } from 'pathe'
|
|
152
125
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
126
|
+
export default defineNuxtModule({
|
|
127
|
+
async setup (_, nuxt) {
|
|
128
|
+
// Resolve main (app.vue)
|
|
129
|
+
const mainComponent = await findPath([
|
|
130
|
+
join(nuxt.options.srcDir, 'App'),
|
|
131
|
+
join(nuxt.options.srcDir, 'app'),
|
|
132
|
+
])
|
|
133
|
+
},
|
|
134
|
+
})
|
|
158
135
|
```
|
|
159
136
|
|
|
160
|
-
###
|
|
161
|
-
|
|
162
|
-
#### `paths`
|
|
163
|
-
|
|
164
|
-
**Type**: `string | string[]`
|
|
165
|
-
|
|
166
|
-
**Required**: `true`
|
|
167
|
-
|
|
168
|
-
A path or an array of paths to resolve.
|
|
169
|
-
|
|
170
|
-
#### `options`
|
|
171
|
-
|
|
172
|
-
**Type**: `ResolvePathOptions`
|
|
173
|
-
|
|
174
|
-
**Default**: `{}`
|
|
175
|
-
|
|
176
|
-
Options to pass to the resolver. This object can have the following properties:
|
|
177
|
-
|
|
178
|
-
- `cwd` (optional)
|
|
179
|
-
|
|
180
|
-
**Type**: `string`
|
|
181
|
-
|
|
182
|
-
**Default**: `process.cwd()`
|
|
183
|
-
|
|
184
|
-
Current working directory.
|
|
185
|
-
|
|
186
|
-
- `alias` (optional)
|
|
187
|
-
|
|
188
|
-
**Type**: `Record<string, string>`
|
|
189
|
-
|
|
190
|
-
**Default**: `{}`
|
|
191
|
-
|
|
192
|
-
Alias map.
|
|
193
|
-
|
|
194
|
-
- `extensions` (optional)
|
|
195
|
-
|
|
196
|
-
**Type**: `string[]`
|
|
197
|
-
|
|
198
|
-
**Default**: `['.js', '.mjs', '.ts', '.jsx', '.tsx', '.json']`
|
|
137
|
+
### Type
|
|
199
138
|
|
|
200
|
-
|
|
139
|
+
```ts
|
|
140
|
+
function findPath (paths: string | string[], options?: ResolvePathOptions, pathType: 'file' | 'dir'): Promise<string | null>
|
|
141
|
+
```
|
|
201
142
|
|
|
202
|
-
|
|
143
|
+
### Parameters
|
|
203
144
|
|
|
204
|
-
|
|
145
|
+
**`paths`**: A path or an array of paths to resolve.
|
|
205
146
|
|
|
206
|
-
|
|
147
|
+
**`options`**: Options to pass to the resolver. This object can have the following properties:
|
|
207
148
|
|
|
208
|
-
|
|
149
|
+
| Property | Type | Required | Description |
|
|
150
|
+
| -------------------- | ----------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
151
|
+
| `cwd` | `string` | `false` | Base for resolving paths from. Default is Nuxt rootDir. |
|
|
152
|
+
| `alias` | `Record<string, string>`{lang="ts"} | `false` | An object of aliases. Default is Nuxt configured aliases. |
|
|
153
|
+
| `extensions` | `string[]` | `false` | The file extensions to try. Default is Nuxt configured extensions. |
|
|
154
|
+
| `virtual` | `boolean` | `false` | Whether to resolve files that exist in the Nuxt VFS (for example, as a Nuxt template). |
|
|
155
|
+
| `fallbackToOriginal` | `boolean` | `false` | Whether to fallback to the original path if the resolved path does not exist instead of returning the normalized input path. |
|
|
209
156
|
|
|
210
157
|
## `createResolver`
|
|
211
158
|
|
|
@@ -215,45 +162,44 @@ Creates resolver relative to base path.
|
|
|
215
162
|
Watch Vue School video about createResolver.
|
|
216
163
|
::
|
|
217
164
|
|
|
218
|
-
###
|
|
165
|
+
### Usage
|
|
219
166
|
|
|
220
167
|
```ts
|
|
221
|
-
|
|
168
|
+
import { defineNuxtModule, createResolver } from '@nuxt/kit'
|
|
222
169
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
170
|
+
export default defineNuxtModule({
|
|
171
|
+
async setup (_, nuxt) {
|
|
172
|
+
const { resolve, resolvePath } = createResolver(import.meta.url)
|
|
173
|
+
},
|
|
174
|
+
})
|
|
175
|
+
```
|
|
227
176
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
177
|
+
### Type
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
function createResolver (basePath: string | URL): Resolver
|
|
233
181
|
```
|
|
234
182
|
|
|
235
183
|
### Parameters
|
|
236
184
|
|
|
237
|
-
|
|
185
|
+
**`basePath`**: A base path to resolve from. It can be a string or a URL.
|
|
238
186
|
|
|
239
|
-
|
|
187
|
+
### Return Value
|
|
240
188
|
|
|
241
|
-
|
|
189
|
+
The `createResolver` function returns an object with the following properties:
|
|
242
190
|
|
|
243
|
-
|
|
191
|
+
| Property | Type | Description |
|
|
192
|
+
| ------------- | ---------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
|
|
193
|
+
| `resolve` | `(path: string) => string`{lang="ts"} | A function that resolves a path relative to the base path. |
|
|
194
|
+
| `resolvePath` | `(path: string, options?: ResolvePathOptions) => Promise<string>`{lang="ts"} | A function that resolves a path relative to the base path and respects Nuxt alias and extensions options. |
|
|
244
195
|
|
|
245
196
|
### Examples
|
|
246
197
|
|
|
247
198
|
```ts
|
|
248
|
-
|
|
249
|
-
import {
|
|
250
|
-
defineNuxtModule,
|
|
251
|
-
isNuxt2,
|
|
252
|
-
createResolver,
|
|
253
|
-
} from '@nuxt/kit'
|
|
199
|
+
import { createResolver, defineNuxtModule, isNuxt2 } from '@nuxt/kit'
|
|
254
200
|
|
|
255
201
|
export default defineNuxtModule({
|
|
256
|
-
setup(options, nuxt) {
|
|
202
|
+
setup (options, nuxt) {
|
|
257
203
|
const resolver = createResolver(import.meta.url)
|
|
258
204
|
|
|
259
205
|
nuxt.hook('modules:done', () => {
|
|
@@ -263,6 +209,6 @@ export default defineNuxtModule({
|
|
|
263
209
|
addPlugin(resolver.resolve('./runtime/plugin.vue3'))
|
|
264
210
|
}
|
|
265
211
|
})
|
|
266
|
-
}
|
|
212
|
+
},
|
|
267
213
|
})
|
|
268
214
|
```
|
|
@@ -14,6 +14,20 @@ Nuxt provides a logger instance that you can use to log messages with extra feat
|
|
|
14
14
|
|
|
15
15
|
Returns a logger instance. It uses [consola](https://github.com/unjs/consola) under the hood.
|
|
16
16
|
|
|
17
|
+
### Usage
|
|
18
|
+
|
|
19
|
+
```ts twoslash
|
|
20
|
+
import { defineNuxtModule, useLogger } from '@nuxt/kit'
|
|
21
|
+
|
|
22
|
+
export default defineNuxtModule({
|
|
23
|
+
setup (options, nuxt) {
|
|
24
|
+
const logger = useLogger('my-module')
|
|
25
|
+
|
|
26
|
+
logger.info('Hello from my module!')
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
17
31
|
### Type
|
|
18
32
|
|
|
19
33
|
```ts
|
|
@@ -22,44 +36,20 @@ function useLogger (tag?: string, options?: Partial<ConsolaOptions>): ConsolaIns
|
|
|
22
36
|
|
|
23
37
|
### Parameters
|
|
24
38
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
**Type**: `string`
|
|
28
|
-
|
|
29
|
-
**Optional**: `true`
|
|
30
|
-
|
|
31
|
-
A tag to prefix all log messages with.
|
|
32
|
-
|
|
33
|
-
#### `options`
|
|
39
|
+
**`tag`**: A tag to suffix all log messages with.
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
**Optional**: `true`
|
|
38
|
-
|
|
39
|
-
Consola configuration options
|
|
41
|
+
**`options`**: Consola configuration options.
|
|
40
42
|
|
|
41
43
|
### Examples
|
|
42
44
|
|
|
43
|
-
```ts
|
|
44
|
-
import { defineNuxtModule, useLogger } from '@nuxt/kit'
|
|
45
|
-
|
|
46
|
-
export default defineNuxtModule({
|
|
47
|
-
setup(options, nuxt) {
|
|
48
|
-
const logger = useLogger('my-module')
|
|
49
|
-
|
|
50
|
-
logger.info('Hello from my module!')
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
```ts
|
|
45
|
+
```ts twoslash
|
|
56
46
|
import { defineNuxtModule, useLogger } from '@nuxt/kit'
|
|
57
47
|
|
|
58
48
|
export default defineNuxtModule({
|
|
59
|
-
setup(options, nuxt) {
|
|
49
|
+
setup (options, nuxt) {
|
|
60
50
|
const logger = useLogger('my-module', { level: options.quiet ? 0 : 3 })
|
|
61
51
|
|
|
62
52
|
logger.info('Hello from my module!')
|
|
63
|
-
}
|
|
53
|
+
},
|
|
64
54
|
})
|
|
65
55
|
```
|