@nuxt/docs-nightly 4.1.3-29313386.edc02e27 → 4.1.3-29316215.910d159d

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 (165) hide show
  1. package/1.getting-started/01.introduction.md +4 -4
  2. package/1.getting-started/02.installation.md +1 -1
  3. package/1.getting-started/03.configuration.md +25 -25
  4. package/1.getting-started/04.views.md +3 -3
  5. package/1.getting-started/05.assets.md +9 -3
  6. package/1.getting-started/06.styling.md +53 -43
  7. package/1.getting-started/07.routing.md +9 -9
  8. package/1.getting-started/08.seo-meta.md +50 -37
  9. package/1.getting-started/09.transitions.md +38 -33
  10. package/1.getting-started/10.data-fetching.md +61 -53
  11. package/1.getting-started/11.state-management.md +19 -12
  12. package/1.getting-started/12.error-handling.md +17 -15
  13. package/1.getting-started/13.server.md +8 -8
  14. package/1.getting-started/14.layers.md +19 -13
  15. package/1.getting-started/15.prerendering.md +28 -28
  16. package/1.getting-started/16.deployment.md +8 -8
  17. package/1.getting-started/17.testing.md +42 -42
  18. package/1.getting-started/18.upgrade.md +50 -68
  19. package/2.guide/0.index.md +5 -5
  20. package/2.guide/1.directory-structure/0.output.md +1 -1
  21. package/2.guide/1.directory-structure/1.app/1.assets.md +1 -1
  22. package/2.guide/1.directory-structure/1.app/1.components.md +40 -23
  23. package/2.guide/1.directory-structure/1.app/1.composables.md +9 -9
  24. package/2.guide/1.directory-structure/1.app/1.layouts.md +12 -8
  25. package/2.guide/1.directory-structure/1.app/1.middleware.md +23 -17
  26. package/2.guide/1.directory-structure/1.app/1.pages.md +25 -23
  27. package/2.guide/1.directory-structure/1.app/1.plugins.md +17 -17
  28. package/2.guide/1.directory-structure/1.app/1.utils.md +3 -3
  29. package/2.guide/1.directory-structure/1.app/3.app-config.md +7 -7
  30. package/2.guide/1.directory-structure/1.app/3.app.md +3 -3
  31. package/2.guide/1.directory-structure/1.app/3.error.md +4 -4
  32. package/2.guide/1.directory-structure/1.content.md +4 -1
  33. package/2.guide/1.directory-structure/1.modules.md +5 -5
  34. package/2.guide/1.directory-structure/1.public.md +1 -1
  35. package/2.guide/1.directory-structure/1.server.md +30 -30
  36. package/2.guide/1.directory-structure/1.shared.md +3 -3
  37. package/2.guide/1.directory-structure/2.env.md +3 -3
  38. package/2.guide/1.directory-structure/2.nuxtrc.md +1 -1
  39. package/2.guide/1.directory-structure/3.nuxt-config.md +1 -1
  40. package/2.guide/2.concepts/1.auto-imports.md +15 -15
  41. package/2.guide/2.concepts/10.nuxt-lifecycle.md +7 -7
  42. package/2.guide/2.concepts/2.vuejs-development.md +9 -9
  43. package/2.guide/2.concepts/3.rendering.md +17 -15
  44. package/2.guide/2.concepts/4.server-engine.md +1 -1
  45. package/2.guide/2.concepts/5.modules.md +3 -3
  46. package/2.guide/2.concepts/7.esm.md +16 -14
  47. package/2.guide/2.concepts/8.typescript.md +4 -4
  48. package/2.guide/3.going-further/1.events.md +3 -3
  49. package/2.guide/3.going-further/1.experimental-features.md +238 -77
  50. package/2.guide/3.going-further/1.features.md +44 -9
  51. package/2.guide/3.going-further/1.internals.md +15 -15
  52. package/2.guide/3.going-further/10.runtime-config.md +8 -8
  53. package/2.guide/3.going-further/11.nightly-release-channel.md +1 -1
  54. package/2.guide/3.going-further/2.hooks.md +11 -11
  55. package/2.guide/3.going-further/3.modules.md +83 -81
  56. package/2.guide/3.going-further/4.kit.md +5 -5
  57. package/2.guide/3.going-further/6.nuxt-app.md +4 -4
  58. package/2.guide/3.going-further/7.layers.md +51 -42
  59. package/2.guide/3.going-further/9.debugging.md +2 -2
  60. package/2.guide/4.recipes/1.custom-routing.md +19 -19
  61. package/2.guide/4.recipes/2.vite-plugin.md +3 -3
  62. package/2.guide/4.recipes/3.custom-usefetch.md +10 -10
  63. package/2.guide/4.recipes/4.sessions-and-authentication.md +34 -20
  64. package/2.guide/5.best-practices/performance.md +13 -13
  65. package/3.api/1.components/1.client-only.md +6 -3
  66. package/3.api/1.components/1.nuxt-client-fallback.md +10 -7
  67. package/3.api/1.components/11.teleports.md +5 -2
  68. package/3.api/1.components/12.nuxt-route-announcer.md +7 -7
  69. package/3.api/1.components/13.nuxt-time.md +44 -17
  70. package/3.api/1.components/2.nuxt-page.md +4 -4
  71. package/3.api/1.components/3.nuxt-layout.md +13 -8
  72. package/3.api/1.components/4.nuxt-link.md +40 -20
  73. package/3.api/1.components/5.nuxt-loading-indicator.md +1 -1
  74. package/3.api/1.components/6.nuxt-error-boundary.md +12 -10
  75. package/3.api/2.composables/on-prehydrate.md +2 -2
  76. package/3.api/2.composables/use-app-config.md +1 -1
  77. package/3.api/2.composables/use-async-data.md +14 -14
  78. package/3.api/2.composables/use-cookie.md +27 -19
  79. package/3.api/2.composables/use-error.md +2 -2
  80. package/3.api/2.composables/use-fetch.md +17 -17
  81. package/3.api/2.composables/use-head-safe.md +5 -5
  82. package/3.api/2.composables/use-head.md +3 -3
  83. package/3.api/2.composables/use-hydration.md +5 -5
  84. package/3.api/2.composables/use-lazy-async-data.md +2 -2
  85. package/3.api/2.composables/use-lazy-fetch.md +2 -2
  86. package/3.api/2.composables/use-loading-indicator.md +10 -10
  87. package/3.api/2.composables/use-nuxt-app.md +10 -10
  88. package/3.api/2.composables/use-nuxt-data.md +7 -7
  89. package/3.api/2.composables/use-preview-mode.md +12 -15
  90. package/3.api/2.composables/use-request-fetch.md +1 -1
  91. package/3.api/2.composables/use-request-headers.md +3 -3
  92. package/3.api/2.composables/use-response-header.md +7 -8
  93. package/3.api/2.composables/use-route-announcer.md +3 -3
  94. package/3.api/2.composables/use-router.md +6 -4
  95. package/3.api/2.composables/use-runtime-config.md +11 -11
  96. package/3.api/2.composables/use-runtime-hook.md +1 -1
  97. package/3.api/2.composables/use-seo-meta.md +3 -3
  98. package/3.api/2.composables/use-server-seo-meta.md +3 -3
  99. package/3.api/2.composables/use-state.md +4 -4
  100. package/3.api/3.utils/$fetch.md +6 -4
  101. package/3.api/3.utils/abort-navigation.md +2 -2
  102. package/3.api/3.utils/add-route-middleware.md +3 -3
  103. package/3.api/3.utils/call-once.md +5 -5
  104. package/3.api/3.utils/clear-error.md +2 -2
  105. package/3.api/3.utils/clear-nuxt-data.md +2 -2
  106. package/3.api/3.utils/clear-nuxt-state.md +2 -2
  107. package/3.api/3.utils/create-error.md +2 -2
  108. package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
  109. package/3.api/3.utils/define-nuxt-component.md +5 -5
  110. package/3.api/3.utils/define-nuxt-plugin.md +12 -12
  111. package/3.api/3.utils/define-nuxt-route-middleware.md +2 -2
  112. package/3.api/3.utils/define-page-meta.md +16 -16
  113. package/3.api/3.utils/define-route-rules.md +5 -5
  114. package/3.api/3.utils/navigate-to.md +10 -10
  115. package/3.api/3.utils/preload-components.md +1 -1
  116. package/3.api/3.utils/preload-route-components.md +2 -2
  117. package/3.api/3.utils/prerender-routes.md +2 -2
  118. package/3.api/3.utils/refresh-cookie.md +4 -4
  119. package/3.api/3.utils/refresh-nuxt-data.md +10 -5
  120. package/3.api/3.utils/reload-nuxt-app.md +3 -3
  121. package/3.api/3.utils/set-response-status.md +2 -2
  122. package/3.api/3.utils/show-error.md +3 -3
  123. package/3.api/3.utils/update-app-config.md +3 -2
  124. package/3.api/4.commands/generate.md +1 -1
  125. package/3.api/4.commands/prepare.md +4 -0
  126. package/3.api/4.commands/typecheck.md +1 -1
  127. package/3.api/5.kit/1.modules.md +36 -36
  128. package/3.api/5.kit/10.templates.md +8 -6
  129. package/3.api/5.kit/11.nitro.md +62 -62
  130. package/3.api/5.kit/12.resolving.md +2 -2
  131. package/3.api/5.kit/14.builder.md +1 -0
  132. package/3.api/5.kit/15.examples.md +2 -2
  133. package/3.api/5.kit/16.layers.md +26 -26
  134. package/3.api/5.kit/3.compatibility.md +12 -12
  135. package/3.api/5.kit/4.autoimports.md +12 -12
  136. package/3.api/5.kit/5.components.md +5 -5
  137. package/3.api/5.kit/6.context.md +3 -3
  138. package/3.api/5.kit/7.pages.md +4 -4
  139. package/3.api/5.kit/8.layout.md +1 -1
  140. package/3.api/5.kit/9.plugins.md +5 -4
  141. package/3.api/6.advanced/1.hooks.md +1 -1
  142. package/3.api/6.advanced/2.import-meta.md +3 -3
  143. package/3.api/6.nuxt-config.md +299 -864
  144. package/3.api/index.md +7 -7
  145. package/5.community/4.contribution.md +5 -5
  146. package/5.community/5.framework-contribution.md +1 -1
  147. package/6.bridge/1.overview.md +1 -1
  148. package/6.bridge/10.configuration.md +2 -1
  149. package/6.bridge/2.typescript.md +2 -2
  150. package/6.bridge/3.bridge-composition-api.md +4 -4
  151. package/6.bridge/4.plugins-and-middleware.md +5 -5
  152. package/6.bridge/5.nuxt3-compatible-api.md +12 -9
  153. package/6.bridge/6.meta.md +15 -14
  154. package/6.bridge/8.nitro.md +2 -2
  155. package/6.bridge/9.vite.md +3 -3
  156. package/7.migration/10.bundling.md +1 -1
  157. package/7.migration/11.server.md +3 -3
  158. package/7.migration/2.configuration.md +18 -16
  159. package/7.migration/20.module-authors.md +1 -1
  160. package/7.migration/4.meta.md +18 -15
  161. package/7.migration/5.plugins-and-middleware.md +8 -8
  162. package/7.migration/6.pages-and-layouts.md +20 -16
  163. package/7.migration/7.component-options.md +7 -7
  164. package/7.migration/8.runtime-config.md +4 -4
  165. package/package.json +1 -1
