@nuxt/docs 3.19.1 → 3.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/1.getting-started/01.introduction.md +2 -2
  2. package/1.getting-started/02.installation.md +1 -0
  3. package/1.getting-started/03.configuration.md +29 -29
  4. package/1.getting-started/04.views.md +7 -7
  5. package/1.getting-started/05.assets.md +15 -9
  6. package/1.getting-started/06.styling.md +55 -45
  7. package/1.getting-started/07.routing.md +12 -12
  8. package/1.getting-started/08.seo-meta.md +55 -42
  9. package/1.getting-started/09.transitions.md +47 -42
  10. package/1.getting-started/10.data-fetching.md +90 -67
  11. package/1.getting-started/11.state-management.md +22 -15
  12. package/1.getting-started/12.error-handling.md +11 -9
  13. package/1.getting-started/13.server.md +3 -3
  14. package/1.getting-started/14.layers.md +21 -15
  15. package/1.getting-started/15.prerendering.md +28 -28
  16. package/1.getting-started/16.deployment.md +9 -9
  17. package/1.getting-started/17.testing.md +43 -43
  18. package/1.getting-started/18.upgrade.md +58 -57
  19. package/2.guide/0.index.md +3 -3
  20. package/2.guide/{2.directory-structure → 1.directory-structure}/.navigation.yml +1 -1
  21. package/2.guide/{2.directory-structure → 1.directory-structure}/0.nuxt.md +3 -3
  22. package/2.guide/{2.directory-structure → 1.directory-structure}/0.output.md +3 -3
  23. package/2.guide/{2.directory-structure → 1.directory-structure}/1.assets.md +3 -3
  24. package/2.guide/{2.directory-structure → 1.directory-structure}/1.components.md +45 -24
  25. package/2.guide/{2.directory-structure → 1.directory-structure}/1.composables.md +11 -11
  26. package/2.guide/{2.directory-structure → 1.directory-structure}/1.content.md +7 -4
  27. package/2.guide/{2.directory-structure → 1.directory-structure}/1.layouts.md +16 -12
  28. package/2.guide/{2.directory-structure → 1.directory-structure}/1.middleware.md +28 -22
  29. package/2.guide/{2.directory-structure → 1.directory-structure}/1.modules.md +6 -6
  30. package/2.guide/{2.directory-structure → 1.directory-structure}/1.node_modules.md +2 -2
  31. package/2.guide/{2.directory-structure → 1.directory-structure}/1.pages.md +33 -31
  32. package/2.guide/{2.directory-structure → 1.directory-structure}/1.plugins.md +25 -25
  33. package/2.guide/{2.directory-structure → 1.directory-structure}/1.public.md +2 -2
  34. package/2.guide/{2.directory-structure → 1.directory-structure}/1.server.md +34 -34
  35. package/2.guide/{2.directory-structure → 1.directory-structure}/1.shared.md +6 -6
  36. package/2.guide/{2.directory-structure → 1.directory-structure}/1.utils.md +5 -5
  37. package/2.guide/{2.directory-structure → 1.directory-structure}/2.env.md +5 -5
  38. package/2.guide/{2.directory-structure → 1.directory-structure}/2.gitignore.md +1 -1
  39. package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtignore.md +4 -4
  40. package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtrc.md +3 -3
  41. package/2.guide/{2.directory-structure → 1.directory-structure}/3.app-config.md +12 -12
  42. package/2.guide/{2.directory-structure → 1.directory-structure}/3.app.md +4 -4
  43. package/2.guide/{2.directory-structure → 1.directory-structure}/3.error.md +6 -6
  44. package/2.guide/{2.directory-structure → 1.directory-structure}/3.nuxt-config.md +2 -2
  45. package/2.guide/{2.directory-structure → 1.directory-structure}/3.package.md +1 -1
  46. package/2.guide/{2.directory-structure → 1.directory-structure}/3.tsconfig.md +3 -3
  47. package/2.guide/{1.concepts → 2.concepts}/1.auto-imports.md +18 -18
  48. package/2.guide/{1.concepts → 2.concepts}/10.nuxt-lifecycle.md +10 -10
  49. package/2.guide/{1.concepts → 2.concepts}/2.vuejs-development.md +9 -9
  50. package/2.guide/{1.concepts → 2.concepts}/3.rendering.md +21 -19
  51. package/2.guide/{1.concepts → 2.concepts}/4.server-engine.md +5 -5
  52. package/2.guide/{1.concepts → 2.concepts}/5.modules.md +4 -4
  53. package/2.guide/{1.concepts → 2.concepts}/7.esm.md +15 -13
  54. package/2.guide/{1.concepts → 2.concepts}/8.typescript.md +11 -11
  55. package/2.guide/3.going-further/1.events.md +2 -2
  56. package/2.guide/3.going-further/1.experimental-features.md +80 -80
  57. package/2.guide/3.going-further/1.features.md +15 -15
  58. package/2.guide/3.going-further/1.internals.md +25 -25
  59. package/2.guide/3.going-further/10.runtime-config.md +11 -11
  60. package/2.guide/3.going-further/2.hooks.md +11 -11
  61. package/2.guide/3.going-further/3.modules.md +89 -87
  62. package/2.guide/3.going-further/4.kit.md +5 -5
  63. package/2.guide/3.going-further/6.nuxt-app.md +5 -5
  64. package/2.guide/3.going-further/7.layers.md +61 -52
  65. package/2.guide/3.going-further/9.debugging.md +2 -2
  66. package/2.guide/4.recipes/1.custom-routing.md +31 -31
  67. package/2.guide/4.recipes/2.vite-plugin.md +4 -4
  68. package/2.guide/4.recipes/3.custom-usefetch.md +12 -12
  69. package/2.guide/4.recipes/4.sessions-and-authentication.md +34 -20
  70. package/2.guide/5.best-practices/hydration.md +4 -4
  71. package/2.guide/5.best-practices/performance.md +12 -12
  72. package/3.api/1.components/1.client-only.md +6 -3
  73. package/3.api/1.components/1.nuxt-client-fallback.md +9 -6
  74. package/3.api/1.components/10.nuxt-picture.md +1 -1
  75. package/3.api/1.components/11.teleports.md +4 -1
  76. package/3.api/1.components/12.nuxt-route-announcer.md +9 -9
  77. package/3.api/1.components/13.nuxt-time.md +44 -17
  78. package/3.api/1.components/2.nuxt-page.md +4 -4
  79. package/3.api/1.components/3.nuxt-layout.md +11 -6
  80. package/3.api/1.components/4.nuxt-link.md +40 -20
  81. package/3.api/1.components/5.nuxt-loading-indicator.md +2 -2
  82. package/3.api/1.components/6.nuxt-error-boundary.md +11 -9
  83. package/3.api/2.composables/on-prehydrate.md +2 -2
  84. package/3.api/2.composables/use-async-data.md +17 -17
  85. package/3.api/2.composables/use-cookie.md +28 -20
  86. package/3.api/2.composables/use-error.md +1 -1
  87. package/3.api/2.composables/use-fetch.md +55 -29
  88. package/3.api/2.composables/use-head-safe.md +7 -7
  89. package/3.api/2.composables/use-head.md +4 -4
  90. package/3.api/2.composables/use-hydration.md +6 -6
  91. package/3.api/2.composables/use-lazy-async-data.md +2 -2
  92. package/3.api/2.composables/use-lazy-fetch.md +2 -2
  93. package/3.api/2.composables/use-loading-indicator.md +12 -12
  94. package/3.api/2.composables/use-nuxt-app.md +19 -19
  95. package/3.api/2.composables/use-nuxt-data.md +8 -8
  96. package/3.api/2.composables/use-preview-mode.md +15 -18
  97. package/3.api/2.composables/use-request-event.md +1 -1
  98. package/3.api/2.composables/use-request-fetch.md +3 -3
  99. package/3.api/2.composables/use-request-header.md +1 -1
  100. package/3.api/2.composables/use-request-headers.md +4 -4
  101. package/3.api/2.composables/use-request-url.md +1 -1
  102. package/3.api/2.composables/use-response-header.md +9 -10
  103. package/3.api/2.composables/use-route-announcer.md +4 -4
  104. package/3.api/2.composables/use-route.md +1 -1
  105. package/3.api/2.composables/use-router.md +9 -7
  106. package/3.api/2.composables/use-runtime-config.md +6 -6
  107. package/3.api/2.composables/use-runtime-hook.md +2 -2
  108. package/3.api/2.composables/use-seo-meta.md +2 -2
  109. package/3.api/2.composables/use-server-seo-meta.md +4 -4
  110. package/3.api/2.composables/use-state.md +4 -4
  111. package/3.api/3.utils/$fetch.md +9 -7
  112. package/3.api/3.utils/abort-navigation.md +3 -3
  113. package/3.api/3.utils/add-route-middleware.md +5 -5
  114. package/3.api/3.utils/call-once.md +4 -4
  115. package/3.api/3.utils/clear-error.md +2 -2
  116. package/3.api/3.utils/clear-nuxt-data.md +3 -3
  117. package/3.api/3.utils/clear-nuxt-state.md +3 -3
  118. package/3.api/3.utils/create-error.md +1 -1
  119. package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
  120. package/3.api/3.utils/define-nuxt-component.md +5 -5
  121. package/3.api/3.utils/define-nuxt-plugin.md +12 -12
  122. package/3.api/3.utils/define-nuxt-route-middleware.md +5 -5
  123. package/3.api/3.utils/define-page-meta.md +21 -21
  124. package/3.api/3.utils/define-route-rules.md +5 -5
  125. package/3.api/3.utils/navigate-to.md +10 -10
  126. package/3.api/3.utils/prefetch-components.md +1 -1
  127. package/3.api/3.utils/preload-components.md +1 -1
  128. package/3.api/3.utils/prerender-routes.md +3 -3
  129. package/3.api/3.utils/refresh-cookie.md +3 -3
  130. package/3.api/3.utils/refresh-nuxt-data.md +11 -6
  131. package/3.api/3.utils/reload-nuxt-app.md +2 -2
  132. package/3.api/3.utils/set-page-layout.md +1 -1
  133. package/3.api/3.utils/set-response-status.md +2 -2
  134. package/3.api/3.utils/show-error.md +4 -4
  135. package/3.api/3.utils/update-app-config.md +3 -2
  136. package/3.api/4.commands/add.md +1 -1
  137. package/3.api/4.commands/analyze.md +2 -1
  138. package/3.api/4.commands/build.md +2 -1
  139. package/3.api/4.commands/dev.md +5 -4
  140. package/3.api/4.commands/generate.md +2 -1
  141. package/3.api/4.commands/init.md +3 -2
  142. package/3.api/4.commands/module.md +4 -4
  143. package/3.api/4.commands/prepare.md +7 -2
  144. package/3.api/4.commands/preview.md +5 -4
  145. package/3.api/4.commands/test.md +40 -0
  146. package/3.api/4.commands/typecheck.md +4 -2
  147. package/3.api/4.commands/upgrade.md +3 -3
  148. package/3.api/5.kit/1.modules.md +36 -36
  149. package/3.api/5.kit/10.runtime-config.md +1 -1
  150. package/3.api/5.kit/10.templates.md +8 -6
  151. package/3.api/5.kit/11.nitro.md +62 -62
  152. package/3.api/5.kit/12.resolving.md +2 -2
  153. package/3.api/5.kit/14.builder.md +1 -0
  154. package/3.api/5.kit/15.examples.md +2 -2
  155. package/3.api/5.kit/16.layers.md +26 -26
  156. package/3.api/5.kit/3.compatibility.md +12 -12
  157. package/3.api/5.kit/4.autoimports.md +13 -13
  158. package/3.api/5.kit/5.components.md +7 -8
  159. package/3.api/5.kit/6.context.md +3 -3
  160. package/3.api/5.kit/7.pages.md +7 -7
  161. package/3.api/5.kit/8.layout.md +2 -2
  162. package/3.api/5.kit/9.plugins.md +6 -5
  163. package/3.api/6.advanced/1.hooks.md +2 -2
  164. package/3.api/6.advanced/2.import-meta.md +3 -3
  165. package/5.community/2.getting-help.md +1 -1
  166. package/5.community/3.reporting-bugs.md +1 -1
  167. package/5.community/4.contribution.md +6 -6
  168. package/5.community/5.framework-contribution.md +3 -3
  169. package/5.community/6.roadmap.md +1 -1
  170. package/6.bridge/1.overview.md +13 -13
  171. package/6.bridge/10.configuration.md +2 -1
  172. package/6.bridge/2.typescript.md +2 -2
  173. package/6.bridge/3.bridge-composition-api.md +6 -6
  174. package/6.bridge/4.plugins-and-middleware.md +9 -9
  175. package/6.bridge/5.nuxt3-compatible-api.md +19 -16
  176. package/6.bridge/6.meta.md +21 -20
  177. package/6.bridge/7.runtime-config.md +1 -1
  178. package/6.bridge/8.nitro.md +3 -3
  179. package/6.bridge/9.vite.md +4 -4
  180. package/7.migration/1.overview.md +2 -2
  181. package/7.migration/2.configuration.md +22 -20
  182. package/7.migration/20.module-authors.md +6 -6
  183. package/7.migration/3.auto-imports.md +3 -3
  184. package/7.migration/4.meta.md +20 -17
  185. package/7.migration/5.plugins-and-middleware.md +5 -5
  186. package/7.migration/6.pages-and-layouts.md +23 -19
  187. package/7.migration/7.component-options.md +14 -14
  188. package/7.migration/8.runtime-config.md +6 -6
  189. package/package.json +1 -1
  190. /package/2.guide/{1.concepts → 2.concepts}/.navigation.yml +0 -0
  191. /package/2.guide/{1.concepts → 2.concepts}/9.code-style.md +0 -0
