@nuxt/docs 3.17.0 → 3.17.2

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.
@@ -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
- ### Type
17
+ ### Usage
18
18
 
19
19
  ```ts
20
- async function resolvePath (path: string, options?: ResolvePathOptions): Promise<string>
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
- **Type**: `Record<string, string>`
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
- **Default**: `{}`
30
+ ### Type
54
31
 
55
- Alias map.
32
+ ```ts
33
+ function resolvePath (path: string, options?: ResolvePathOptions): Promise<string>
34
+ ```
56
35
 
57
- - `extensions` (optional)
36
+ ### Parameters
58
37
 
59
- **Type**: `string[]`
38
+ **`path`**: A path to resolve.
60
39
 
61
- **Default**: `['.js', '.mjs', '.ts', '.jsx', '.tsx', '.json']`
40
+ **`options`**: Options to pass to the resolver. This object can have the following properties:
62
41
 
63
- Extensions to try.
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
- #### `path`
129
-
130
- **Type**: `string`
112
+ **`path`**: A path to resolve.
131
113
 
132
- **Required**: `true`
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
- ### Type
120
+ ### Usage
149
121
 
150
122
  ```ts
151
- async function findPath (paths: string | string[], options?: ResolvePathOptions, pathType: 'file' | 'dir'): Promise<string | null>
123
+ import { defineNuxtModule, findPath } from '@nuxt/kit'
124
+ import { join } from 'pathe'
152
125
 
153
- interface ResolvePathOptions {
154
- cwd?: string
155
- alias?: Record<string, string>
156
- extensions?: string[]
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
- ### Parameters
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
- Extensions to try.
139
+ ```ts
140
+ function findPath (paths: string | string[], options?: ResolvePathOptions, pathType: 'file' | 'dir'): Promise<string | null>
141
+ ```
201
142
 
202
- #### `pathType`
143
+ ### Parameters
203
144
 
204
- **Type**: `'file' | 'dir'`
145
+ **`paths`**: A path or an array of paths to resolve.
205
146
 
206
- **Default**: `'file'`
147
+ **`options`**: Options to pass to the resolver. This object can have the following properties:
207
148
 
208
- Type of path to resolve. If set to `'file'`, the function will try to resolve a file. If set to `'dir'`, the function will try to resolve a directory.
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
- ### Type
165
+ ### Usage
219
166
 
220
167
  ```ts
221
- function createResolver (basePath: string | URL): Resolver
168
+ import { defineNuxtModule, createResolver } from '@nuxt/kit'
222
169
 
223
- interface Resolver {
224
- resolve (...path: string[]): string
225
- resolvePath (path: string, options?: ResolvePathOptions): Promise<string>
226
- }
170
+ export default defineNuxtModule({
171
+ async setup (_, nuxt) {
172
+ const { resolve, resolvePath } = createResolver(import.meta.url)
173
+ },
174
+ })
175
+ ```
227
176
 
228
- interface ResolvePathOptions {
229
- cwd?: string
230
- alias?: Record<string, string>
231
- extensions?: string[]
232
- }
177
+ ### Type
178
+
179
+ ```ts
180
+ function createResolver (basePath: string | URL): Resolver
233
181
  ```
234
182
 
235
183
  ### Parameters
236
184
 
237
- #### `basePath`
185
+ **`basePath`**: A base path to resolve from. It can be a string or a URL.
238
186
 
239
- **Type**: `string`
187
+ ### Return Value
240
188
 
241
- **Required**: `true`
189
+ The `createResolver` function returns an object with the following properties:
242
190
 
243
- Base path to resolve from.
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
- // https://github.com/vuejs/pinia/blob/v2/packages/nuxt
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
- #### `tag`
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
- **Type**: `Partial<ConsolaOptions>`
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
  ```