@@ -136,7 +136,7 @@ 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
  }
@@ -148,7 +148,7 @@ You can get type-hint support for this function using the higher-level `defineNu
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
 
@@ -237,10 +237,10 @@ Or any other kind of asset you want to inject in users' Nuxt applications:
237
237
  - Images
238
238
  - etc.
239
239
 
240
- You'll then be able to inject all those assets inside the application from your [module definition](/docs/guide/going-further/modules#module-definition).
240
+ You'll then be able to inject all those assets inside the application from your [module definition](/docs/4.x/guide/going-further/modules#module-definition).
241
241
 
242
242
  ::tip
243
- Learn more about asset injection in [the recipes section](/docs/guide/going-further/modules#recipes).
243
+ Learn more about asset injection in [the recipes section](/docs/4.x/guide/going-further/modules#recipes).
244
244
  ::
245
245
 
246
246
  ::warning
@@ -261,7 +261,7 @@ Modules come with a set of first-party tools to help you with their development.
261
261
 
262
262
  [Nuxt Kit](/docs/4.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
- :read-more{to="/docs/guide/going-further/kit"}
264
+ :read-more{to="/docs/4.x/guide/going-further/kit"}
265
265
 
266
266
  #### `@nuxt/test-utils`
267
267
 
@@ -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
 
@@ -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
 
@@ -324,7 +326,7 @@ const options = useRuntimeConfig().public.myModule
324
326
  Be careful not to expose any sensitive module configuration on the public runtime config, such as private API keys, as they will end up in the public bundle.
325
327
  ::
326
328
 
327
- :read-more{to="/docs/guide/going-further/runtime-config"}
329
+ :read-more{to="/docs/4.x/guide/going-further/runtime-config"}
328
330
 
329
331
  ::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/passing-and-exposing-module-options?friend=nuxt" target="_blank"}
330
332
  Watch Vue School video about passing and exposing Nuxt module options.
@@ -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,53 +345,53 @@ 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
 
350
- :read-more{to="/docs/guide/going-further/kit"}
352
+ :read-more{to="/docs/4.x/guide/going-further/kit"}
351
353
 
352
354
  #### Injecting Vue Components With `addComponent`
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
482
  And a more advanced one, exposing a folder of assets through [Nitro](/docs/4.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,12 +521,12 @@ 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
 
@@ -533,25 +535,25 @@ export default defineNuxtModule<ModuleOptions>({
533
535
  [Lifecycle hooks](/docs/4.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
 
554
- :read-more{to="/docs/api/advanced/hooks"}
556
+ :read-more{to="/docs/4.x/api/advanced/hooks"}
555
557
 
556
558
  ::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/nuxt-lifecycle-hooks?friend=nuxt" target="_blank"}
557
559
  Watch Vue School video about using Nuxt lifecycle hooks in modules.
@@ -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' })
@@ -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
@@ -754,7 +756,7 @@ An example of such a workflow is available on [the module starter](https://githu
754
756
 
755
757
  #### Manual QA With Playground and Externally
756
758
 
757
- Having a playground Nuxt application to test your module when developing it is really useful. [The module starter integrates one for that purpose](/docs/guide/going-further/modules#how-to-develop).
759
+ Having a playground Nuxt application to test your module when developing it is really useful. [The module starter integrates one for that purpose](/docs/4.x/guide/going-further/modules#how-to-develop).
758
760
 
759
761
  You can test your module with other Nuxt applications (applications that are not part of your module repository) locally. To do so, you can use [`npm pack`](https://docs.npmjs.com/cli/commands/npm-pack) command, or your package manager equivalent, to create a tarball from your module. Then in your test project, you can add your module to `package.json` packages as: `"my-module": "file:/path/to/tarball.tgz"`.
760
762
 
@@ -5,7 +5,7 @@ description: "@nuxt/kit provides features for module authors."
5
5
 
6
6
  Nuxt Kit provides composable utilities to make interacting with [Nuxt Hooks](/docs/4.x/api/advanced/hooks), the [Nuxt Interface](/docs/4.x/guide/going-further/internals#the-nuxt-interface) and developing [Nuxt Modules](/docs/4.x/guide/going-further/modules) super easy.
7
7
 
8
- ::read-more{to="/docs/api/kit"}
8
+ ::read-more{to="/docs/4.x/api/kit"}
9
9
  Discover all Nuxt Kit utilities.
10
10
  ::
11
11
 
@@ -29,11 +29,11 @@ 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
 
36
- :read-more{to="/docs/api/kit"}
36
+ :read-more{to="/docs/4.x/api/kit"}
37
37
 
38
38
  ::note
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).
@@ -41,10 +41,10 @@ Nuxt Kit utilities are only available for modules and not meant to be imported i
41
41
 
42
42
  Nuxt Kit is an [esm-only package](/docs/4.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()
@@ -15,7 +15,7 @@ In Nuxt 2, this was referred to as **Nuxt context**.
15
15
 
16
16
  ## Nuxt App Interface
17
17
 
18
- ::read-more{to="/docs/guide/going-further/internals#the-nuxtapp-interface"}
18
+ ::read-more{to="/docs/4.x/guide/going-further/internals#the-nuxtapp-interface"}
19
19
  Jump over the `NuxtApp` interface documentation.
20
20
  ::
21
21
 
@@ -42,7 +42,7 @@ If your composable does not always need `nuxtApp` or you simply want to check if
42
42
 
43
43
  Plugins also receive `nuxtApp` as the first argument for convenience.
44
44
 
45
- :read-more{to="/docs/guide/directory-structure/plugins"}
45
+ :read-more{to="/docs/4.x/guide/directory-structure/plugins"}
46
46
 
47
47
  ## Providing Helpers
48
48
 
@@ -50,12 +50,12 @@ 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
  ```
57
57
 
58
- ::read-more{to="/docs/guide/directory-structure/plugins#providing-helpers"}
58
+ ::read-more{to="/docs/4.x/guide/directory-structure/plugins#providing-helpers"}
59
59
  It is possible to inject helpers by returning an object with a `provide` key in plugins.
60
60
  ::
61
61