@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
|
@@ -20,10 +20,10 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
20
20
|
|
|
21
21
|
## Type
|
|
22
22
|
|
|
23
|
-
```ts
|
|
24
|
-
defineNuxtPlugin<T extends Record<string, unknown>>(plugin: Plugin<T> | ObjectPlugin<T>): Plugin<T> & ObjectPlugin<T>
|
|
23
|
+
```ts [Signature]
|
|
24
|
+
export function defineNuxtPlugin<T extends Record<string, unknown>> (plugin: Plugin<T> | ObjectPlugin<T>): Plugin<T> & ObjectPlugin<T>
|
|
25
25
|
|
|
26
|
-
type Plugin<T> = (nuxt:
|
|
26
|
+
type Plugin<T> = (nuxt: NuxtApp) => Promise<void> | Promise<{ provide?: T }> | void | { provide?: T }
|
|
27
27
|
|
|
28
28
|
interface ObjectPlugin<T> {
|
|
29
29
|
name?: string
|
|
@@ -32,7 +32,7 @@ interface ObjectPlugin<T> {
|
|
|
32
32
|
order?: number
|
|
33
33
|
parallel?: boolean
|
|
34
34
|
setup?: Plugin<T>
|
|
35
|
-
hooks?: Partial<
|
|
35
|
+
hooks?: Partial<RuntimeNuxtHooks>
|
|
36
36
|
env?: {
|
|
37
37
|
islands?: boolean
|
|
38
38
|
}
|
|
@@ -69,8 +69,8 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
69
69
|
// Add a global method
|
|
70
70
|
return {
|
|
71
71
|
provide: {
|
|
72
|
-
hello: (name: string) => `Hello ${name}
|
|
73
|
-
}
|
|
72
|
+
hello: (name: string) => `Hello ${name}!`,
|
|
73
|
+
},
|
|
74
74
|
}
|
|
75
75
|
})
|
|
76
76
|
```
|
|
@@ -86,17 +86,17 @@ export default defineNuxtPlugin({
|
|
|
86
86
|
async setup (nuxtApp) {
|
|
87
87
|
// Plugin setup logic
|
|
88
88
|
const data = await $fetch('/api/config')
|
|
89
|
-
|
|
89
|
+
|
|
90
90
|
return {
|
|
91
91
|
provide: {
|
|
92
|
-
config: data
|
|
93
|
-
}
|
|
92
|
+
config: data,
|
|
93
|
+
},
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
hooks: {
|
|
97
|
-
'app:created'() {
|
|
97
|
+
'app:created' () {
|
|
98
98
|
console.log('App created!')
|
|
99
|
-
}
|
|
99
|
+
},
|
|
100
100
|
},
|
|
101
101
|
})
|
|
102
102
|
```
|
|
@@ -12,8 +12,8 @@ Route middleware are stored in the [`app/middleware/`](/docs/4.x/guide/directory
|
|
|
12
12
|
|
|
13
13
|
## Type
|
|
14
14
|
|
|
15
|
-
```ts
|
|
16
|
-
defineNuxtRouteMiddleware(middleware: RouteMiddleware)
|
|
15
|
+
```ts [Signature]
|
|
16
|
+
export function defineNuxtRouteMiddleware (middleware: RouteMiddleware): RouteMiddleware
|
|
17
17
|
|
|
18
18
|
interface RouteMiddleware {
|
|
19
19
|
(to: RouteLocationNormalized, from: RouteLocationNormalized): ReturnType<NavigationGuard>
|
|
@@ -13,7 +13,7 @@ links:
|
|
|
13
13
|
```vue [app/pages/some-page.vue]
|
|
14
14
|
<script setup lang="ts">
|
|
15
15
|
definePageMeta({
|
|
16
|
-
layout: 'default'
|
|
16
|
+
layout: 'default',
|
|
17
17
|
})
|
|
18
18
|
</script>
|
|
19
19
|
```
|
|
@@ -22,11 +22,11 @@ definePageMeta({
|
|
|
22
22
|
|
|
23
23
|
## Type
|
|
24
24
|
|
|
25
|
-
```ts
|
|
26
|
-
definePageMeta(meta: PageMeta)
|
|
25
|
+
```ts [Signature]
|
|
26
|
+
export function definePageMeta (meta: PageMeta): void
|
|
27
27
|
|
|
28
28
|
interface PageMeta {
|
|
29
|
-
validate?: (route: RouteLocationNormalized) => boolean | Promise<boolean> | Partial<NuxtError> | Promise<Partial<NuxtError>>
|
|
29
|
+
validate?: ((route: RouteLocationNormalized) => boolean | Promise<boolean> | Partial<NuxtError> | Promise<Partial<NuxtError>>)
|
|
30
30
|
redirect?: RouteRecordRedirectOption
|
|
31
31
|
name?: string
|
|
32
32
|
path?: string
|
|
@@ -157,13 +157,13 @@ The example below demonstrates:
|
|
|
157
157
|
```vue [app/pages/some-page.vue]
|
|
158
158
|
<script setup lang="ts">
|
|
159
159
|
definePageMeta({
|
|
160
|
-
key:
|
|
160
|
+
key: route => route.fullPath,
|
|
161
161
|
|
|
162
162
|
keepalive: {
|
|
163
|
-
exclude: ['modal']
|
|
163
|
+
exclude: ['modal'],
|
|
164
164
|
},
|
|
165
165
|
|
|
166
|
-
pageType: 'Checkout'
|
|
166
|
+
pageType: 'Checkout',
|
|
167
167
|
})
|
|
168
168
|
</script>
|
|
169
169
|
```
|
|
@@ -181,20 +181,20 @@ definePageMeta({
|
|
|
181
181
|
const auth = useState('auth')
|
|
182
182
|
|
|
183
183
|
if (!auth.value.authenticated) {
|
|
184
|
-
|
|
184
|
+
return navigateTo('/login')
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
if (to.path !== '/checkout') {
|
|
188
188
|
return navigateTo('/checkout')
|
|
189
189
|
}
|
|
190
|
-
}
|
|
190
|
+
},
|
|
191
191
|
],
|
|
192
192
|
|
|
193
193
|
// ... or a string
|
|
194
|
-
middleware: 'auth'
|
|
194
|
+
middleware: 'auth',
|
|
195
195
|
|
|
196
196
|
// ... or multiple strings
|
|
197
|
-
middleware: ['auth', 'another-named-middleware']
|
|
197
|
+
middleware: ['auth', 'another-named-middleware'],
|
|
198
198
|
})
|
|
199
199
|
</script>
|
|
200
200
|
```
|
|
@@ -210,7 +210,7 @@ To make sure that we are only matching digits (`\d+`) for `postId` in the `[post
|
|
|
210
210
|
```vue [app/pages/[postId\\]-[postSlug\\].vue]
|
|
211
211
|
<script setup lang="ts">
|
|
212
212
|
definePageMeta({
|
|
213
|
-
path: '/:postId(\\d+)-:postSlug'
|
|
213
|
+
path: '/:postId(\\d+)-:postSlug',
|
|
214
214
|
})
|
|
215
215
|
</script>
|
|
216
216
|
```
|
|
@@ -225,10 +225,10 @@ You can define the layout that matches the layout's file name located (by defaul
|
|
|
225
225
|
<script setup lang="ts">
|
|
226
226
|
definePageMeta({
|
|
227
227
|
// set custom layout
|
|
228
|
-
layout: 'admin'
|
|
228
|
+
layout: 'admin',
|
|
229
229
|
|
|
230
230
|
// ... or disable a default layout
|
|
231
|
-
layout: false
|
|
231
|
+
layout: false,
|
|
232
232
|
})
|
|
233
233
|
</script>
|
|
234
234
|
```
|
|
@@ -17,7 +17,7 @@ This feature is experimental and in order to use it you must enable the `experim
|
|
|
17
17
|
```vue [app/pages/index.vue]
|
|
18
18
|
<script setup lang="ts">
|
|
19
19
|
defineRouteRules({
|
|
20
|
-
prerender: true
|
|
20
|
+
prerender: true,
|
|
21
21
|
})
|
|
22
22
|
</script>
|
|
23
23
|
|
|
@@ -31,8 +31,8 @@ Will be translated to:
|
|
|
31
31
|
```ts [nuxt.config.ts]
|
|
32
32
|
export default defineNuxtConfig({
|
|
33
33
|
routeRules: {
|
|
34
|
-
'/': { prerender: true }
|
|
35
|
-
}
|
|
34
|
+
'/': { prerender: true },
|
|
35
|
+
},
|
|
36
36
|
})
|
|
37
37
|
```
|
|
38
38
|
|
|
@@ -35,8 +35,8 @@ await navigateTo({
|
|
|
35
35
|
path: '/search',
|
|
36
36
|
query: {
|
|
37
37
|
page: 1,
|
|
38
|
-
sort: 'asc'
|
|
39
|
-
}
|
|
38
|
+
sort: 'asc',
|
|
39
|
+
},
|
|
40
40
|
})
|
|
41
41
|
</script>
|
|
42
42
|
```
|
|
@@ -92,7 +92,7 @@ await navigateTo('https://nuxt.com')
|
|
|
92
92
|
|
|
93
93
|
// will redirect successfully with the 'external' parameter set to 'true'
|
|
94
94
|
await navigateTo('https://nuxt.com', {
|
|
95
|
-
external: true
|
|
95
|
+
external: true,
|
|
96
96
|
})
|
|
97
97
|
</script>
|
|
98
98
|
```
|
|
@@ -107,20 +107,20 @@ await navigateTo('https://nuxt.com', {
|
|
|
107
107
|
target: '_blank',
|
|
108
108
|
windowFeatures: {
|
|
109
109
|
width: 500,
|
|
110
|
-
height: 500
|
|
111
|
-
}
|
|
112
|
-
}
|
|
110
|
+
height: 500,
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
113
|
})
|
|
114
114
|
</script>
|
|
115
115
|
```
|
|
116
116
|
|
|
117
117
|
## Type
|
|
118
118
|
|
|
119
|
-
```ts
|
|
120
|
-
function navigateTo(
|
|
119
|
+
```ts [Signature]
|
|
120
|
+
export function navigateTo (
|
|
121
121
|
to: RouteLocationRaw | undefined | null,
|
|
122
122
|
options?: NavigateToOptions
|
|
123
|
-
)
|
|
123
|
+
): Promise<void | NavigationFailure | false> | false | void | RouteLocationRaw
|
|
124
124
|
|
|
125
125
|
interface NavigateToOptions {
|
|
126
126
|
replace?: boolean
|
|
@@ -12,7 +12,7 @@ Preloading components loads components that your page will need very soon, which
|
|
|
12
12
|
|
|
13
13
|
Use `preloadComponents` to manually preload individual components that have been registered globally in your Nuxt app. By default Nuxt registers these as async components. You must use the Pascal-cased version of the component name.
|
|
14
14
|
|
|
15
|
-
```
|
|
15
|
+
```ts
|
|
16
16
|
await preloadComponents('MyGlobalComponent')
|
|
17
17
|
|
|
18
18
|
await preloadComponents(['MyGlobalComponent1', 'MyGlobalComponent2'])
|
|
@@ -18,7 +18,7 @@ When prerendering, you can hint to Nitro to prerender additional paths, even if
|
|
|
18
18
|
`prerenderRoutes` has to be executed during prerendering. If the `prerenderRoutes` is used in dynamic pages/routes which are not prerendered, then it will not be executed.
|
|
19
19
|
::
|
|
20
20
|
|
|
21
|
-
```
|
|
21
|
+
```ts
|
|
22
22
|
const route = useRoute()
|
|
23
23
|
|
|
24
24
|
prerenderRoutes('/')
|
|
@@ -31,7 +31,7 @@ In the browser, or if called outside prerendering, `prerenderRoutes` will have n
|
|
|
31
31
|
|
|
32
32
|
You can even prerender API routes which is particularly useful for full statically generated sites (SSG) because you can then `$fetch` data as if you have an available server!
|
|
33
33
|
|
|
34
|
-
```
|
|
34
|
+
```ts
|
|
35
35
|
prerenderRoutes('/api/content/article/name-of-article')
|
|
36
36
|
|
|
37
37
|
// Somewhere later in App
|
|
@@ -27,7 +27,7 @@ This is useful for updating the `useCookie` ref when we know the new cookie valu
|
|
|
27
27
|
const tokenCookie = useCookie('token')
|
|
28
28
|
|
|
29
29
|
const login = async (username, password) => {
|
|
30
|
-
const token = await $fetch('/api/token', { ... }) // Sets `token` cookie on response
|
|
30
|
+
const token = await $fetch('/api/token', { /** ... */ }) // Sets `token` cookie on response
|
|
31
31
|
refreshCookie('token')
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -41,6 +41,6 @@ You can enable experimental `cookieStore` option to automatically refresh `useCo
|
|
|
41
41
|
|
|
42
42
|
## Type
|
|
43
43
|
|
|
44
|
-
```ts
|
|
45
|
-
refreshCookie(name: string): void
|
|
44
|
+
```ts [Signature]
|
|
45
|
+
export function refreshCookie (name: string): void
|
|
46
46
|
```
|
|
@@ -16,8 +16,8 @@ If your component is cached by `<KeepAlive>` and enters a deactivated state, the
|
|
|
16
16
|
|
|
17
17
|
## Type
|
|
18
18
|
|
|
19
|
-
```ts
|
|
20
|
-
refreshNuxtData(keys?: string | string[])
|
|
19
|
+
```ts [Signature]
|
|
20
|
+
export function refreshNuxtData (keys?: string | string[])
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Parameters
|
|
@@ -50,7 +50,10 @@ async function refreshAll () {
|
|
|
50
50
|
|
|
51
51
|
<template>
|
|
52
52
|
<div>
|
|
53
|
-
<button
|
|
53
|
+
<button
|
|
54
|
+
:disabled="refreshing"
|
|
55
|
+
@click="refreshAll"
|
|
56
|
+
>
|
|
54
57
|
Refetch All Data
|
|
55
58
|
</button>
|
|
56
59
|
</div>
|
|
@@ -80,7 +83,9 @@ async function refresh () {
|
|
|
80
83
|
<div v-if="refreshing">
|
|
81
84
|
Loading
|
|
82
85
|
</div>
|
|
83
|
-
<button @click="refresh">
|
|
86
|
+
<button @click="refresh">
|
|
87
|
+
Refresh
|
|
88
|
+
</button>
|
|
84
89
|
</template>
|
|
85
90
|
```
|
|
86
91
|
|
|
@@ -20,8 +20,8 @@ You can enable experimental restoration of this state by enabling the `experimen
|
|
|
20
20
|
|
|
21
21
|
## Type
|
|
22
22
|
|
|
23
|
-
```ts
|
|
24
|
-
reloadNuxtApp(options?: ReloadNuxtAppOptions)
|
|
23
|
+
```ts [Signature]
|
|
24
|
+
export function reloadNuxtApp (options?: ReloadNuxtAppOptions)
|
|
25
25
|
|
|
26
26
|
interface ReloadNuxtAppOptions {
|
|
27
27
|
ttl?: number
|
|
@@ -16,7 +16,7 @@ Nuxt provides composables and utilities for first-class server-side-rendering su
|
|
|
16
16
|
`setResponseStatus` can only be called in the [Nuxt context](/docs/4.x/guide/going-further/nuxt-app#the-nuxt-context).
|
|
17
17
|
::
|
|
18
18
|
|
|
19
|
-
```
|
|
19
|
+
```ts
|
|
20
20
|
const event = useRequestEvent()
|
|
21
21
|
|
|
22
22
|
// event will be undefined in the browser
|
|
@@ -15,10 +15,10 @@ Within the [Nuxt context](/docs/4.x/guide/going-further/nuxt-app#the-nuxt-contex
|
|
|
15
15
|
- `error`: `string | Error | Partial<{ cause, data, message, name, stack, statusCode, statusMessage }>`
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
showError(
|
|
18
|
+
showError('😱 Oh no, an error has been thrown.')
|
|
19
19
|
showError({
|
|
20
20
|
statusCode: 404,
|
|
21
|
-
statusMessage:
|
|
21
|
+
statusMessage: 'Page Not Found',
|
|
22
22
|
})
|
|
23
23
|
```
|
|
24
24
|
|
|
@@ -15,10 +15,11 @@ Updates the [`app.config`](/docs/4.x/guide/directory-structure/app-config) using
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
17
|
```js
|
|
18
|
+
import { updateAppConfig, useAppConfig } from '#imports'
|
|
19
|
+
|
|
18
20
|
const appConfig = useAppConfig() // { foo: 'bar' }
|
|
19
21
|
|
|
20
22
|
const newAppConfig = { foo: 'baz' }
|
|
21
|
-
|
|
22
23
|
updateAppConfig(newAppConfig)
|
|
23
24
|
|
|
24
25
|
console.log(appConfig) // { foo: 'baz' }
|
|
@@ -34,3 +34,7 @@ Option | Default | Description
|
|
|
34
34
|
`--logLevel=<silent\|info\|verbose>` | | Specify build-time log level
|
|
35
35
|
`--envName` | | The environment to use when resolving configuration overrides (default is `production` when building, and `development` when running the dev server)
|
|
36
36
|
<!--/prepare-opts-->
|
|
37
|
+
|
|
38
|
+
::note
|
|
39
|
+
This command sets `process.env.NODE_ENV` to `production`.
|
|
40
|
+
::
|
package/3.api/5.kit/1.modules.md
CHANGED
|
@@ -22,16 +22,16 @@ import { defineNuxtModule } from '@nuxt/kit'
|
|
|
22
22
|
export default defineNuxtModule({
|
|
23
23
|
meta: {
|
|
24
24
|
name: 'my-module',
|
|
25
|
-
configKey: 'myModule'
|
|
25
|
+
configKey: 'myModule',
|
|
26
26
|
},
|
|
27
27
|
defaults: {
|
|
28
|
-
enabled: true
|
|
28
|
+
enabled: true,
|
|
29
29
|
},
|
|
30
30
|
setup (options) {
|
|
31
31
|
if (options.enabled) {
|
|
32
32
|
console.log('My Nuxt module is enabled!')
|
|
33
33
|
}
|
|
34
|
-
}
|
|
34
|
+
},
|
|
35
35
|
})
|
|
36
36
|
```
|
|
37
37
|
|
|
@@ -78,17 +78,17 @@ import { defineNuxtModule } from '@nuxt/kit'
|
|
|
78
78
|
export default defineNuxtModule({
|
|
79
79
|
meta: {
|
|
80
80
|
name: 'my-module',
|
|
81
|
-
configKey: 'myModule'
|
|
81
|
+
configKey: 'myModule',
|
|
82
82
|
},
|
|
83
83
|
defaults: {
|
|
84
84
|
// Module options
|
|
85
|
-
enabled: true
|
|
85
|
+
enabled: true,
|
|
86
86
|
},
|
|
87
87
|
setup (options) {
|
|
88
88
|
if (options.enabled) {
|
|
89
89
|
console.log('My Nuxt module is enabled!')
|
|
90
90
|
}
|
|
91
|
-
}
|
|
91
|
+
},
|
|
92
92
|
})
|
|
93
93
|
```
|
|
94
94
|
|
|
@@ -97,8 +97,8 @@ Users can provide options for this module under the corresponding key in `nuxt.c
|
|
|
97
97
|
```ts
|
|
98
98
|
export default defineNuxtConfig({
|
|
99
99
|
myModule: {
|
|
100
|
-
enabled: false
|
|
101
|
-
}
|
|
100
|
+
enabled: false,
|
|
101
|
+
},
|
|
102
102
|
})
|
|
103
103
|
```
|
|
104
104
|
|
|
@@ -116,7 +116,7 @@ export default defineNuxtModule({
|
|
|
116
116
|
nuxt: '>=3.0.0', // or use '^3.0.0'
|
|
117
117
|
},
|
|
118
118
|
},
|
|
119
|
-
|
|
119
|
+
setup () {
|
|
120
120
|
const resolver = createResolver(import.meta.url)
|
|
121
121
|
// Implement
|
|
122
122
|
},
|
|
@@ -148,26 +148,26 @@ interface ModuleOptions {
|
|
|
148
148
|
export default defineNuxtModule<ModuleOptions>().with({
|
|
149
149
|
meta: {
|
|
150
150
|
name: '@nuxtjs/my-api',
|
|
151
|
-
configKey: 'myApi'
|
|
151
|
+
configKey: 'myApi',
|
|
152
152
|
},
|
|
153
153
|
defaults: {
|
|
154
154
|
baseURL: 'https://api.example.com',
|
|
155
155
|
timeout: 5000,
|
|
156
|
-
retries: 3
|
|
156
|
+
retries: 3,
|
|
157
157
|
},
|
|
158
|
-
setup(resolvedOptions, nuxt) {
|
|
158
|
+
setup (resolvedOptions, nuxt) {
|
|
159
159
|
// resolvedOptions is properly typed as:
|
|
160
160
|
// {
|
|
161
161
|
// apiKey: string // Required, no default provided
|
|
162
162
|
// baseURL: string // Required, has default value
|
|
163
163
|
// timeout: number // Optional, has default value
|
|
164
|
-
// retries: number // Optional, has default value
|
|
164
|
+
// retries: number // Optional, has default value
|
|
165
165
|
// }
|
|
166
|
-
|
|
166
|
+
|
|
167
167
|
console.log(resolvedOptions.baseURL) // ✅ TypeScript knows this is always defined
|
|
168
168
|
console.log(resolvedOptions.timeout) // ✅ TypeScript knows this is always defined
|
|
169
169
|
console.log(resolvedOptions.retries) // ✅ TypeScript knows this is always defined
|
|
170
|
-
}
|
|
170
|
+
},
|
|
171
171
|
})
|
|
172
172
|
```
|
|
173
173
|
|
|
@@ -197,45 +197,45 @@ export default defineNuxtModule({
|
|
|
197
197
|
meta: {
|
|
198
198
|
name: 'my-awesome-module',
|
|
199
199
|
version: '1.2.0', // Required for lifecycle hooks
|
|
200
|
-
configKey: 'myAwesomeModule'
|
|
200
|
+
configKey: 'myAwesomeModule',
|
|
201
201
|
},
|
|
202
202
|
defaults: {
|
|
203
203
|
apiKey: '',
|
|
204
|
-
enabled: true
|
|
204
|
+
enabled: true,
|
|
205
205
|
},
|
|
206
|
-
|
|
207
|
-
onInstall(nuxt) {
|
|
206
|
+
|
|
207
|
+
onInstall (nuxt) {
|
|
208
208
|
// This runs only when the module is first installed
|
|
209
209
|
console.log('Setting up my-awesome-module for the first time!')
|
|
210
|
-
|
|
210
|
+
|
|
211
211
|
// You might want to:
|
|
212
212
|
// - Create initial configuration files
|
|
213
213
|
// - Set up database schemas
|
|
214
214
|
// - Display welcome messages
|
|
215
215
|
// - Perform initial data migration
|
|
216
216
|
},
|
|
217
|
-
|
|
218
|
-
onUpgrade(options, nuxt, previousVersion) {
|
|
217
|
+
|
|
218
|
+
onUpgrade (options, nuxt, previousVersion) {
|
|
219
219
|
// This runs when the module is upgraded to a newer version
|
|
220
220
|
console.log(`Upgrading my-awesome-module from ${previousVersion} to 1.2.0`)
|
|
221
|
-
|
|
221
|
+
|
|
222
222
|
// You might want to:
|
|
223
223
|
// - Migrate configuration files
|
|
224
|
-
// - Update database schemas
|
|
224
|
+
// - Update database schemas
|
|
225
225
|
// - Clean up deprecated files
|
|
226
226
|
// - Display upgrade notes
|
|
227
|
-
|
|
227
|
+
|
|
228
228
|
if (semver.lt(previousVersion, '1.1.0')) {
|
|
229
229
|
console.log('⚠️ Breaking changes in 1.1.0 - please check the migration guide')
|
|
230
230
|
}
|
|
231
231
|
},
|
|
232
|
-
|
|
233
|
-
setup(options, nuxt) {
|
|
232
|
+
|
|
233
|
+
setup (options, nuxt) {
|
|
234
234
|
// Regular setup logic runs on every build
|
|
235
235
|
if (options.enabled) {
|
|
236
236
|
// Configure the module
|
|
237
237
|
}
|
|
238
|
-
}
|
|
238
|
+
},
|
|
239
239
|
})
|
|
240
240
|
```
|
|
241
241
|
|
|
@@ -248,7 +248,7 @@ Install specified Nuxt module programmatically. This is helpful when your module
|
|
|
248
248
|
```ts twoslash
|
|
249
249
|
import { defineNuxtModule, installModule } from '@nuxt/kit'
|
|
250
250
|
|
|
251
|
-
export default defineNuxtModule({
|
|
251
|
+
export default defineNuxtModule({
|
|
252
252
|
async setup () {
|
|
253
253
|
// will install @nuxtjs/fontaine with Roboto font and Impact fallback
|
|
254
254
|
await installModule('@nuxtjs/fontaine', {
|
|
@@ -258,10 +258,10 @@ export default defineNuxtModule({
|
|
|
258
258
|
family: 'Roboto',
|
|
259
259
|
fallbacks: ['Impact'],
|
|
260
260
|
fallbackName: 'fallback-a',
|
|
261
|
-
}
|
|
262
|
-
]
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
263
|
})
|
|
264
|
-
}
|
|
264
|
+
},
|
|
265
265
|
})
|
|
266
266
|
```
|
|
267
267
|
|
|
@@ -284,7 +284,7 @@ async function installModule (moduleToInstall: string | NuxtModule, inlineOption
|
|
|
284
284
|
```ts
|
|
285
285
|
import { defineNuxtModule, installModule } from '@nuxt/kit'
|
|
286
286
|
|
|
287
|
-
export default defineNuxtModule({
|
|
287
|
+
export default defineNuxtModule({
|
|
288
288
|
async setup (options, nuxt) {
|
|
289
289
|
// will install @nuxtjs/fontaine with Roboto font and Impact fallback
|
|
290
290
|
await installModule('@nuxtjs/fontaine', {
|
|
@@ -294,9 +294,9 @@ export default defineNuxtModule({
|
|
|
294
294
|
family: 'Roboto',
|
|
295
295
|
fallbacks: ['Impact'],
|
|
296
296
|
fallbackName: 'fallback-a',
|
|
297
|
-
}
|
|
298
|
-
]
|
|
297
|
+
},
|
|
298
|
+
],
|
|
299
299
|
})
|
|
300
|
-
}
|
|
300
|
+
},
|
|
301
301
|
})
|
|
302
302
|
```
|
|
@@ -21,17 +21,17 @@ import { addTemplate, defineNuxtModule } from '@nuxt/kit'
|
|
|
21
21
|
import { defu } from 'defu'
|
|
22
22
|
|
|
23
23
|
export default defineNuxtModule({
|
|
24
|
-
setup(options, nuxt) {
|
|
24
|
+
setup (options, nuxt) {
|
|
25
25
|
const globalMeta = defu(nuxt.options.app.head, {
|
|
26
26
|
charset: options.charset,
|
|
27
|
-
viewport: options.viewport
|
|
27
|
+
viewport: options.viewport,
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
addTemplate({
|
|
31
31
|
filename: 'meta.config.mjs',
|
|
32
|
-
getContents: () => 'export default ' + JSON.stringify({ globalMeta, mixinKey: 'setup' })
|
|
32
|
+
getContents: () => 'export default ' + JSON.stringify({ globalMeta, mixinKey: 'setup' }),
|
|
33
33
|
})
|
|
34
|
-
}
|
|
34
|
+
},
|
|
35
35
|
})
|
|
36
36
|
```
|
|
37
37
|
|
|
@@ -88,7 +88,7 @@ In the module above, we generate a virtual file named `meta.config.mjs`. In the
|
|
|
88
88
|
import { createHead as createServerHead } from '@unhead/vue/server'
|
|
89
89
|
import { createHead as createClientHead } from '@unhead/vue/client'
|
|
90
90
|
import { defineNuxtPlugin } from '#imports'
|
|
91
|
-
// @ts-
|
|
91
|
+
// @ts-expect-error - virtual file
|
|
92
92
|
import metaConfig from '#build/meta.config.mjs'
|
|
93
93
|
|
|
94
94
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
@@ -279,7 +279,9 @@ export default defineNuxtModule({
|
|
|
279
279
|
]
|
|
280
280
|
// watch and rebuild routes template list when one of the pages changes
|
|
281
281
|
nuxt.hook('builder:watch', async (event, relativePath) => {
|
|
282
|
-
if (event === 'change') {
|
|
282
|
+
if (event === 'change') {
|
|
283
|
+
return
|
|
284
|
+
}
|
|
283
285
|
|
|
284
286
|
const path = resolve(nuxt.options.srcDir, relativePath)
|
|
285
287
|
if (updateTemplatePaths.some(dir => path.startsWith(dir))) {
|