@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,268 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Resolving
|
|
3
|
+
description: Nuxt Kit provides a set of utilities to help you resolve paths. These functions allow you to resolve paths relative to the current module, with unknown name or extension.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/kit/src/resolve.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Sometimes you need to resolve a paths: relative to the current module, with unknown name or extension. For example, you may want to add a plugin that is located in the same directory as the module. To handle this cases, nuxt provides a set of utilities to resolve paths. `resolvePath` and `resolveAlias` are used to resolve paths relative to the current module. `findPath` is used to find first existing file in given paths. `createResolver` is used to create resolver relative to base path.
|
|
12
|
+
|
|
13
|
+
## `resolvePath`
|
|
14
|
+
|
|
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
|
+
|
|
17
|
+
### Type
|
|
18
|
+
|
|
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)
|
|
50
|
+
|
|
51
|
+
**Type**: `Record<string, string>`
|
|
52
|
+
|
|
53
|
+
**Default**: `{}`
|
|
54
|
+
|
|
55
|
+
Alias map.
|
|
56
|
+
|
|
57
|
+
- `extensions` (optional)
|
|
58
|
+
|
|
59
|
+
**Type**: `string[]`
|
|
60
|
+
|
|
61
|
+
**Default**: `['.js', '.mjs', '.ts', '.jsx', '.tsx', '.json']`
|
|
62
|
+
|
|
63
|
+
Extensions to try.
|
|
64
|
+
|
|
65
|
+
### Examples
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
// https://github.com/P4sca1/nuxt-headlessui
|
|
69
|
+
import { defineNuxtModule, resolvePath } from '@nuxt/kit'
|
|
70
|
+
import { join } from 'pathe'
|
|
71
|
+
|
|
72
|
+
const headlessComponents: ComponentGroup[] = [
|
|
73
|
+
{
|
|
74
|
+
relativePath: 'combobox/combobox.js',
|
|
75
|
+
chunkName: 'headlessui/combobox',
|
|
76
|
+
exports: [
|
|
77
|
+
'Combobox',
|
|
78
|
+
'ComboboxLabel',
|
|
79
|
+
'ComboboxButton',
|
|
80
|
+
'ComboboxInput',
|
|
81
|
+
'ComboboxOptions',
|
|
82
|
+
'ComboboxOption'
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
export default defineNuxtModule({
|
|
88
|
+
meta: {
|
|
89
|
+
name: 'nuxt-headlessui',
|
|
90
|
+
configKey: 'headlessui',
|
|
91
|
+
},
|
|
92
|
+
defaults: {
|
|
93
|
+
prefix: 'Headless'
|
|
94
|
+
},
|
|
95
|
+
async setup (options) {
|
|
96
|
+
const entrypoint = await resolvePath('@headlessui/vue')
|
|
97
|
+
const root = join(entrypoint, '../components')
|
|
98
|
+
|
|
99
|
+
for (const group of headlessComponents) {
|
|
100
|
+
for (const e of group.exports) {
|
|
101
|
+
addComponent(
|
|
102
|
+
{
|
|
103
|
+
name: e,
|
|
104
|
+
export: e,
|
|
105
|
+
filePath: join(root, group.relativePath),
|
|
106
|
+
chunkName: group.chunkName,
|
|
107
|
+
mode: 'all'
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## `resolveAlias`
|
|
117
|
+
|
|
118
|
+
Resolves path aliases respecting Nuxt alias options.
|
|
119
|
+
|
|
120
|
+
### Type
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
function resolveAlias (path: string, alias?: Record<string, string>): string
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Parameters
|
|
127
|
+
|
|
128
|
+
#### `path`
|
|
129
|
+
|
|
130
|
+
**Type**: `string`
|
|
131
|
+
|
|
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`.
|
|
143
|
+
|
|
144
|
+
## `findPath`
|
|
145
|
+
|
|
146
|
+
Try to resolve first existing file in given paths.
|
|
147
|
+
|
|
148
|
+
### Type
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
async function findPath (paths: string | string[], options?: ResolvePathOptions, pathType: 'file' | 'dir'): Promise<string | null>
|
|
152
|
+
|
|
153
|
+
interface ResolvePathOptions {
|
|
154
|
+
cwd?: string
|
|
155
|
+
alias?: Record<string, string>
|
|
156
|
+
extensions?: string[]
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
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']`
|
|
199
|
+
|
|
200
|
+
Extensions to try.
|
|
201
|
+
|
|
202
|
+
#### `pathType`
|
|
203
|
+
|
|
204
|
+
**Type**: `'file' | 'dir'`
|
|
205
|
+
|
|
206
|
+
**Default**: `'file'`
|
|
207
|
+
|
|
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.
|
|
209
|
+
|
|
210
|
+
## `createResolver`
|
|
211
|
+
|
|
212
|
+
Creates resolver relative to base path.
|
|
213
|
+
|
|
214
|
+
::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/resolving-paths-and-injecting-assets-to-the-app?friend=nuxt" target="_blank"}
|
|
215
|
+
Watch Vue School video about createResolver.
|
|
216
|
+
::
|
|
217
|
+
|
|
218
|
+
### Type
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
function createResolver (basePath: string | URL): Resolver
|
|
222
|
+
|
|
223
|
+
interface Resolver {
|
|
224
|
+
resolve (...path: string[]): string
|
|
225
|
+
resolvePath (path: string, options?: ResolvePathOptions): Promise<string>
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
interface ResolvePathOptions {
|
|
229
|
+
cwd?: string
|
|
230
|
+
alias?: Record<string, string>
|
|
231
|
+
extensions?: string[]
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Parameters
|
|
236
|
+
|
|
237
|
+
#### `basePath`
|
|
238
|
+
|
|
239
|
+
**Type**: `string`
|
|
240
|
+
|
|
241
|
+
**Required**: `true`
|
|
242
|
+
|
|
243
|
+
Base path to resolve from.
|
|
244
|
+
|
|
245
|
+
### Examples
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
// https://github.com/vuejs/pinia/blob/v2/packages/nuxt
|
|
249
|
+
import {
|
|
250
|
+
defineNuxtModule,
|
|
251
|
+
isNuxt2,
|
|
252
|
+
createResolver,
|
|
253
|
+
} from '@nuxt/kit'
|
|
254
|
+
|
|
255
|
+
export default defineNuxtModule({
|
|
256
|
+
setup(options, nuxt) {
|
|
257
|
+
const resolver = createResolver(import.meta.url)
|
|
258
|
+
|
|
259
|
+
nuxt.hook('modules:done', () => {
|
|
260
|
+
if (isNuxt2()) {
|
|
261
|
+
addPlugin(resolver.resolve('./runtime/plugin.vue2'))
|
|
262
|
+
} else {
|
|
263
|
+
addPlugin(resolver.resolve('./runtime/plugin.vue3'))
|
|
264
|
+
}
|
|
265
|
+
})
|
|
266
|
+
}
|
|
267
|
+
})
|
|
268
|
+
```
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Logging"
|
|
3
|
+
description: Nuxt Kit provides a set of utilities to help you work with logging. These functions allow you to log messages with extra features.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/kit/src/logger.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Nuxt provides a logger instance that you can use to log messages with extra features. `useLogger` allows you to get a logger instance.
|
|
12
|
+
|
|
13
|
+
## `useLogger`
|
|
14
|
+
|
|
15
|
+
Returns a logger instance. It uses [consola](https://github.com/unjs/consola) under the hood.
|
|
16
|
+
|
|
17
|
+
### Type
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
function useLogger (tag?: string, options?: Partial<ConsolaOptions>): ConsolaInstance
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Parameters
|
|
24
|
+
|
|
25
|
+
#### `tag`
|
|
26
|
+
|
|
27
|
+
**Type**: `string`
|
|
28
|
+
|
|
29
|
+
**Optional**: `true`
|
|
30
|
+
|
|
31
|
+
A tag to prefix all log messages with.
|
|
32
|
+
|
|
33
|
+
#### `options`
|
|
34
|
+
|
|
35
|
+
**Type**: `Partial<ConsolaOptions>`
|
|
36
|
+
|
|
37
|
+
**Optional**: `true`
|
|
38
|
+
|
|
39
|
+
Consola configuration options
|
|
40
|
+
|
|
41
|
+
### Examples
|
|
42
|
+
|
|
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
|
|
56
|
+
import { defineNuxtModule, useLogger } from '@nuxt/kit'
|
|
57
|
+
|
|
58
|
+
export default defineNuxtModule({
|
|
59
|
+
setup(options, nuxt) {
|
|
60
|
+
const logger = useLogger('my-module', { level: options.quiet ? 0 : 3 })
|
|
61
|
+
|
|
62
|
+
logger.info('Hello from my module!')
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
```
|