@@ -4,7 +4,7 @@ description: "Learn how to create a Nuxt Module to integrate, enhance or extend
4
4
  image: '/socials/module-author-guide.jpg'
5
5
  ---
6
6
 
7
- Nuxt's [configuration](/docs/api/nuxt-config) and [hooks](/docs/guide/going-further/hooks) systems make it possible to customize every aspect of Nuxt and add any integration you might need (Vue plugins, CMS, server routes, components, logging, etc.).
7
+ Nuxt's [configuration](/docs/3.x/api/nuxt-config) and [hooks](/docs/3.x/guide/going-further/hooks) systems make it possible to customize every aspect of Nuxt and add any integration you might need (Vue plugins, CMS, server routes, components, logging, etc.).
8
8
 
9
9
  **Nuxt Modules** are functions that sequentially run when starting Nuxt in development mode using `nuxt dev` or building a project for production with `nuxt build`.
10
10
  With modules, you can encapsulate, properly test, and share custom solutions as npm packages without adding unnecessary boilerplate to your project, or requiring changes to Nuxt itself.
@@ -117,7 +117,7 @@ Nuxt Modules come with a variety of powerful APIs and patterns allowing them to
117
117
  We can consider two kinds of Nuxt Modules:
118
118
 
119
119
  - published modules are distributed on npm - you can see a list of some community modules on [the Nuxt website](/modules).
