@nuxt/docs-nightly 4.1.3-29314777.50febbbb → 4.1.3-29316225.304409da
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/03.configuration.md +19 -19
- package/1.getting-started/04.views.md +1 -1
- package/1.getting-started/05.assets.md +8 -2
- package/1.getting-started/06.styling.md +50 -40
- package/1.getting-started/07.routing.md +4 -4
- package/1.getting-started/08.seo-meta.md +46 -33
- package/1.getting-started/09.transitions.md +38 -33
- package/1.getting-started/10.data-fetching.md +47 -39
- package/1.getting-started/11.state-management.md +15 -8
- package/1.getting-started/12.error-handling.md +6 -4
- package/1.getting-started/13.server.md +3 -3
- package/1.getting-started/14.layers.md +18 -12
- package/1.getting-started/15.prerendering.md +24 -24
- package/1.getting-started/16.deployment.md +7 -7
- package/1.getting-started/17.testing.md +41 -41
- package/1.getting-started/18.upgrade.md +48 -66
- package/2.guide/1.directory-structure/1.app/1.components.md +36 -19
- package/2.guide/1.directory-structure/1.app/1.composables.md +7 -7
- package/2.guide/1.directory-structure/1.app/1.layouts.md +9 -5
- package/2.guide/1.directory-structure/1.app/1.middleware.md +20 -14
- package/2.guide/1.directory-structure/1.app/1.pages.md +19 -17
- package/2.guide/1.directory-structure/1.app/1.plugins.md +17 -17
- package/2.guide/1.directory-structure/1.app/1.utils.md +1 -1
- package/2.guide/1.directory-structure/1.app/3.app-config.md +6 -6
- package/2.guide/1.directory-structure/1.app/3.error.md +4 -4
- package/2.guide/1.directory-structure/1.content.md +4 -1
- package/2.guide/1.directory-structure/1.modules.md +4 -4
- package/2.guide/1.directory-structure/1.public.md +1 -1
- package/2.guide/1.directory-structure/1.server.md +28 -28
- package/2.guide/1.directory-structure/1.shared.md +1 -1
- package/2.guide/2.concepts/1.auto-imports.md +11 -11
- package/2.guide/2.concepts/2.vuejs-development.md +5 -5
- package/2.guide/2.concepts/3.rendering.md +14 -12
- package/2.guide/2.concepts/5.modules.md +2 -2
- package/2.guide/2.concepts/7.esm.md +14 -12
- package/2.guide/2.concepts/8.typescript.md +4 -4
- package/2.guide/3.going-further/1.events.md +2 -2
- package/2.guide/3.going-further/1.experimental-features.md +234 -73
- package/2.guide/3.going-further/1.features.md +44 -9
- package/2.guide/3.going-further/1.internals.md +15 -15
- package/2.guide/3.going-further/10.runtime-config.md +7 -7
- package/2.guide/3.going-further/2.hooks.md +8 -8
- package/2.guide/3.going-further/3.modules.md +76 -74
- package/2.guide/3.going-further/4.kit.md +3 -3
- package/2.guide/3.going-further/6.nuxt-app.md +1 -1
- package/2.guide/3.going-further/7.layers.md +50 -41
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +19 -19
- package/2.guide/4.recipes/2.vite-plugin.md +3 -3
- package/2.guide/4.recipes/3.custom-usefetch.md +9 -9
- package/2.guide/4.recipes/4.sessions-and-authentication.md +33 -19
- package/2.guide/5.best-practices/performance.md +8 -8
- package/3.api/1.components/1.client-only.md +6 -3
- package/3.api/1.components/1.nuxt-client-fallback.md +9 -6
- package/3.api/1.components/11.teleports.md +4 -1
- package/3.api/1.components/12.nuxt-route-announcer.md +7 -7
- package/3.api/1.components/13.nuxt-time.md +44 -17
- package/3.api/1.components/2.nuxt-page.md +2 -2
- package/3.api/1.components/3.nuxt-layout.md +9 -4
- package/3.api/1.components/4.nuxt-link.md +38 -18
- package/3.api/1.components/6.nuxt-error-boundary.md +11 -9
- package/3.api/2.composables/on-prehydrate.md +2 -2
- package/3.api/2.composables/use-async-data.md +11 -11
- package/3.api/2.composables/use-cookie.md +26 -18
- package/3.api/2.composables/use-error.md +1 -1
- package/3.api/2.composables/use-fetch.md +13 -13
- package/3.api/2.composables/use-head-safe.md +5 -5
- package/3.api/2.composables/use-head.md +2 -2
- package/3.api/2.composables/use-hydration.md +5 -5
- package/3.api/2.composables/use-loading-indicator.md +10 -10
- package/3.api/2.composables/use-nuxt-app.md +9 -9
- package/3.api/2.composables/use-nuxt-data.md +7 -7
- package/3.api/2.composables/use-preview-mode.md +12 -15
- package/3.api/2.composables/use-request-fetch.md +1 -1
- package/3.api/2.composables/use-request-headers.md +3 -3
- package/3.api/2.composables/use-response-header.md +7 -8
- package/3.api/2.composables/use-route-announcer.md +3 -3
- package/3.api/2.composables/use-router.md +5 -3
- package/3.api/2.composables/use-runtime-config.md +6 -6
- package/3.api/2.composables/use-runtime-hook.md +1 -1
- package/3.api/2.composables/use-seo-meta.md +1 -1
- package/3.api/2.composables/use-server-seo-meta.md +1 -1
- package/3.api/2.composables/use-state.md +3 -3
- package/3.api/3.utils/$fetch.md +5 -3
- package/3.api/3.utils/abort-navigation.md +2 -2
- package/3.api/3.utils/add-route-middleware.md +3 -3
- package/3.api/3.utils/call-once.md +3 -3
- package/3.api/3.utils/clear-error.md +1 -1
- package/3.api/3.utils/clear-nuxt-data.md +2 -2
- package/3.api/3.utils/clear-nuxt-state.md +2 -2
- package/3.api/3.utils/create-error.md +1 -1
- package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
- package/3.api/3.utils/define-nuxt-component.md +5 -5
- package/3.api/3.utils/define-nuxt-plugin.md +11 -11
- package/3.api/3.utils/define-nuxt-route-middleware.md +2 -2
- package/3.api/3.utils/define-page-meta.md +14 -14
- package/3.api/3.utils/define-route-rules.md +3 -3
- package/3.api/3.utils/navigate-to.md +9 -9
- package/3.api/3.utils/preload-components.md +1 -1
- package/3.api/3.utils/prerender-routes.md +2 -2
- package/3.api/3.utils/refresh-cookie.md +3 -3
- package/3.api/3.utils/refresh-nuxt-data.md +9 -4
- package/3.api/3.utils/reload-nuxt-app.md +2 -2
- package/3.api/3.utils/set-response-status.md +1 -1
- package/3.api/3.utils/show-error.md +2 -2
- package/3.api/3.utils/update-app-config.md +2 -1
- package/3.api/4.commands/prepare.md +4 -0
- package/3.api/5.kit/1.modules.md +36 -36
- package/3.api/5.kit/10.templates.md +8 -6
- package/3.api/5.kit/11.nitro.md +62 -62
- package/3.api/5.kit/12.resolving.md +2 -2
- package/3.api/5.kit/14.builder.md +1 -0
- package/3.api/5.kit/15.examples.md +2 -2
- package/3.api/5.kit/16.layers.md +26 -26
- package/3.api/5.kit/3.compatibility.md +12 -12
- package/3.api/5.kit/4.autoimports.md +12 -12
- package/3.api/5.kit/5.components.md +5 -5
- package/3.api/5.kit/6.context.md +3 -3
- package/3.api/5.kit/7.pages.md +4 -4
- package/3.api/5.kit/8.layout.md +1 -1
- package/3.api/5.kit/9.plugins.md +5 -4
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/3.api/6.nuxt-config.md +293 -858
- package/6.bridge/1.overview.md +1 -1
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +2 -2
- package/6.bridge/3.bridge-composition-api.md +2 -2
- package/6.bridge/4.plugins-and-middleware.md +5 -5
- package/6.bridge/5.nuxt3-compatible-api.md +11 -8
- package/6.bridge/6.meta.md +15 -14
- package/6.bridge/8.nitro.md +2 -2
- package/6.bridge/9.vite.md +3 -3
- package/7.migration/2.configuration.md +17 -15
- package/7.migration/4.meta.md +17 -14
- package/7.migration/5.plugins-and-middleware.md +5 -5
- package/7.migration/6.pages-and-layouts.md +15 -11
- package/7.migration/7.component-options.md +3 -3
- package/7.migration/8.runtime-config.md +3 -3
- package/package.json +1 -1
package/3.api/5.kit/11.nitro.md
CHANGED
|
@@ -17,17 +17,17 @@ Adds a Nitro server handler. Use this if you want to create server middleware or
|
|
|
17
17
|
### Usage
|
|
18
18
|
|
|
19
19
|
```ts twoslash
|
|
20
|
-
import { createResolver, defineNuxtModule
|
|
20
|
+
import { addServerHandler, createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
21
21
|
|
|
22
22
|
export default defineNuxtModule({
|
|
23
|
-
setup(options) {
|
|
23
|
+
setup (options) {
|
|
24
24
|
const { resolve } = createResolver(import.meta.url)
|
|
25
25
|
|
|
26
26
|
addServerHandler({
|
|
27
27
|
route: '/robots.txt',
|
|
28
|
-
handler: resolve('./runtime/robots.get')
|
|
28
|
+
handler: resolve('./runtime/robots.get'),
|
|
29
29
|
})
|
|
30
|
-
}
|
|
30
|
+
},
|
|
31
31
|
})
|
|
32
32
|
```
|
|
33
33
|
|
|
@@ -58,24 +58,24 @@ You can use `addServerHandler` to add a server handler from your module.
|
|
|
58
58
|
::code-group
|
|
59
59
|
|
|
60
60
|
```ts twoslash [module.ts]
|
|
61
|
-
import { createResolver, defineNuxtModule
|
|
61
|
+
import { addServerHandler, createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
62
62
|
|
|
63
63
|
export default defineNuxtModule({
|
|
64
|
-
setup(options) {
|
|
64
|
+
setup (options) {
|
|
65
65
|
const { resolve } = createResolver(import.meta.url)
|
|
66
66
|
|
|
67
67
|
addServerHandler({
|
|
68
68
|
route: '/robots.txt',
|
|
69
|
-
handler: resolve('./runtime/robots.get')
|
|
69
|
+
handler: resolve('./runtime/robots.get'),
|
|
70
70
|
})
|
|
71
|
-
}
|
|
71
|
+
},
|
|
72
72
|
})
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
```ts twoslash [runtime/robots.get.ts]
|
|
76
76
|
export default defineEventHandler(() => {
|
|
77
77
|
return {
|
|
78
|
-
body: `User-agent: *\nDisallow:
|
|
78
|
+
body: `User-agent: *\nDisallow: /`,
|
|
79
79
|
}
|
|
80
80
|
})
|
|
81
81
|
```
|
|
@@ -97,19 +97,19 @@ Adds a Nitro server handler to be used only in development mode. This handler wi
|
|
|
97
97
|
|
|
98
98
|
```ts twoslash
|
|
99
99
|
import { defineEventHandler } from 'h3'
|
|
100
|
-
import { createResolver, defineNuxtModule
|
|
100
|
+
import { addDevServerHandler, createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
101
101
|
|
|
102
102
|
export default defineNuxtModule({
|
|
103
|
-
setup() {
|
|
103
|
+
setup () {
|
|
104
104
|
addDevServerHandler({
|
|
105
105
|
handler: defineEventHandler(() => {
|
|
106
106
|
return {
|
|
107
|
-
body: `Response generated at ${new Date().toISOString()}
|
|
107
|
+
body: `Response generated at ${new Date().toISOString()}`,
|
|
108
108
|
}
|
|
109
109
|
}),
|
|
110
|
-
route: '/_handler'
|
|
110
|
+
route: '/_handler',
|
|
111
111
|
})
|
|
112
|
-
}
|
|
112
|
+
},
|
|
113
113
|
})
|
|
114
114
|
```
|
|
115
115
|
|
|
@@ -139,18 +139,18 @@ In some cases, you may want to create a server handler specifically for developm
|
|
|
139
139
|
|
|
140
140
|
```ts
|
|
141
141
|
import { joinURL } from 'ufo'
|
|
142
|
-
import {
|
|
142
|
+
import { addDevServerHandler, defineNuxtModule } from '@nuxt/kit'
|
|
143
143
|
|
|
144
144
|
export default defineNuxtModule({
|
|
145
|
-
async setup(options, nuxt) {
|
|
145
|
+
async setup (options, nuxt) {
|
|
146
146
|
const route = joinURL(nuxt.options.app?.baseURL, '/_tailwind')
|
|
147
147
|
|
|
148
|
-
// @ts-
|
|
148
|
+
// @ts-expect-error - tailwind-config-viewer does not have correct types
|
|
149
149
|
const createServer = await import('tailwind-config-viewer/server/index.js').then(r => r.default || r) as any
|
|
150
150
|
const viewerDevMiddleware = createServer({ tailwindConfigProvider: () => options, routerPrefix: route }).asMiddleware()
|
|
151
151
|
|
|
152
152
|
addDevServerHandler({ route, handler: viewerDevMiddleware })
|
|
153
|
-
}
|
|
153
|
+
},
|
|
154
154
|
})
|
|
155
155
|
```
|
|
156
156
|
|
|
@@ -172,14 +172,14 @@ Changes to the Nitro instance configuration are not applied.
|
|
|
172
172
|
import { defineNuxtModule, useNitro } from '@nuxt/kit'
|
|
173
173
|
|
|
174
174
|
export default defineNuxtModule({
|
|
175
|
-
setup(options, nuxt) {
|
|
175
|
+
setup (options, nuxt) {
|
|
176
176
|
const resolver = createResolver(import.meta.url)
|
|
177
177
|
|
|
178
178
|
nuxt.hook('ready', () => {
|
|
179
179
|
const nitro = useNitro()
|
|
180
180
|
// Do something with Nitro instance
|
|
181
181
|
})
|
|
182
|
-
}
|
|
182
|
+
},
|
|
183
183
|
})
|
|
184
184
|
```
|
|
185
185
|
|
|
@@ -200,13 +200,13 @@ You can read more about Nitro plugins in the [Nitro documentation](https://nitro
|
|
|
200
200
|
### Usage
|
|
201
201
|
|
|
202
202
|
```ts twoslash
|
|
203
|
-
import { createResolver, defineNuxtModule
|
|
203
|
+
import { addServerPlugin, createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
204
204
|
|
|
205
205
|
export default defineNuxtModule({
|
|
206
|
-
setup() {
|
|
206
|
+
setup () {
|
|
207
207
|
const { resolve } = createResolver(import.meta.url)
|
|
208
208
|
addServerPlugin(resolve('./runtime/plugin.ts'))
|
|
209
|
-
}
|
|
209
|
+
},
|
|
210
210
|
})
|
|
211
211
|
```
|
|
212
212
|
|
|
@@ -227,30 +227,30 @@ function addServerPlugin (plugin: string): void
|
|
|
227
227
|
::code-group
|
|
228
228
|
|
|
229
229
|
```ts [module.ts]
|
|
230
|
-
import { createResolver, defineNuxtModule
|
|
230
|
+
import { addServerPlugin, createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
231
231
|
|
|
232
232
|
export default defineNuxtModule({
|
|
233
|
-
setup() {
|
|
233
|
+
setup () {
|
|
234
234
|
const { resolve } = createResolver(import.meta.url)
|
|
235
235
|
addServerPlugin(resolve('./runtime/plugin.ts'))
|
|
236
|
-
}
|
|
236
|
+
},
|
|
237
237
|
})
|
|
238
238
|
```
|
|
239
239
|
|
|
240
240
|
```ts [runtime/plugin.ts]
|
|
241
241
|
export default defineNitroPlugin((nitroApp) => {
|
|
242
|
-
nitroApp.hooks.hook(
|
|
243
|
-
console.log(
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
nitroApp.hooks.hook(
|
|
247
|
-
console.log(
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
nitroApp.hooks.hook(
|
|
251
|
-
console.log(
|
|
252
|
-
})
|
|
253
|
-
})
|
|
242
|
+
nitroApp.hooks.hook('request', (event) => {
|
|
243
|
+
console.log('on request', event.path)
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
nitroApp.hooks.hook('beforeResponse', (event, { body }) => {
|
|
247
|
+
console.log('on response', event.path, { body })
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
nitroApp.hooks.hook('afterResponse', (event, { body }) => {
|
|
251
|
+
console.log('on after response', event.path, { body })
|
|
252
|
+
})
|
|
253
|
+
})
|
|
254
254
|
```
|
|
255
255
|
|
|
256
256
|
::
|
|
@@ -262,7 +262,7 @@ Add routes to be prerendered to Nitro.
|
|
|
262
262
|
### Usage
|
|
263
263
|
|
|
264
264
|
```ts
|
|
265
|
-
import {
|
|
265
|
+
import { addPrerenderRoutes, defineNuxtModule } from '@nuxt/kit'
|
|
266
266
|
|
|
267
267
|
export default defineNuxtModule({
|
|
268
268
|
meta: {
|
|
@@ -273,11 +273,11 @@ export default defineNuxtModule({
|
|
|
273
273
|
sitemapUrl: '/sitemap.xml',
|
|
274
274
|
prerender: true,
|
|
275
275
|
},
|
|
276
|
-
setup(options) {
|
|
276
|
+
setup (options) {
|
|
277
277
|
if (options.prerender) {
|
|
278
278
|
addPrerenderRoutes(options.sitemapUrl)
|
|
279
279
|
}
|
|
280
|
-
}
|
|
280
|
+
},
|
|
281
281
|
})
|
|
282
282
|
```
|
|
283
283
|
|
|
@@ -300,22 +300,22 @@ Add imports to the server. It makes your imports available in Nitro without the
|
|
|
300
300
|
### Usage
|
|
301
301
|
|
|
302
302
|
```ts twoslash
|
|
303
|
-
import {
|
|
303
|
+
import { addServerImports, createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
304
304
|
|
|
305
305
|
export default defineNuxtModule({
|
|
306
|
-
setup(options) {
|
|
306
|
+
setup (options) {
|
|
307
307
|
const names = [
|
|
308
308
|
'useStoryblok',
|
|
309
309
|
'useStoryblokApi',
|
|
310
310
|
'useStoryblokBridge',
|
|
311
311
|
'renderRichText',
|
|
312
|
-
'RichTextSchema'
|
|
312
|
+
'RichTextSchema',
|
|
313
313
|
]
|
|
314
314
|
|
|
315
|
-
names.forEach(
|
|
316
|
-
addServerImports({ name, as: name, from: '@storyblok/vue' })
|
|
315
|
+
names.forEach(name =>
|
|
316
|
+
addServerImports({ name, as: name, from: '@storyblok/vue' }),
|
|
317
317
|
)
|
|
318
|
-
}
|
|
318
|
+
},
|
|
319
319
|
})
|
|
320
320
|
```
|
|
321
321
|
|
|
@@ -347,17 +347,17 @@ Add a directory to be scanned for auto-imports by Nitro.
|
|
|
347
347
|
### Usage
|
|
348
348
|
|
|
349
349
|
```ts twoslash
|
|
350
|
-
import {
|
|
350
|
+
import { addServerImportsDir, createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
351
351
|
|
|
352
352
|
export default defineNuxtModule({
|
|
353
353
|
meta: {
|
|
354
354
|
name: 'my-module',
|
|
355
355
|
configKey: 'myModule',
|
|
356
356
|
},
|
|
357
|
-
setup(options) {
|
|
357
|
+
setup (options) {
|
|
358
358
|
const { resolve } = createResolver(import.meta.url)
|
|
359
359
|
addServerImportsDir(resolve('./runtime/server/composables'))
|
|
360
|
-
}
|
|
360
|
+
},
|
|
361
361
|
})
|
|
362
362
|
```
|
|
363
363
|
|
|
@@ -381,22 +381,22 @@ You can use `addServerImportsDir` to add a directory to be scanned by Nitro. Thi
|
|
|
381
381
|
::code-group
|
|
382
382
|
|
|
383
383
|
```ts twoslash [module.ts]
|
|
384
|
-
import {
|
|
384
|
+
import { addServerImportsDir, createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
385
385
|
|
|
386
386
|
export default defineNuxtModule({
|
|
387
387
|
meta: {
|
|
388
388
|
name: 'my-module',
|
|
389
389
|
configKey: 'myModule',
|
|
390
390
|
},
|
|
391
|
-
setup(options) {
|
|
391
|
+
setup (options) {
|
|
392
392
|
const { resolve } = createResolver(import.meta.url)
|
|
393
393
|
addServerImportsDir(resolve('./runtime/server/composables'))
|
|
394
|
-
}
|
|
394
|
+
},
|
|
395
395
|
})
|
|
396
396
|
```
|
|
397
397
|
|
|
398
398
|
```ts twoslash [runtime/server/composables/index.ts]
|
|
399
|
-
export function useApiSecret() {
|
|
399
|
+
export function useApiSecret () {
|
|
400
400
|
const { apiSecret } = useRuntimeConfig()
|
|
401
401
|
return apiSecret
|
|
402
402
|
}
|
|
@@ -427,17 +427,17 @@ Only `~/server/api`, `~/server/routes`, `~/server/middleware`, and `~/server/uti
|
|
|
427
427
|
### Usage
|
|
428
428
|
|
|
429
429
|
```ts twoslash
|
|
430
|
-
import {
|
|
430
|
+
import { addServerScanDir, createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
431
431
|
|
|
432
432
|
export default defineNuxtModule({
|
|
433
433
|
meta: {
|
|
434
434
|
name: 'my-module',
|
|
435
435
|
configKey: 'myModule',
|
|
436
436
|
},
|
|
437
|
-
setup(options) {
|
|
437
|
+
setup (options) {
|
|
438
438
|
const { resolve } = createResolver(import.meta.url)
|
|
439
439
|
addServerScanDir(resolve('./runtime/server'))
|
|
440
|
-
}
|
|
440
|
+
},
|
|
441
441
|
})
|
|
442
442
|
```
|
|
443
443
|
|
|
@@ -461,22 +461,22 @@ You can use `addServerScanDir` to add a directory to be scanned by Nitro. This i
|
|
|
461
461
|
::code-group
|
|
462
462
|
|
|
463
463
|
```ts twoslash [module.ts]
|
|
464
|
-
import {
|
|
464
|
+
import { addServerScanDir, createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
465
465
|
|
|
466
466
|
export default defineNuxtModule({
|
|
467
467
|
meta: {
|
|
468
468
|
name: 'my-module',
|
|
469
469
|
configKey: 'myModule',
|
|
470
470
|
},
|
|
471
|
-
setup(options) {
|
|
471
|
+
setup (options) {
|
|
472
472
|
const { resolve } = createResolver(import.meta.url)
|
|
473
473
|
addServerScanDir(resolve('./runtime/server'))
|
|
474
|
-
}
|
|
474
|
+
},
|
|
475
475
|
})
|
|
476
476
|
```
|
|
477
477
|
|
|
478
478
|
```ts twoslash [runtime/server/utils/index.ts]
|
|
479
|
-
export function hello() {
|
|
479
|
+
export function hello () {
|
|
480
480
|
return 'Hello from server utils!'
|
|
481
481
|
}
|
|
482
482
|
```
|
|
@@ -485,7 +485,7 @@ export function hello() {
|
|
|
485
485
|
You can then use the `hello` function in your server code.
|
|
486
486
|
|
|
487
487
|
```ts twoslash [runtime/server/api/hello.ts]
|
|
488
|
-
function hello() {
|
|
488
|
+
function hello () {
|
|
489
489
|
return 'Hello from server utils!'
|
|
490
490
|
}
|
|
491
491
|
// ---cut---
|
|
@@ -165,10 +165,10 @@ Watch Vue School video about createResolver.
|
|
|
165
165
|
### Usage
|
|
166
166
|
|
|
167
167
|
```ts
|
|
168
|
-
import {
|
|
168
|
+
import { createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
169
169
|
|
|
170
170
|
export default defineNuxtModule({
|
|
171
|
-
|
|
171
|
+
setup (_, nuxt) {
|
|
172
172
|
const { resolve, resolvePath } = createResolver(import.meta.url)
|
|
173
173
|
},
|
|
174
174
|
})
|
|
@@ -234,6 +234,7 @@ import type { ExtendConfigOptions } from '@nuxt/kit'
|
|
|
234
234
|
import type { Plugin as VitePlugin } from 'vite'
|
|
235
235
|
import type { WebpackPluginInstance } from 'webpack'
|
|
236
236
|
import type { RspackPluginInstance } from '@rspack/core'
|
|
237
|
+
|
|
237
238
|
interface AddBuildPluginFactory {
|
|
238
239
|
vite?: () => VitePlugin | VitePlugin[]
|
|
239
240
|
webpack?: () => WebpackPluginInstance | WebpackPluginInstance[]
|
|
@@ -16,10 +16,10 @@ Some examples of projects doing this already:
|
|
|
16
16
|
Here is a brief example of how you might access the Vite config from a project; you could implement a similar approach to get the webpack configuration.
|
|
17
17
|
|
|
18
18
|
```js
|
|
19
|
-
import {
|
|
19
|
+
import { buildNuxt, loadNuxt } from '@nuxt/kit'
|
|
20
20
|
|
|
21
21
|
// https://github.com/nuxt/nuxt/issues/14534
|
|
22
|
-
async function getViteConfig() {
|
|
22
|
+
async function getViteConfig () {
|
|
23
23
|
const nuxt = await loadNuxt({ cwd: process.cwd(), dev: false, overrides: { ssr: false } })
|
|
24
24
|
return new Promise((resolve, reject) => {
|
|
25
25
|
nuxt.hook('vite:extendConfig', (config, { isClient }) => {
|
package/3.api/5.kit/16.layers.md
CHANGED
|
@@ -20,9 +20,9 @@ Get the resolved directory paths for all layers in a Nuxt application. This func
|
|
|
20
20
|
import { defineNuxtModule, getLayerDirectories } from '@nuxt/kit'
|
|
21
21
|
|
|
22
22
|
export default defineNuxtModule({
|
|
23
|
-
setup() {
|
|
23
|
+
setup () {
|
|
24
24
|
const layerDirs = getLayerDirectories()
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
// Access directories from all layers
|
|
27
27
|
for (const [index, layer] of layerDirs.entries()) {
|
|
28
28
|
console.log(`Layer ${index}:`)
|
|
@@ -32,7 +32,7 @@ export default defineNuxtModule({
|
|
|
32
32
|
console.log(` Pages: ${layer.appPages}`)
|
|
33
33
|
// ... other directories
|
|
34
34
|
}
|
|
35
|
-
}
|
|
35
|
+
},
|
|
36
36
|
})
|
|
37
37
|
```
|
|
38
38
|
|
|
@@ -42,7 +42,7 @@ export default defineNuxtModule({
|
|
|
42
42
|
// @errors: 2391
|
|
43
43
|
import type { Nuxt } from '@nuxt/schema'
|
|
44
44
|
// ---cut---
|
|
45
|
-
function getLayerDirectories(nuxt?: Nuxt): LayerDirectories[]
|
|
45
|
+
function getLayerDirectories (nuxt?: Nuxt): LayerDirectories[]
|
|
46
46
|
|
|
47
47
|
interface LayerDirectories {
|
|
48
48
|
/** Nuxt rootDir (`/` by default) */
|
|
@@ -110,9 +110,9 @@ import { resolve } from 'pathe'
|
|
|
110
110
|
import { globby } from 'globby'
|
|
111
111
|
|
|
112
112
|
export default defineNuxtModule({
|
|
113
|
-
async setup() {
|
|
113
|
+
async setup () {
|
|
114
114
|
const layerDirs = getLayerDirectories()
|
|
115
|
-
|
|
115
|
+
|
|
116
116
|
// Find all component files across layers
|
|
117
117
|
// Note: layerDirs[0] is the user layer (highest priority)
|
|
118
118
|
// Later layers in the array have lower priority
|
|
@@ -120,37 +120,37 @@ export default defineNuxtModule({
|
|
|
120
120
|
for (const [index, layer] of layerDirs.entries()) {
|
|
121
121
|
const files = await globby('**/*.vue', {
|
|
122
122
|
cwd: resolve(layer.app, 'components'),
|
|
123
|
-
absolute: true
|
|
123
|
+
absolute: true,
|
|
124
124
|
})
|
|
125
125
|
console.log(`Layer ${index} (${index === 0 ? 'user' : 'base'}):`, files.length, 'components')
|
|
126
126
|
componentFiles.push(...files)
|
|
127
127
|
}
|
|
128
|
-
}
|
|
128
|
+
},
|
|
129
129
|
})
|
|
130
130
|
```
|
|
131
131
|
|
|
132
132
|
**Adding templates from multiple layers:**
|
|
133
133
|
|
|
134
134
|
```ts twoslash
|
|
135
|
-
import { defineNuxtModule, getLayerDirectories
|
|
136
|
-
import {
|
|
137
|
-
import { existsSync } from 'fs'
|
|
135
|
+
import { addTemplate, defineNuxtModule, getLayerDirectories } from '@nuxt/kit'
|
|
136
|
+
import { basename, resolve } from 'pathe'
|
|
137
|
+
import { existsSync } from 'node:fs'
|
|
138
138
|
|
|
139
139
|
export default defineNuxtModule({
|
|
140
|
-
|
|
140
|
+
setup () {
|
|
141
141
|
const layerDirs = getLayerDirectories()
|
|
142
|
-
|
|
142
|
+
|
|
143
143
|
// Add a config file from each layer that has one
|
|
144
144
|
for (const dirs of layerDirs) {
|
|
145
145
|
const configPath = resolve(dirs.app, 'my-module.config.ts')
|
|
146
146
|
if (existsSync(configPath)) {
|
|
147
147
|
addTemplate({
|
|
148
148
|
filename: `my-module-${basename(dirs.root)}.config.ts`,
|
|
149
|
-
src: configPath
|
|
149
|
+
src: configPath,
|
|
150
150
|
})
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
}
|
|
153
|
+
},
|
|
154
154
|
})
|
|
155
155
|
```
|
|
156
156
|
|
|
@@ -159,12 +159,12 @@ export default defineNuxtModule({
|
|
|
159
159
|
```ts twoslash
|
|
160
160
|
import { defineNuxtModule, getLayerDirectories } from '@nuxt/kit'
|
|
161
161
|
import { resolve } from 'pathe'
|
|
162
|
-
import { existsSync, readFileSync } from 'fs'
|
|
162
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
163
163
|
|
|
164
164
|
export default defineNuxtModule({
|
|
165
|
-
setup() {
|
|
165
|
+
setup () {
|
|
166
166
|
const layerDirs = getLayerDirectories()
|
|
167
|
-
|
|
167
|
+
|
|
168
168
|
// Find the first (highest priority) layer that has a specific config file
|
|
169
169
|
// This respects the layer priority system
|
|
170
170
|
let configContent = null
|
|
@@ -176,7 +176,7 @@ export default defineNuxtModule({
|
|
|
176
176
|
break // Use the first (highest priority) config found
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
-
|
|
179
|
+
|
|
180
180
|
// Alternative: Collect configs from all layers, with user layer taking precedence
|
|
181
181
|
const allConfigs = {}
|
|
182
182
|
for (const dirs of layerDirs.reverse()) { // Process from lowest to highest priority
|
|
@@ -186,7 +186,7 @@ export default defineNuxtModule({
|
|
|
186
186
|
Object.assign(allConfigs, config) // Later assignments override earlier ones
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
}
|
|
189
|
+
},
|
|
190
190
|
})
|
|
191
191
|
```
|
|
192
192
|
|
|
@@ -194,20 +194,20 @@ export default defineNuxtModule({
|
|
|
194
194
|
|
|
195
195
|
```ts twoslash
|
|
196
196
|
import { defineNuxtModule, getLayerDirectories } from '@nuxt/kit'
|
|
197
|
-
import { existsSync } from 'fs'
|
|
197
|
+
import { existsSync } from 'node:fs'
|
|
198
198
|
import { resolve } from 'pathe'
|
|
199
199
|
|
|
200
200
|
export default defineNuxtModule({
|
|
201
|
-
setup() {
|
|
201
|
+
setup () {
|
|
202
202
|
const layerDirs = getLayerDirectories()
|
|
203
|
-
|
|
203
|
+
|
|
204
204
|
// Find layers that have a specific custom directory
|
|
205
|
-
const layersWithAssets = layerDirs.filter(layer => {
|
|
205
|
+
const layersWithAssets = layerDirs.filter((layer) => {
|
|
206
206
|
return existsSync(resolve(layer.app, 'assets'))
|
|
207
207
|
})
|
|
208
|
-
|
|
208
|
+
|
|
209
209
|
console.log(`Found ${layersWithAssets.length} layers with assets directory`)
|
|
210
|
-
}
|
|
210
|
+
},
|
|
211
211
|
})
|
|
212
212
|
```
|
|
213
213
|
|
|
@@ -17,7 +17,7 @@ Checks if constraints are met for the current Nuxt version. If not, returns an a
|
|
|
17
17
|
### Usage
|
|
18
18
|
|
|
19
19
|
```ts twoslash
|
|
20
|
-
import {
|
|
20
|
+
import { checkNuxtCompatibility, defineNuxtModule } from '@nuxt/kit'
|
|
21
21
|
|
|
22
22
|
export default defineNuxtModule({
|
|
23
23
|
async setup (_options, nuxt) {
|
|
@@ -27,14 +27,14 @@ export default defineNuxtModule({
|
|
|
27
27
|
} else {
|
|
28
28
|
// do something
|
|
29
29
|
}
|
|
30
|
-
}
|
|
30
|
+
},
|
|
31
31
|
})
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
### Type
|
|
35
35
|
|
|
36
36
|
```ts
|
|
37
|
-
function checkNuxtCompatibility(constraints: NuxtCompatibility, nuxt?: Nuxt): Promise<NuxtCompatibilityIssues
|
|
37
|
+
function checkNuxtCompatibility (constraints: NuxtCompatibility, nuxt?: Nuxt): Promise<NuxtCompatibilityIssues>
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
### Parameters
|
|
@@ -58,7 +58,7 @@ Asserts that constraints are met for the current Nuxt version. If not, throws an
|
|
|
58
58
|
// @errors: 2391
|
|
59
59
|
import type { Nuxt, NuxtCompatibility } from '@nuxt/schema'
|
|
60
60
|
// ---cut---
|
|
61
|
-
function assertNuxtCompatibility(constraints: NuxtCompatibility, nuxt?: Nuxt): Promise<true
|
|
61
|
+
function assertNuxtCompatibility (constraints: NuxtCompatibility, nuxt?: Nuxt): Promise<true>
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
### Parameters
|
|
@@ -84,14 +84,14 @@ export default defineNuxtModule({
|
|
|
84
84
|
} else {
|
|
85
85
|
// do something else
|
|
86
86
|
}
|
|
87
|
-
}
|
|
87
|
+
},
|
|
88
88
|
})
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
### Type
|
|
92
92
|
|
|
93
93
|
```ts
|
|
94
|
-
function hasNuxtCompatibility(constraints: NuxtCompatibility, nuxt?: Nuxt): Promise<boolean
|
|
94
|
+
function hasNuxtCompatibility (constraints: NuxtCompatibility, nuxt?: Nuxt): Promise<boolean>
|
|
95
95
|
```
|
|
96
96
|
|
|
97
97
|
### Parameters
|
|
@@ -110,20 +110,20 @@ Check if current Nuxt instance is of specified major version
|
|
|
110
110
|
import { defineNuxtModule, isNuxtMajorVersion } from '@nuxt/kit'
|
|
111
111
|
|
|
112
112
|
export default defineNuxtModule({
|
|
113
|
-
|
|
113
|
+
setup () {
|
|
114
114
|
if (isNuxtMajorVersion(3)) {
|
|
115
115
|
// do something for Nuxt 3
|
|
116
116
|
} else {
|
|
117
117
|
// do something else for other versions
|
|
118
118
|
}
|
|
119
|
-
}
|
|
119
|
+
},
|
|
120
120
|
})
|
|
121
121
|
```
|
|
122
122
|
|
|
123
123
|
### Type
|
|
124
124
|
|
|
125
125
|
```ts
|
|
126
|
-
function isNuxtMajorVersion(major: number, nuxt?: Nuxt): boolean
|
|
126
|
+
function isNuxtMajorVersion (major: number, nuxt?: Nuxt): boolean
|
|
127
127
|
```
|
|
128
128
|
|
|
129
129
|
### Parameters
|
|
@@ -143,7 +143,7 @@ Use `isNuxtMajorVersion(2, nuxt)` instead. This may be removed in \@nuxt/kit v5
|
|
|
143
143
|
### Type
|
|
144
144
|
|
|
145
145
|
```ts
|
|
146
|
-
function isNuxt3(nuxt?: Nuxt): boolean
|
|
146
|
+
function isNuxt3 (nuxt?: Nuxt): boolean
|
|
147
147
|
```
|
|
148
148
|
|
|
149
149
|
### Parameters
|
|
@@ -161,7 +161,7 @@ Use `isNuxtMajorVersion(2, nuxt)` instead. This may be removed in \@nuxt/kit v5
|
|
|
161
161
|
### Type
|
|
162
162
|
|
|
163
163
|
```ts
|
|
164
|
-
function isNuxt2(nuxt?: Nuxt): boolean
|
|
164
|
+
function isNuxt2 (nuxt?: Nuxt): boolean
|
|
165
165
|
```
|
|
166
166
|
|
|
167
167
|
### Parameters
|
|
@@ -175,7 +175,7 @@ Returns the current Nuxt version.
|
|
|
175
175
|
### Type
|
|
176
176
|
|
|
177
177
|
```ts
|
|
178
|
-
function getNuxtVersion(nuxt?: Nuxt): string
|
|
178
|
+
function getNuxtVersion (nuxt?: Nuxt): string
|
|
179
179
|
```
|
|
180
180
|
|
|
181
181
|
### Parameters
|
|
@@ -29,22 +29,22 @@ Add imports to the Nuxt application. It makes your imports available in the Nuxt
|
|
|
29
29
|
### Usage
|
|
30
30
|
|
|
31
31
|
```ts twoslash
|
|
32
|
-
import {
|
|
32
|
+
import { addImports, defineNuxtModule } from '@nuxt/kit'
|
|
33
33
|
|
|
34
34
|
export default defineNuxtModule({
|
|
35
|
-
setup(options, nuxt) {
|
|
35
|
+
setup (options, nuxt) {
|
|
36
36
|
const names = [
|
|
37
37
|
'useStoryblok',
|
|
38
38
|
'useStoryblokApi',
|
|
39
39
|
'useStoryblokBridge',
|
|
40
40
|
'renderRichText',
|
|
41
|
-
'RichTextSchema'
|
|
41
|
+
'RichTextSchema',
|
|
42
42
|
]
|
|
43
43
|
|
|
44
|
-
names.forEach(
|
|
45
|
-
addImports({ name, as: name, from: '@storyblok/vue' })
|
|
44
|
+
names.forEach(name =>
|
|
45
|
+
addImports({ name, as: name, from: '@storyblok/vue' }),
|
|
46
46
|
)
|
|
47
|
-
}
|
|
47
|
+
},
|
|
48
48
|
})
|
|
49
49
|
```
|
|
50
50
|
|
|
@@ -76,14 +76,14 @@ Add imports from a directory to the Nuxt application. It will automatically impo
|
|
|
76
76
|
### Usage
|
|
77
77
|
|
|
78
78
|
```ts twoslash
|
|
79
|
-
import {
|
|
79
|
+
import { addImportsDir, createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
80
80
|
|
|
81
81
|
export default defineNuxtModule({
|
|
82
82
|
meta: {
|
|
83
83
|
name: '@vueuse/motion',
|
|
84
84
|
configKey: 'motion',
|
|
85
85
|
},
|
|
86
|
-
setup(options, nuxt) {
|
|
86
|
+
setup (options, nuxt) {
|
|
87
87
|
const resolver = createResolver(import.meta.url)
|
|
88
88
|
addImportsDir(resolver.resolve('./runtime/composables'))
|
|
89
89
|
},
|
|
@@ -110,10 +110,10 @@ Add listed imports to the Nuxt application.
|
|
|
110
110
|
### Usage
|
|
111
111
|
|
|
112
112
|
```ts twoslash
|
|
113
|
-
import {
|
|
113
|
+
import { addImportsSources, defineNuxtModule } from '@nuxt/kit'
|
|
114
114
|
|
|
115
115
|
export default defineNuxtModule({
|
|
116
|
-
setup() {
|
|
116
|
+
setup () {
|
|
117
117
|
addImportsSources({
|
|
118
118
|
from: 'h3',
|
|
119
119
|
imports: [
|
|
@@ -121,10 +121,10 @@ export default defineNuxtModule({
|
|
|
121
121
|
'getQuery',
|
|
122
122
|
'getRouterParams',
|
|
123
123
|
'readBody',
|
|
124
|
-
'sendRedirect'
|
|
124
|
+
'sendRedirect',
|
|
125
125
|
],
|
|
126
126
|
})
|
|
127
|
-
}
|
|
127
|
+
},
|
|
128
128
|
})
|
|
129
129
|
```
|
|
130
130
|
|