120
- - "local" modules, they exist within a Nuxt project itself, either [inlined in Nuxt config](/docs/api/nuxt-config#modules) or as part of [the `modules` directory](/docs/guide/directory-structure/modules).
120
+ - "local" modules, they exist within a Nuxt project itself, either [inlined in Nuxt config](/docs/3.x/api/nuxt-config#modules) or as part of [the `modules` directory](/docs/3.x/guide/directory-structure/modules).
121
121
 
122
122
  In either case, their anatomy is similar.
123
123
 
@@ -136,19 +136,19 @@ export default function (inlineOptions, nuxt) {
136
136
  // You can do whatever you like here..
137
137
  console.log(inlineOptions.token) // `123`
138
138
  console.log(nuxt.options.dev) // `true` or `false`
139
- nuxt.hook('ready', async nuxt => {
139
+ nuxt.hook('ready', (nuxt) => {
140
140
  console.log('Nuxt is ready')
141
141
  })
142
142
  }
143
143
  ```
144
144
 
145
- You can get type-hint support for this function using the higher-level `defineNuxtModule` helper provided by [Nuxt Kit](/docs/guide/going-further/kit).
145
+ You can get type-hint support for this function using the higher-level `defineNuxtModule` helper provided by [Nuxt Kit](/docs/3.x/guide/going-further/kit).
146
146
 
147
147
  ```ts
148
148
  import { defineNuxtModule } from '@nuxt/kit'
149
149
 
150
150
  export default defineNuxtModule((options, nuxt) => {
151
- nuxt.hook('pages:extend', pages => {
151
+ nuxt.hook('pages:extend', (pages) => {
152
152
  console.log(`Discovered ${pages.length} pages`)
153
153
  })
154
154
  })
@@ -170,8 +170,8 @@ export default defineNuxtModule({
170
170
  // Compatibility constraints
171
171
  compatibility: {
172
172
  // Semver version of supported nuxt versions
173
- nuxt: '>=3.0.0'
174
- }
173
+ nuxt: '>=3.0.0',
174
+ },
175
175
  },
176
176
  // Default configuration options for your module, can also be a function returning those
177
177
  defaults: {},
@@ -191,13 +191,13 @@ export default defineNuxtModule({
191
191
  overrides: {},
192
192
  // Any configuration that should be set. It will override module defaults but
193
193
  // will not override any configuration set in `nuxt.options`.
194
- defaults: {}
195
- }
194
+ defaults: {},
195
+ },
196
196
  },
197
197
  // The function holding your module logic, it can be asynchronous
198
- setup(moduleOptions, nuxt) {
198
+ setup (moduleOptions, nuxt) {
199
199
  // ...
200
- }
200
+ },
201
201
  })
202
202
  ```
203
203
 
@@ -224,9 +224,9 @@ Modules, like everything in a Nuxt configuration, aren't included in your applic
224
224
  Inside the runtime directory, you can provide any kind of assets related to the Nuxt App:
225
225
  - Vue components
226
226
  - Composables
227
- - [Nuxt plugins](/docs/guide/directory-structure/plugins)
227
+ - [Nuxt plugins](/docs/3.x/guide/directory-structure/plugins)
228
228
 
229
- To the [server engine](/docs/guide/concepts/server-engine), Nitro:
229
+ To the [server engine](/docs/3.x/guide/concepts/server-engine), Nitro:
230
230
  - API routes
231
231
  - Middlewares
232
232
  - Nitro plugins
@@ -259,13 +259,13 @@ Modules come with a set of first-party tools to help you with their development.
259
259
 
260
260
  #### `@nuxt/kit`
261
261
 
262
- [Nuxt Kit](/docs/guide/going-further/kit) provides composable utilities to help your module interact with Nuxt applications. It's recommended to use Nuxt Kit utilities over manual alternatives whenever possible to ensure better compatibility and code readability of your module.
262
+ [Nuxt Kit](/docs/3.x/guide/going-further/kit) provides composable utilities to help your module interact with Nuxt applications. It's recommended to use Nuxt Kit utilities over manual alternatives whenever possible to ensure better compatibility and code readability of your module.
263
263
 
264
264
  :read-more{to="/docs/guide/going-further/kit"}
265
265
 
266
266
  #### `@nuxt/test-utils`
267
267
 
268
- [Nuxt Test Utils](/docs/getting-started/testing) is a collection of utilities to help set up and run Nuxt applications within your module tests.
268
+ [Nuxt Test Utils](/docs/3.x/getting-started/testing) is a collection of utilities to help set up and run Nuxt applications within your module tests.
269
269
 
270
270
  ### Recipes
271
271
 
@@ -283,7 +283,7 @@ export default defineNuxtModule({
283
283
  // We create the `experimental` object if it doesn't exist yet
284
284
  nuxt.options.experimental ||= {}
285
285
  nuxt.options.experimental.componentIslands = true
286
- }
286
+ },
287
287
  })
288
288
  ```
289
289
 
@@ -295,7 +295,7 @@ Watch Vue School video about altering Nuxt configuration.
295
295
 
296
296
  #### Exposing Options to Runtime
297
297
 
298
- Because modules aren't part of the application runtime, their options aren't either. However, in many cases, you might need access to some of these module options within your runtime code. We recommend exposing the needed config using Nuxt's [`runtimeConfig`](/docs/api/nuxt-config#runtimeconfig).
298
+ Because modules aren't part of the application runtime, their options aren't either. However, in many cases, you might need access to some of these module options within your runtime code. We recommend exposing the needed config using Nuxt's [`runtimeConfig`](/docs/3.x/api/nuxt-config#runtimeconfig).
299
299
 
300
300
  <!-- TODO: Update after #18466 (or equivalent) -->
301
301
 
@@ -306,9 +306,9 @@ import { defu } from 'defu'
306
306
  export default defineNuxtModule({
307
307
  setup (options, nuxt) {
308
308
  nuxt.options.runtimeConfig.public.myModule = defu(nuxt.options.runtimeConfig.public.myModule, {
309
- foo: options.foo
309
+ foo: options.foo,
310
310
  })
311
- }
311
+ },
312
312
  })
313
313
  ```
314
314
 
@@ -317,6 +317,8 @@ Note that we use [`defu`](https://github.com/unjs/defu) to extend the public run
317
317
  You can then access your module options in a plugin, component, the application like any other runtime configuration:
318
318
 
319
319
  ```js
320
+ import { useRuntimeConfig } from '@nuxt/kit'
321
+
320
322
  const options = useRuntimeConfig().public.myModule
321
323
  ```
322
324
 
@@ -335,7 +337,7 @@ Watch Vue School video about passing and exposing Nuxt module options.
335
337
  Plugins are a common way for a module to add runtime logic. You can use the `addPlugin` utility to register them from your module.
336
338
 
337
339
  ```js
338
- import { defineNuxtModule, addPlugin, createResolver } from '@nuxt/kit'
340
+ import { addPlugin, createResolver, defineNuxtModule } from '@nuxt/kit'
339
341
 
340
342
  export default defineNuxtModule({
341
343
  setup (options, nuxt) {
@@ -343,7 +345,7 @@ export default defineNuxtModule({
343
345
  const resolver = createResolver(import.meta.url)
344
346
 
345
347
  addPlugin(resolver.resolve('./runtime/plugin'))
346
- }
348
+ },
347
349
  })
348
350
  ```
349
351
 
@@ -353,43 +355,43 @@ export default defineNuxtModule({
353
355
 
354
356
  If your module should provide Vue components, you can use the `addComponent` utility to add them as auto-imports for Nuxt to resolve.
355
357
 
356
- ```js
357
- import { defineNuxtModule, addComponent } from '@nuxt/kit'
358
+ ```ts twoslash
359
+ import { addComponent, createResolver, defineNuxtModule, useRuntimeConfig } from '@nuxt/kit'
358
360
 
359
361
  export default defineNuxtModule({
360
- setup(options, nuxt) {
362
+ setup (options, nuxt) {
361
363
  const resolver = createResolver(import.meta.url)
362
364
 
363
365
  // From the runtime directory
364
366
  addComponent({
365
367
  name: 'MySuperComponent', // name of the component to be used in vue templates
366
368
  export: 'MySuperComponent', // (optional) if the component is a named (rather than default) export
367
- filePath: resolver.resolve('runtime/components/MySuperComponent.vue')
369
+ filePath: resolver.resolve('runtime/components/MySuperComponent.vue'),
368
370
  })
369
371
 
370
372
  // From a library
371
373
  addComponent({
372
374
  name: 'MyAwesomeComponent', // name of the component to be used in vue templates
373
375
  export: 'MyAwesomeComponent', // (optional) if the component is a named (rather than default) export
374
- filePath: '@vue/awesome-components'
376
+ filePath: '@vue/awesome-components',
375
377
  })
376
- }
378
+ },
377
379
  })
378
380
  ```
379
381
 
380
382
  Alternatively, you can add an entire directory by using `addComponentsDir`.
381
383
 
382
384
  ```ts
383
- import { defineNuxtModule, addComponentsDir } from '@nuxt/kit'
385
+ import { addComponentsDir, defineNuxtModule } from '@nuxt/kit'
384
386
 
385
387
  export default defineNuxtModule({
386
- setup(options, nuxt) {
388
+ setup (options, nuxt) {
387
389
  const resolver = createResolver(import.meta.url)
388
390
 
389
391
  addComponentsDir({
390
- path: resolver.resolve('runtime/components')
392
+ path: resolver.resolve('runtime/components'),
391
393
  })
392
- }
394
+ },
393
395
  })
394
396
  ```
395
397
 
@@ -398,66 +400,66 @@ export default defineNuxtModule({
398
400
  If your module should provide composables, you can use the `addImports` utility to add them as auto-imports for Nuxt to resolve.
399
401
 
400
402
  ```ts
401
- import { defineNuxtModule, addImports, createResolver } from '@nuxt/kit'
403
+ import { addImports, createResolver, defineNuxtModule } from '@nuxt/kit'
402
404
 
403
405
  export default defineNuxtModule({
404
- setup(options, nuxt) {
406
+ setup (options, nuxt) {
405
407
  const resolver = createResolver(import.meta.url)
406
408
 
407
409
  addImports({
408
410
  name: 'useComposable', // name of the composable to be used
409
411
  as: 'useComposable',
410
- from: resolver.resolve('runtime/composables/useComposable') // path of composable
412
+ from: resolver.resolve('runtime/composables/useComposable'), // path of composable
411
413
  })
412
- }
414
+ },
413
415
  })
414
416
  ```
415
417
 
416
418
  Alternatively, you can add an entire directory by using `addImportsDir`.
417
419
 
418
420
  ```ts
419
- import { defineNuxtModule, addImportsDir, createResolver } from '@nuxt/kit'
421
+ import { addImportsDir, createResolver, defineNuxtModule } from '@nuxt/kit'
420
422
 
421
423
  export default defineNuxtModule({
422
- setup(options, nuxt) {
424
+ setup (options, nuxt) {
423
425
  const resolver = createResolver(import.meta.url)
424
426
 
425
427
  addImportsDir(resolver.resolve('runtime/composables'))
426
- }
428
+ },
427
429
  })
428
430
  ```
429
431
 
430
432
  #### Injecting Server Routes With `addServerHandler`
431
433
 
432
434
  ```ts
433
- import { defineNuxtModule, addServerHandler, createResolver } from '@nuxt/kit'
435
+ import { addServerHandler, createResolver, defineNuxtModule } from '@nuxt/kit'
434
436
 
435
437
  export default defineNuxtModule({
436
- setup(options, nuxt) {
438
+ setup (options, nuxt) {
437
439
  const resolver = createResolver(import.meta.url)
438
440
 
439
441
  addServerHandler({
440
442
  route: '/api/hello',
441
- handler: resolver.resolve('./runtime/server/api/hello/index.get')
443
+ handler: resolver.resolve('./runtime/server/api/hello/index.get'),
442
444
  })
443
- }
445
+ },
444
446
  })
445
447
  ```
446
448
 
447
449
  You can also add a dynamic server route:
448
450
 
449
451
  ```ts
450
- import { defineNuxtModule, addServerHandler, createResolver } from '@nuxt/kit'
452
+ import { addServerHandler, createResolver, defineNuxtModule } from '@nuxt/kit'
451
453
 
452
454
  export default defineNuxtModule({
453
- setup(options, nuxt) {
455
+ setup (options, nuxt) {
454
456
  const resolver = createResolver(import.meta.url)
455
457
 
456
458
  addServerHandler({
457
459
  route: '/api/hello/:name',
458
- handler: resolver.resolve('./runtime/server/api/hello/[name].get')
460
+ handler: resolver.resolve('./runtime/server/api/hello/[name].get'),
459
461
  })
460
- }
462
+ },
461
463
  })
462
464
  ```
463
465
 
@@ -466,34 +468,34 @@ export default defineNuxtModule({
466
468
  If your module should provide other kinds of assets, they can also be injected. Here's a simple example module injecting a stylesheet through Nuxt's `css` array.
467
469
 
468
470
  ```js
469
- import { defineNuxtModule, addPlugin, createResolver } from '@nuxt/kit'
471
+ import { addPlugin, createResolver, defineNuxtModule } from '@nuxt/kit'
470
472
 
471
473
  export default defineNuxtModule({
472
474
  setup (options, nuxt) {
473
475
  const resolver = createResolver(import.meta.url)
474
476
 
475
477
  nuxt.options.css.push(resolver.resolve('./runtime/style.css'))
476
- }
478
+ },
477
479
  })
478
480
  ```
479
481
 
480
- And a more advanced one, exposing a folder of assets through [Nitro](/docs/guide/concepts/server-engine)'s `publicAssets` option:
482
+ And a more advanced one, exposing a folder of assets through [Nitro](/docs/3.x/guide/concepts/server-engine)'s `publicAssets` option:
481
483
 
482
484
  ```js
483
- import { defineNuxtModule, createResolver } from '@nuxt/kit'
485
+ import { createResolver, defineNuxtModule } from '@nuxt/kit'
484
486
 
485
487
  export default defineNuxtModule({
486
488
  setup (options, nuxt) {
487
489
  const resolver = createResolver(import.meta.url)
488
490
 
489
- nuxt.hook('nitro:config', async (nitroConfig) => {
491
+ nuxt.hook('nitro:config', (nitroConfig) => {
490
492
  nitroConfig.publicAssets ||= []
491
493
  nitroConfig.publicAssets.push({
492
494
  dir: resolver.resolve('./runtime/public'),
493
- maxAge: 60 * 60 * 24 * 365 // 1 year
495
+ maxAge: 60 * 60 * 24 * 365, // 1 year
494
496
  })
495
497
  })
496
- }
498
+ },
497
499
  })
498
500
  ```
499
501
 
@@ -502,7 +504,7 @@ export default defineNuxtModule({
502
504
  If your module depends on other modules, you can add them by using Nuxt Kit's `installModule` utility. For example, if you wanted to use Nuxt Tailwind in your module, you could add it as below:
503
505
 
504
506
  ```ts
505
- import { defineNuxtModule, createResolver, installModule } from '@nuxt/kit'
507
+ import { createResolver, defineNuxtModule, installModule } from '@nuxt/kit'
506
508
 
507
509
  export default defineNuxtModule<ModuleOptions>({
508
510
  async setup (options, nuxt) {
@@ -519,35 +521,35 @@ export default defineNuxtModule<ModuleOptions>({
519
521
  content: {
520
522
  files: [
521
523
  resolver.resolve('./runtime/components/**/*.{vue,mjs,ts}'),
522
- resolver.resolve('./runtime/*.{mjs,js,ts}')
523
- ]
524
- }
525
- }
524
+ resolver.resolve('./runtime/*.{mjs,js,ts}'),
525
+ ],
526
+ },
527
+ },
526
528
  })
527
- }
529
+ },
528
530
  })
529
531
  ```
530
532
 
531
533
  #### Using Hooks
532
534
 
533
- [Lifecycle hooks](/docs/guide/going-further/hooks) allow you to expand almost every aspect of Nuxt. Modules can hook to them programmatically or through the `hooks` map in their definition.
535
+ [Lifecycle hooks](/docs/3.x/guide/going-further/hooks) allow you to expand almost every aspect of Nuxt. Modules can hook to them programmatically or through the `hooks` map in their definition.
534
536
 
535
537
  ```js
536
- import { defineNuxtModule, addPlugin, createResolver } from '@nuxt/kit'
538
+ import { addPlugin, createResolver, defineNuxtModule } from '@nuxt/kit'
537
539
 
538
540
  export default defineNuxtModule({
539
541
  // Hook to the `app:error` hook through the `hooks` map
540
542
  hooks: {
541
543
  'app:error': (err) => {
542
- console.info(`This error happened: ${err}`);
543
- }
544
+ console.info(`This error happened: ${err}`)
545
+ },
544
546
  },
545
547
  setup (options, nuxt) {
546
548
  // Programmatically hook to the `pages:extend` hook
547
549
  nuxt.hook('pages:extend', (pages) => {
548
- console.info(`Discovered ${pages.length} pages`);
550
+ console.info(`Discovered ${pages.length} pages`)
549
551
  })
550
- }
552
+ },
551
553
  })
552
554
  ```
553
555
 
@@ -568,10 +570,10 @@ import { defineNuxtModule } from '@nuxt/kit'
568
570
 
569
571
  export default defineNuxtModule({
570
572
  setup (options, nuxt) {
571
- nuxt.hook('close', async nuxt => {
573
+ nuxt.hook('close', async (nuxt) => {
572
574
  // Your custom code here
573
575
  })
574
- }
576
+ },
575
577
  })
576
578
  ```
577
579
  ::
@@ -597,7 +599,7 @@ export default defineNuxtModule({
597
599
  const payload = { foo: 'bar' }
598
600
  await nuxt.callHook('my-module:custom-hook', payload)
599
601
  })
600
- }
602
+ },
601
603
  })
602
604
  ```
603
605
 
@@ -606,32 +608,32 @@ export default defineNuxtModule({
606
608
  If you need to add a virtual file that can be imported into the user's app, you can use the `addTemplate` utility.
607
609
 
608
610
  ```ts
609
- import { defineNuxtModule, addTemplate } from '@nuxt/kit'
611
+ import { addTemplate, defineNuxtModule } from '@nuxt/kit'
610
612
 
611
613
  export default defineNuxtModule({
612
614
  setup (options, nuxt) {
613
615
  // The file is added to Nuxt's internal virtual file system and can be imported from '#build/my-module-feature.mjs'
614
616
  addTemplate({
615
617
  filename: 'my-module-feature.mjs',
616
- getContents: () => 'export const myModuleFeature = () => "hello world !"'
618
+ getContents: () => 'export const myModuleFeature = () => "hello world !"',
617
619
  })
618
- }
620
+ },
619
621
  })
620
622
  ```
621
623
 
622
624
  For the server, you should use the `addServerTemplate` utility instead.
623
625
 
624
626
  ```ts
625
- import { defineNuxtModule, addServerTemplate } from '@nuxt/kit'
627
+ import { addServerTemplate, defineNuxtModule } from '@nuxt/kit'
626
628
 
627
629
  export default defineNuxtModule({
628
630
  setup (options, nuxt) {
629
631
  // The file is added to Nitro's virtual file system and can be imported in the server code from 'my-server-module.mjs'
630
632
  addServerTemplate({
631
633
  filename: 'my-server-module.mjs',
632
- getContents: () => 'export const myServerModule = () => "hello world !"'
634
+ getContents: () => 'export const myServerModule = () => "hello world !"',
633
635
  })
634
- }
636
+ },
635
637
  })
636
638
  ```
637
639
 
@@ -644,7 +646,7 @@ writes a template to the disk and adds a reference to it in the generated `nuxt.
644
646
  If your module should augment types handled by Nuxt, you can use `addTypeTemplate` to perform this operation:
645
647
 
646
648
  ```js
647
- import { defineNuxtModule, addTemplate, addTypeTemplate } from '@nuxt/kit'
649
+ import { addTemplate, addTypeTemplate, defineNuxtModule } from '@nuxt/kit'
648
650
 
649
651
  export default defineNuxtModule({
650
652
  setup (options, nuxt) {
@@ -658,9 +660,9 @@ export default defineNuxtModule({
658
660
  interface NitroRouteRules extends MyModuleNitroRules {}
659
661
  interface NitroRouteConfig extends MyModuleNitroRules {}
660
662
  }
661
- export {}`
663
+ export {}`,
662
664
  })
663
- }
665
+ },
664
666
  })
665
667
  ```
666
668
 
@@ -678,7 +680,7 @@ nuxt.hook('prepare:types', ({ references }) => {
678
680
  If you need to update your templates/virtual files, you can leverage the `updateTemplates` utility like this :
679
681
 
680
682
  ```ts
681
- nuxt.hook('builder:watch', async (event, path) => {
683
+ nuxt.hook('builder:watch', (event, path) => {
682
684
  if (path.includes('my-module-feature.config')) {
683
685
  // This will reload the template that you registered
684
686
  updateTemplates({ filter: t => t.filename === 'my-module-feature.mjs' })
@@ -700,7 +702,7 @@ We're still discussing and exploring how to ease unit and integration testing on
700
702
 
701
703
  #### End to End
702
704
 
703
- [Nuxt Test Utils](/docs/getting-started/testing) is the go-to library to help you test your module in an end-to-end way. Here's the workflow to adopt with it:
705
+ [Nuxt Test Utils](/docs/3.x/getting-started/testing) is the go-to library to help you test your module in an end-to-end way. Here's the workflow to adopt with it:
704
706
 
705
707
  1. Create a Nuxt application to be used as a "fixture" inside `test/fixtures/*`
706
708
  2. Setup Nuxt with this fixture inside your test file
@@ -710,24 +712,24 @@ We're still discussing and exploring how to ease unit and integration testing on
710
712
 
711
713
  In practice, the fixture:
712
714
 
713
- ```js [test/fixtures/ssr/nuxt.config.ts]
715
+ ```ts [test/fixtures/ssr/nuxt.config.ts]
714
716
  // 1. Create a Nuxt application to be used as a "fixture"
715
717
  import MyModule from '../../../src/module'
716
718
 
717
719
  export default defineNuxtConfig({
718
720
  ssr: true,
719
721
  modules: [
720
- MyModule
721
- ]
722
+ MyModule,
723
+ ],
722
724
  })
723
725
  ```
724
726
 
725
727
  And its test:
726
728
 
727
- ```js [test/rendering.ts]
728
- import { describe, it, expect } from 'vitest'
729
+ ```ts [test/rendering.ts]
730
+ import { describe, expect, it } from 'vitest'
729
731
  import { fileURLToPath } from 'node:url'
730
- import { setup, $fetch } from '@nuxt/test-utils/e2e'
732
+ import { $fetch, setup } from '@nuxt/test-utils/e2e'
731
733
 
732
734
  describe('ssr', async () => {
733
735
  // 2. Setup Nuxt with this fixture inside your test file
@@ -810,7 +812,7 @@ export default defineNuxtModule({
810
812
  })
811
813
  ```
812
814
 
813
- This pattern prevents unnecessary work on every build and provides a better developer experience. See the [lifecycle hooks documentation](/docs/api/kit/modules#using-lifecycle-hooks-for-module-installation-and-upgrade) for more details.
815
+ This pattern prevents unnecessary work on every build and provides a better developer experience. See the [lifecycle hooks documentation](/docs/3.x/api/kit/modules#using-lifecycle-hooks-for-module-installation-and-upgrade) for more details.
814
816
 
815
817
  #### Be TypeScript Friendly
816
818
 
@@ -820,7 +822,7 @@ Exposing types and using TypeScript to develop modules benefits users even when
820
822
 
821
823
  #### Avoid CommonJS Syntax
822
824
 
823
- Nuxt relies on native ESM. Please read [Native ES Modules](/docs/guide/concepts/esm) for more information.
825
+ Nuxt relies on native ESM. Please read [Native ES Modules](/docs/3.x/guide/concepts/esm) for more information.
824
826
 
825
827
  #### Document Module Usage
826
828
 
@@ -3,7 +3,7 @@ title: "Nuxt Kit"
3
3
  description: "@nuxt/kit provides features for module authors."
4
4
  ---
5
5
 
6
- Nuxt Kit provides composable utilities to make interacting with [Nuxt Hooks](/docs/api/advanced/hooks), the [Nuxt Interface](/docs/guide/going-further/internals#the-nuxt-interface) and developing [Nuxt Modules](/docs/guide/going-further/modules) super easy.
6
+ Nuxt Kit provides composable utilities to make interacting with [Nuxt Hooks](/docs/3.x/api/advanced/hooks), the [Nuxt Interface](/docs/3.x/guide/going-further/internals#the-nuxt-interface) and developing [Nuxt Modules](/docs/3.x/guide/going-further/modules) super easy.
7
7
 
8
8
  ::read-more{to="/docs/api/kit"}
9
9
  Discover all Nuxt Kit utilities.
@@ -29,7 +29,7 @@ You can install the latest Nuxt Kit by adding it to the `dependencies` section o
29
29
 
30
30
  ### Import Kit Utilities
31
31
 
32
- ```js [test.mjs]
32
+ ```ts [test.mjs]
33
33
  import { useNuxt } from '@nuxt/kit'
34
34
  ```
35
35
 
@@ -39,12 +39,12 @@ import { useNuxt } from '@nuxt/kit'
39
39
  Nuxt Kit utilities are only available for modules and not meant to be imported in runtime (components, Vue composables, pages, plugins, or server routes).
40
40
  ::
41
41
 
42
- Nuxt Kit is an [esm-only package](/docs/guide/concepts/esm) meaning that you **cannot** `require('@nuxt/kit')`. As a workaround, use dynamic import in the CommonJS context:
42
+ Nuxt Kit is an [esm-only package](/docs/3.x/guide/concepts/esm) meaning that you **cannot** `require('@nuxt/kit')`. As a workaround, use dynamic import in the CommonJS context:
43
43
 
44
- ```js [test.cjs]
44
+ ```ts [test.cjs]
45
45
  // This does NOT work!
46
46
  // const kit = require('@nuxt/kit')
47
- async function main() {
47
+ async function main () {
48
48
  const kit = await import('@nuxt/kit')
49
49
  }
50
50
  main()
@@ -23,13 +23,13 @@ Jump over the `NuxtApp` interface documentation.
23
23
 
24
24
  Many composables and utilities, both built-in and user-made, may require access to the Nuxt instance. This doesn't exist everywhere on your application, because a fresh instance is created on every request.
25
25
 
26
- Currently, the Nuxt context is only accessible in [plugins](/docs/guide/directory-structure/plugins), [Nuxt hooks](/docs/guide/going-further/hooks), [Nuxt middleware](/docs/guide/directory-structure/middleware) (if wrapped in `defineNuxtRouteMiddleware`), and [setup functions](https://vuejs.org/api/composition-api-setup.html) (in pages and components).
26
+ Currently, the Nuxt context is only accessible in [plugins](/docs/3.x/guide/directory-structure/plugins), [Nuxt hooks](/docs/3.x/guide/going-further/hooks), [Nuxt middleware](/docs/3.x/guide/directory-structure/middleware) (if wrapped in `defineNuxtRouteMiddleware`), and [setup functions](https://vuejs.org/api/composition-api-setup.html) (in pages and components).
27
27
 
28
- If a composable is called without access to the context, you may get an error stating that 'A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function.' In that case, you can also explicitly call functions within this context by using [`nuxtApp.runWithContext`](/docs/api/composables/use-nuxt-app#runwithcontext).
28
+ If a composable is called without access to the context, you may get an error stating that 'A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function.' In that case, you can also explicitly call functions within this context by using [`nuxtApp.runWithContext`](/docs/3.x/api/composables/use-nuxt-app#runwithcontext).
29
29
 
30
30
  ## Accessing NuxtApp
31
31
 
32
- Within composables, plugins and components you can access `nuxtApp` with [`useNuxtApp()`](/docs/api/composables/use-nuxt-app):
32
+ Within composables, plugins and components you can access `nuxtApp` with [`useNuxtApp()`](/docs/3.x/api/composables/use-nuxt-app):
33
33
 
34
34
  ```ts [composables/useMyComposable.ts]
35
35
  export function useMyComposable () {
@@ -38,7 +38,7 @@ export function useMyComposable () {
38
38
  }
39
39
  ```
40
40
 
41
- If your composable does not always need `nuxtApp` or you simply want to check if it is present or not, since [`useNuxtApp`](/docs/api/composables/use-nuxt-app) throws an exception, you can use [`tryUseNuxtApp`](/docs/api/composables/use-nuxt-app#tryusenuxtapp) instead.
41
+ If your composable does not always need `nuxtApp` or you simply want to check if it is present or not, since [`useNuxtApp`](/docs/3.x/api/composables/use-nuxt-app) throws an exception, you can use [`tryUseNuxtApp`](/docs/3.x/api/composables/use-nuxt-app#tryusenuxtapp) instead.
42
42
 
43
43
  Plugins also receive `nuxtApp` as the first argument for convenience.
44
44
 
@@ -50,7 +50,7 @@ You can provide helpers to be usable across all composables and application. Thi
50
50
 
51
51
  ```ts
52
52
  const nuxtApp = useNuxtApp()
53
- nuxtApp.provide('hello', (name) => `Hello ${name}!`)
53
+ nuxtApp.provide('hello', name => `Hello ${name}!`)
54
54
 
55
55
  console.log(nuxtApp.$hello('name')) // Prints "Hello name!"
56
56
  ```