@nuxt/docs 3.19.2 → 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 +41 -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 -7
  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 +20 -19
  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
@@ -32,7 +32,7 @@ bun x nuxt upgrade
32
32
 
33
33
  ### Nightly Release Channel
34
34
 
35
- To use the latest Nuxt build and test features before their release, read about the [nightly release channel](/docs/guide/going-further/nightly-release-channel) guide.
35
+ To use the latest Nuxt build and test features before their release, read about the [nightly release channel](/docs/3.x/guide/going-further/nightly-release-channel) guide.
36
36
 
37
37
  ::warning
38
38
  The nightly release channel `latest` tag is currently tracking the Nuxt v4 branch, meaning that it is particularly likely to have breaking changes right now — be careful! You can opt in to the 3.x branch nightly releases with `"nuxt": "npm:nuxt-nightly@3x"`.
@@ -221,8 +221,8 @@ export default defineNuxtConfig({
221
221
  srcDir: '.',
222
222
  // This specifies the directory prefix for `app/router.options.ts` and `app/spa-loading-template.html`
223
223
  dir: {
224
- app: 'app'
225
- }
224
+ app: 'app',
225
+ },
226
226
  })
227
227
  ```
228
228
 
@@ -259,14 +259,14 @@ These changes have been made to improve memory usage and increase consistency wi
259
259
  It may be beneficial to extract any calls to `useAsyncData` that share an explicit key (and have custom options) into their own composable:
260
260
 
261
261
  ```ts [composables/useUserData.ts]
262
- export function useUserData(userId: string) {
262
+ export function useUserData (userId: string) {
263
263
  return useAsyncData(
264
264
  `user-${userId}`,
265
265
  () => fetchUser(userId),
266
- {
266
+ {
267
267
  deep: true,
268
- transform: (user) => ({ ...user, lastAccessed: new Date() })
269
- }
268
+ transform: user => ({ ...user, lastAccessed: new Date() }),
269
+ },
270
270
  )
271
271
  }
272
272
  ```
@@ -295,8 +295,8 @@ Alternatively, for now, you can disable this behaviour with:
295
295
  export default defineNuxtConfig({
296
296
  experimental: {
297
297
  granularCachedData: false,
298
- purgeCachedData: false
299
- }
298
+ purgeCachedData: false,
299
+ },
300
300
  })
301
301
  ```
302
302
 
@@ -306,7 +306,7 @@ export default defineNuxtConfig({
306
306
 
307
307
  #### What Changed
308
308
 
309
- The order in which modules are loaded when using [Nuxt layers](/docs/guide/going-further/layers) has been corrected. Previously, modules from the project root were loaded before modules from extended layers, which was the reverse of the expected behavior.
309
+ The order in which modules are loaded when using [Nuxt layers](/docs/3.x/guide/going-further/layers) has been corrected. Previously, modules from the project root were loaded before modules from extended layers, which was the reverse of the expected behavior.
310
310
 
311
311
  Now modules are loaded in the correct order:
312
312
 
@@ -338,23 +338,23 @@ Example of the new correct order:
338
338
  ```ts
339
339
  // Layer: my-layer/nuxt.config.ts
340
340
  export default defineNuxtConfig({
341
- modules: ['layer-module-1', 'layer-module-2']
341
+ modules: ['layer-module-1', 'layer-module-2'],
342
342
  })
343
343
 
344
344
  // Project: nuxt.config.ts
345
345
  export default defineNuxtConfig({
346
346
  extends: ['./my-layer'],
347
- modules: ['project-module-1', 'project-module-2']
347
+ modules: ['project-module-1', 'project-module-2'],
348
348
  })
349
349
 
350
350
  // Loading order (corrected):
351
351
  // 1. layer-module-1
352
- // 2. layer-module-2
352
+ // 2. layer-module-2
353
353
  // 3. project-module-1 (can override layer modules)
354
354
  // 4. project-module-2 (can override layer modules)
355
355
  ```
356
356
 
357
- If you encounter issues with module order dependencies due to needing to register a hook, consider using the [`modules:done` hook](/docs/guide/going-further/modules#custom-hooks) for modules that need to call a hook. This is run after all other modules have been loaded, which means it is safe to use.
357
+ If you encounter issues with module order dependencies due to needing to register a hook, consider using the [`modules:done` hook](/docs/3.x/guide/going-further/modules#custom-hooks) for modules that need to call a hook. This is run after all other modules have been loaded, which means it is safe to use.
358
358
 
359
359
  👉 See [PR #31507](https://github.com/nuxt/nuxt/pull/31507) and [issue #25719](https://github.com/nuxt/nuxt/issues/25719) for more details.
360
360
 
@@ -415,8 +415,8 @@ Alternatively, for now, you can disable this behaviour with:
415
415
  ```ts twoslash [nuxt.config.ts]
416
416
  export default defineNuxtConfig({
417
417
  experimental: {
418
- normalizeComponentNames: false
419
- }
418
+ normalizeComponentNames: false,
419
+ },
420
420
  })
421
421
  ```
422
422
 
@@ -455,14 +455,14 @@ useHead({
455
455
  * If you're using [Template Params](https://unhead.unjs.io/docs/head/guides/plugins/template-params) or [Alias Tag Sorting](https://unhead.unjs.io/docs/head/guides/plugins/alias-sorting), you will need to explicitly opt in to these features now.
456
456
 
457
457
  ```ts
458
- import { TemplateParamsPlugin, AliasSortingPlugin } from '@unhead/vue/plugins'
458
+ import { AliasSortingPlugin, TemplateParamsPlugin } from '@unhead/vue/plugins'
459
459
 
460
460
  export default defineNuxtPlugin({
461
- setup() {
461
+ setup () {
462
462
  const unhead = injectHead()
463
463
  unhead.use(TemplateParamsPlugin)
464
464
  unhead.use(AliasSortingPlugin)
465
- }
465
+ },
466
466
  })
467
467
  ```
468
468
 
@@ -479,7 +479,7 @@ If you still have issues you may revert to the v1 behavior by enabling the `head
479
479
  export default defineNuxtConfig({
480
480
  unhead: {
481
481
  legacy: true,
482
- }
482
+ },
483
483
  })
484
484
  ```
485
485
 
@@ -518,7 +518,7 @@ Alternatively, you can revert to the previous behaviour with:
518
518
  export default defineNuxtConfig({
519
519
  experimental: {
520
520
  spaLoadingTemplateLocation: 'within',
521
- }
521
+ },
522
522
  })
523
523
  ```
524
524
 
@@ -550,7 +550,7 @@ Alternatively, you can disable this change:
550
550
  ```ts twoslash [nuxt.config.ts]
551
551
  export default defineNuxtConfig({
552
552
  experimental: {
553
- parseErrorData: false
553
+ parseErrorData: false,
554
554
  },
555
555
  })
556
556
  ```
@@ -572,8 +572,8 @@ This feature is fully configurable and you can revert to the previous behavior b
572
572
  ```ts twoslash [nuxt.config.ts]
573
573
  export default defineNuxtConfig({
574
574
  features: {
575
- inlineStyles: true
576
- }
575
+ inlineStyles: true,
576
+ },
577
577
  })
578
578
  ```
579
579
 
@@ -611,8 +611,8 @@ Alternatively, you can revert to the previous behaviour with:
611
611
  ```ts twoslash [nuxt.config.ts]
612
612
  export default defineNuxtConfig({
613
613
  experimental: {
614
- scanPageMeta: true
615
- }
614
+ scanPageMeta: true,
615
+ },
616
616
  })
617
617
  ```
618
618
 
@@ -652,8 +652,8 @@ Alternatively, you can disable this feature with:
652
652
  ```ts twoslash [nuxt.config.ts]
653
653
  export default defineNuxtConfig({
654
654
  experimental: {
655
- sharedPrerenderData: false
656
- }
655
+ sharedPrerenderData: false,
656
+ },
657
657
  })
658
658
  ```
659
659
 
@@ -685,10 +685,10 @@ export default defineNuxtConfig({
685
685
  defaults: {
686
686
  useAsyncData: {
687
687
  value: 'null',
688
- errorValue: 'null'
689
- }
690
- }
691
- }
688
+ errorValue: 'null',
689
+ },
690
+ },
691
+ },
692
692
  })
693
693
  ```
694
694
 
@@ -703,7 +703,8 @@ Please report an issue if you are doing this, as we do not plan to keep this as
703
703
  Previously it was possible to pass `dedupe: boolean` to `refresh`. These were aliases of `cancel` (`true`) and `defer` (`false`).
704
704
 
705
705
  ```ts twoslash [app.vue]
706
- const { refresh } = await useAsyncData(async () => ({ message: 'Hello, Nuxt!' }))
706
+ // @errors: 2322
707
+ const { refresh } = await useAsyncData(() => Promise.resolve({ message: 'Hello, Nuxt!' }))
707
708
 
708
709
  async function refreshData () {
709
710
  await refresh({ dedupe: true })
@@ -758,7 +759,7 @@ If you encounter any issues you can revert back to the previous behavior, for no
758
759
  export default defineNuxtConfig({
759
760
  experimental: {
760
761
  resetAsyncDataToUndefined: true,
761
- }
762
+ },
762
763
  })
763
764
  ```
764
765
 
@@ -805,8 +806,8 @@ Alternatively, you can temporarily revert to the previous behavior with:
805
806
  ```ts twoslash [nuxt.config.ts]
806
807
  export default defineNuxtConfig({
807
808
  experimental: {
808
- pendingWhenIdle: true
809
- }
809
+ pendingWhenIdle: true,
810
+ },
810
811
  })
811
812
  ```
812
813
 
@@ -845,8 +846,8 @@ To opt out of this behavior:
845
846
  // Or globally in your Nuxt config
846
847
  export default defineNuxtConfig({
847
848
  experimental: {
848
- alwaysRunFetchOnKeyChange: true
849
- }
849
+ alwaysRunFetchOnKeyChange: true,
850
+ },
850
851
  })
851
852
  ```
852
853
 
@@ -879,10 +880,10 @@ In most cases, no migration steps are required, but if you rely on the reactivit
879
880
  experimental: {
880
881
  defaults: {
881
882
  useAsyncData: {
882
- deep: true
883
- }
884
- }
885
- }
883
+ deep: true,
884
+ },
885
+ },
886
+ },
886
887
  })
887
888
  ```
888
889
 
@@ -961,10 +962,10 @@ Probably no migration is necessary but if you wish to revert to previous behavio
961
962
  ```ts
962
963
  export default defineNuxtConfig({
963
964
  hooks: {
964
- 'app:resolve'(app) {
965
+ 'app:resolve' (app) {
965
966
  app.middleware = app.middleware.filter(mw => !/\/index\.[^/]+$/.test(mw.path))
966
- }
967
- }
967
+ },
968
+ },
968
969
  })
969
970
  ```
970
971
 
@@ -1014,7 +1015,7 @@ Finally, if you are using the template utilities (`serialize`, `importName`, `im
1014
1015
  ```ts
1015
1016
  import { genDynamicImport, genImport, genSafeVariableName } from 'knitwork'
1016
1017
 
1017
- const serialize = (data: any) => JSON.stringify(data, null, 2).replace(/"{(.+)}"(?=,?$)/gm, r => JSON.parse(r).replace(/^{(.*)}$/, '$1'))
1018
+ const serialize = (data: any) => JSON.stringify(data, null, 2).replace(/"\{(.+)\}"(?=,?$)/gm, r => JSON.parse(r).replace(/^\{(.*)\}$/, '$1'))
1018
1019
 
1019
1020
  const importSources = (sources: string | string[], { lazy = false } = {}) => {
1020
1021
  return toArray(sources).map((src) => {
@@ -1059,10 +1060,10 @@ There are two approaches:
1059
1060
  typescript: {
1060
1061
  tsConfig: {
1061
1062
  compilerOptions: {
1062
- noUncheckedIndexedAccess: false
1063
- }
1064
- }
1065
- }
1063
+ noUncheckedIndexedAccess: false,
1064
+ },
1065
+ },
1066
+ },
1066
1067
  })
1067
1068
  ```
1068
1069
 
@@ -1147,16 +1148,16 @@ However, to take advantage of improved type checking, you can opt in to the new
1147
1148
  // Customize app/server TypeScript config
1148
1149
  tsConfig: {
1149
1150
  compilerOptions: {
1150
- strict: true
1151
- }
1151
+ strict: true,
1152
+ },
1152
1153
  },
1153
- // Customize build-time TypeScript config
1154
+ // Customize build-time TypeScript config
1154
1155
  nodeTsConfig: {
1155
1156
  compilerOptions: {
1156
- strict: true
1157
- }
1158
- }
1159
- }
1157
+ strict: true,
1158
+ },
1159
+ },
1160
+ },
1160
1161
  })
1161
1162
  ```
1162
1163
 
@@ -7,12 +7,12 @@ surround: false
7
7
  ---
8
8
 
9
9
  ::card-group{class="sm:grid-cols-1"}
10
- ::card{icon="i-lucide-medal" title="Key Concepts" to="/docs/guide/concepts"}
11
- Discover the main concepts behind Nuxt, from auto-import, hybrid rendering to its TypeScript support.
12
- ::
13
10
  ::card{icon="i-lucide-folders" title="Directory Structure" to="/docs/guide/directory-structure"}
14
11
  Learn about Nuxt directory structure and what benefits each directory or file offers.
15
12
  ::
13
+ ::card{icon="i-lucide-medal" title="Key Concepts" to="/docs/guide/concepts"}
14
+ Discover the main concepts behind Nuxt, from auto-import, hybrid rendering to its TypeScript support.
15
+ ::
16
16
  ::card{icon="i-lucide-star" title="Going Further" to="/docs/guide/going-further"}
17
17
  Master Nuxt with advanced concepts like experimental features, hooks, modules, and more.
18
18
  ::
@@ -1,3 +1,3 @@
1
1
  title: Directory Structure
2
2
  titleTemplate: '%s · Nuxt Directory Structure'
3
- icon: i-lucide-folders
3
+ icon: i-vscode-icons-default-folder
@@ -2,11 +2,11 @@
2
2
  title: ".nuxt"
3
3
  description: "Nuxt uses the .nuxt/ directory in development to generate your Vue application."
4
4
  head.title: ".nuxt/"
5
- navigation.icon: i-lucide-folder
5
+ navigation.icon: i-vscode-icons-folder-type-temp
6
6
  ---
7
7
 
8
8
  ::important
9
- This directory should be added to your [`.gitignore`](/docs/guide/directory-structure/gitignore) file to avoid pushing the dev build output to your repository.
9
+ This directory should be added to your [`.gitignore`](/docs/3.x/guide/directory-structure/gitignore) file to avoid pushing the dev build output to your repository.
10
10
  ::
11
11
 
12
12
  This directory is interesting if you want to learn more about the files Nuxt generates based on your directory structure.
@@ -16,5 +16,5 @@ Nuxt also provides a Virtual File System (VFS) for modules to add templates to t
16
16
  You can explore the generated files by opening the [Nuxt DevTools](https://devtools.nuxt.com) in development mode and navigating to the **Virtual Files** tab.
17
17
 
18
18
  ::warning
19
- You should not touch any files inside since the whole directory will be re-created when running [`nuxt dev`](/docs/api/commands/dev).
19
+ You should not touch any files inside since the whole directory will be re-created when running [`nuxt dev`](/docs/3.x/api/commands/dev).
20
20
  ::
@@ -2,11 +2,11 @@
2
2
  title: ".output"
3
3
  description: "Nuxt creates the .output/ directory when building your application for production."
4
4
  head.title: ".output/"
5
- navigation.icon: i-lucide-folder
5
+ navigation.icon: i-vscode-icons-folder-type-package
6
6
  ---
7
7
 
8
8
  ::important
9
- This directory should be added to your [`.gitignore`](/docs/guide/directory-structure/gitignore) file to avoid pushing the build output to your repository.
9
+ This directory should be added to your [`.gitignore`](/docs/3.x/guide/directory-structure/gitignore) file to avoid pushing the build output to your repository.
10
10
  ::
11
11
 
12
12
  Use this directory to deploy your Nuxt application to production.
@@ -14,5 +14,5 @@ Use this directory to deploy your Nuxt application to production.
14
14
  :read-more{to="/docs/getting-started/deployment"}
15
15
 
16
16
  ::warning
17
- You should not touch any files inside since the whole directory will be re-created when running [`nuxt build`](/docs/api/commands/build).
17
+ You should not touch any files inside since the whole directory will be re-created when running [`nuxt build`](/docs/3.x/api/commands/build).
18
18
  ::
@@ -2,15 +2,15 @@
2
2
  title: "assets"
3
3
  description: "The assets/ directory is used to add all the website's assets that the build tool will process."
4
4
  head.title: "assets/"
5
- navigation.icon: i-lucide-folder
5
+ navigation.icon: i-vscode-icons-folder-type-asset
6
6
  ---
7
7
 
8
8
  The directory usually contains the following types of files:
9
9
 
10
10
  - Stylesheets (CSS, SASS, etc.)
11
11
  - Fonts
12
- - Images that won't be served from the [`public/`](/docs/guide/directory-structure/public) directory.
12
+ - Images that won't be served from the [`public/`](/docs/3.x/guide/directory-structure/public) directory.
13
13
 
14
- If you want to serve assets from the server, we recommend taking a look at the [`public/`](/docs/guide/directory-structure/public) directory.
14
+ If you want to serve assets from the server, we recommend taking a look at the [`public/`](/docs/3.x/guide/directory-structure/public) directory.
15
15
 
16
16
  :read-more{to="/docs/getting-started/assets"}
@@ -2,7 +2,7 @@
2
2
  title: "components"
3
3
  head.title: "components/"
4
4
  description: "The components/ directory is where you put all your Vue components."
5
- navigation.icon: i-lucide-folder
5
+ navigation.icon: i-vscode-icons-folder-type-component
6
6
  ---
7
7
 
8
8
  Nuxt automatically imports any components in this directory (along with components that are registered by any modules you may be using).
@@ -54,7 +54,7 @@ export default defineNuxtConfig({
54
54
  pathPrefix: false, // [!code ++]
55
55
  },
56
56
  ],
57
- });
57
+ })
58
58
  ```
59
59
 
60
60
  This registers the components using the same strategy as used in Nuxt 2. For example, `~/components/Some/MyComponent.vue` will be usable as `<MyComponent>` and not `<SomeMyComponent>`.
@@ -116,7 +116,12 @@ const show = ref(false)
116
116
  <div>
117
117
  <h1>Mountains</h1>
118
118
  <LazyMountainsList v-if="show" />
119
- <button v-if="!show" @click="show = true">Show List</button>
119
+ <button
120
+ v-if="!show"
121
+ @click="show = true"
122
+ >
123
+ Show List
124
+ </button>
120
125
  </div>
121
126
  </template>
122
127
  ```
@@ -235,9 +240,10 @@ Hydrates the component based on a boolean condition.
235
240
  <LazyMyComponent :hydrate-when="isReady" />
236
241
  </div>
237
242
  </template>
243
+
238
244
  <script setup lang="ts">
239
245
  const isReady = ref(false)
240
- function myFunction() {
246
+ function myFunction () {
241
247
  // trigger custom hydration strategy...
242
248
  isReady.value = true
243
249
  }
@@ -263,13 +269,16 @@ All delayed hydration components emit a `@hydrated` event when they are hydrated
263
269
  ```vue [pages/index.vue]
264
270
  <template>
265
271
  <div>
266
- <LazyMyComponent hydrate-on-visible @hydrated="onHydrate" />
272
+ <LazyMyComponent
273
+ hydrate-on-visible
274
+ @hydrated="onHydrate"
275
+ />
267
276
  </div>
268
277
  </template>
269
278
 
270
279
  <script setup lang="ts">
271
- function onHydrate() {
272
- console.log("Component has been hydrated!")
280
+ function onHydrate () {
281
+ console.log('Component has been hydrated!')
273
282
  }
274
283
  </script>
275
284
  ```
@@ -297,7 +306,7 @@ You can also explicitly import components from `#components` if you want or need
297
306
 
298
307
  ```vue [pages/index.vue]
299
308
  <script setup lang="ts">
300
- import { NuxtLink, LazyMountainsList } from '#components'
309
+ import { LazyMountainsList, NuxtLink } from '#components'
301
310
 
302
311
  const show = ref(false)
303
312
  </script>
@@ -306,7 +315,12 @@ const show = ref(false)
306
315
  <div>
307
316
  <h1>Mountains</h1>
308
317
  <LazyMountainsList v-if="show" />
309
- <button v-if="!show" @click="show = true">Show List</button>
318
+ <button
319
+ v-if="!show"
320
+ @click="show = true"
321
+ >
322
+ Show List
323
+ </button>
310
324
  <NuxtLink to="/">Home</NuxtLink>
311
325
  </div>
312
326
  </template>
@@ -333,8 +347,8 @@ export default defineNuxtConfig({
333
347
  //
334
348
  // ~/components/Btn.vue => <Btn />
335
349
  // ~/components/base/Btn.vue => <BaseBtn />
336
- '~/components'
337
- ]
350
+ '~/components',
351
+ ],
338
352
  })
339
353
  ```
340
354
 
@@ -344,7 +358,7 @@ Any nested directories need to be added first as they are scanned in order.
344
358
 
345
359
  ## npm Packages
346
360
 
347
- If you want to auto-import components from an npm package, you can use [`addComponent`](/docs/api/kit/components#addcomponent) in a [local module](/docs/guide/directory-structure/modules) to register them.
361
+ If you want to auto-import components from an npm package, you can use [`addComponent`](/docs/3.x/api/kit/components#addcomponent) in a [local module](/docs/3.x/guide/directory-structure/modules) to register them.
348
362
 
349
363
  ::code-group
350
364
 
@@ -352,7 +366,7 @@ If you want to auto-import components from an npm package, you can use [`addComp
352
366
  import { addComponent, defineNuxtModule } from '@nuxt/kit'
353
367
 
354
368
  export default defineNuxtModule({
355
- setup() {
369
+ setup () {
356
370
  // import { MyComponent as MyAutoImportedComponent } from 'my-npm-package'
357
371
  addComponent({
358
372
  name: 'MyAutoImportedComponent',
@@ -376,7 +390,7 @@ export default defineNuxtModule({
376
390
 
377
391
  ## Component Extensions
378
392
 
379
- By default, any file with an extension specified in the [extensions key of `nuxt.config.ts`](/docs/api/nuxt-config#extensions) is treated as a component.
393
+ By default, any file with an extension specified in the [extensions key of `nuxt.config.ts`](/docs/3.x/api/nuxt-config#extensions) is treated as a component.
380
394
  If you need to restrict the file extensions that should be registered as components, you can use the extended form of the components directory declaration and its `extensions` key:
381
395
 
382
396
  ```ts twoslash [nuxt.config.ts]
@@ -385,8 +399,8 @@ export default defineNuxtConfig({
385
399
  {
386
400
  path: '~/components',
387
401
  extensions: ['.vue'], // [!code ++]
388
- }
389
- ]
402
+ },
403
+ ],
390
404
  })
391
405
  ```
392
406
 
@@ -443,8 +457,8 @@ Server components are currently experimental and in order to use them, you need
443
457
  ```ts twoslash [nuxt.config.ts]
444
458
  export default defineNuxtConfig({
445
459
  experimental: {
446
- componentIslands: true
447
- }
460
+ componentIslands: true,
461
+ },
448
462
  })
449
463
  ```
450
464
 
@@ -467,7 +481,7 @@ Now you can register server-only components with the `.server` suffix and use th
467
481
  </template>
468
482
  ```
469
483
 
470
- Server-only components use [`<NuxtIsland>`](/docs/api/components/nuxt-island) under the hood, meaning that `lazy` prop and `#fallback` slot are both passed down to it.
484
+ Server-only components use [`<NuxtIsland>`](/docs/3.x/api/components/nuxt-island) under the hood, meaning that `lazy` prop and `#fallback` slot are both passed down to it.
471
485
 
472
486
  ::warning
473
487
  Server components (and islands) must have a single root element. (HTML comments are considered elements as well.)
@@ -498,7 +512,10 @@ You can partially hydrate a component by setting a `nuxt-client` attribute on th
498
512
  <div>
499
513
  <HighlightedMarkdown markdown="# Headline" />
500
514
  <!-- Counter will be loaded and hydrated client-side -->
501
- <Counter nuxt-client :count="5" />
515
+ <Counter
516
+ nuxt-client
517
+ :count="5"
518
+ />
502
519
  </div>
503
520
  </template>
504
521
  ```
@@ -554,7 +571,7 @@ There are a number of components that Nuxt provides, including `<ClientOnly>` an
554
571
 
555
572
  Making Vue component libraries with automatic tree-shaking and component registration is super easy. ✨
556
573
 
557
- You can use the [`addComponentsDir`](/docs/api/kit/components#addcomponentsdir) method provided from the `@nuxt/kit` to register your components directory in your Nuxt module.
574
+ You can use the [`addComponentsDir`](/docs/3.x/api/kit/components#addcomponentsdir) method provided from the `@nuxt/kit` to register your components directory in your Nuxt module.
558
575
 
559
576
  Imagine a directory structure like this:
560
577
 
@@ -573,10 +590,10 @@ Imagine a directory structure like this:
573
590
  Then in `awesome-ui/nuxt.ts` you can use the `addComponentsDir` hook:
574
591
 
575
592
  ```ts twoslash
576
- import { createResolver, defineNuxtModule, addComponentsDir } from '@nuxt/kit'
593
+ import { addComponentsDir, createResolver, defineNuxtModule } from '@nuxt/kit'
577
594
 
578
595
  export default defineNuxtModule({
579
- setup() {
596
+ setup () {
580
597
  const resolver = createResolver(import.meta.url)
581
598
 
582
599
  // Add ./components dir to the list
@@ -592,7 +609,7 @@ That's it! Now in your project, you can import your UI library as a Nuxt module
592
609
 
593
610
  ```ts twoslash [nuxt.config.ts]
594
611
  export default defineNuxtConfig({
595
- modules: ['awesome-ui/nuxt']
612
+ modules: ['awesome-ui/nuxt'],
596
613
  })
597
614
  ```
598
615
 
@@ -2,14 +2,14 @@
2
2
  title: 'composables'
3
3
  head.title: 'composables/'
4
4
  description: Use the composables/ directory to auto-import your Vue composables into your application.
5
- navigation.icon: i-lucide-folder
5
+ navigation.icon: i-vscode-icons-folder-type-src
6
6
  ---
7
7
 
8
8
  ## Usage
9
9
 
10
10
  **Method 1:** Using named export
11
11
 
12
- ```js [composables/useFoo.ts]
12
+ ```ts [composables/useFoo.ts]
13
13
  export const useFoo = () => {
14
14
  return useState('foo', () => 'bar')
15
15
  }
@@ -17,7 +17,7 @@ export const useFoo = () => {
17
17
 
18
18
  **Method 2:** Using default export
19
19
 
20
- ```js [composables/use-foo.ts or composables/useFoo.ts]
20
+ ```ts [composables/use-foo.ts or composables/useFoo.ts]
21
21
  // It will be available as useFoo() (camelCase of file name without extension)
22
22
  export default function () {
23
23
  return useState('foo', () => 'bar')
@@ -50,7 +50,7 @@ The `composables/` directory in Nuxt does not provide any additional reactivity
50
50
 
51
51
  Under the hood, Nuxt auto generates the file `.nuxt/imports.d.ts` to declare the types.
52
52
 
53
- Be aware that you have to run [`nuxt prepare`](/docs/api/commands/prepare), [`nuxt dev`](/docs/api/commands/dev) or [`nuxt build`](/docs/api/commands/build) in order to let Nuxt generate the types.
53
+ Be aware that you have to run [`nuxt prepare`](/docs/3.x/api/commands/prepare), [`nuxt dev`](/docs/3.x/api/commands/dev) or [`nuxt build`](/docs/3.x/api/commands/build) in order to let Nuxt generate the types.
54
54
 
55
55
  ::note
56
56
  If you create a composable without having the dev server running, TypeScript will throw an error, such as `Cannot find name 'useBar'.`
@@ -62,7 +62,7 @@ If you create a composable without having the dev server running, TypeScript wil
62
62
 
63
63
  You can use a composable within another composable using auto imports:
64
64
 
65
- ```js [composables/test.ts]
65
+ ```ts [composables/test.ts]
66
66
  export const useFoo = () => {
67
67
  const nuxtApp = useNuxtApp()
68
68
  const bar = useBar()
@@ -71,9 +71,9 @@ export const useFoo = () => {
71
71
 
72
72
  ### Access plugin injections
73
73
 
74
- You can access [plugin injections](/docs/guide/directory-structure/plugins#providing-helpers) from composables:
74
+ You can access [plugin injections](/docs/3.x/guide/directory-structure/plugins#providing-helpers) from composables:
75
75
 
76
- ```js [composables/test.ts]
76
+ ```ts [composables/test.ts]
77
77
  export const useHello = () => {
78
78
  const nuxtApp = useNuxtApp()
79
79
  return nuxtApp.$hello
@@ -82,7 +82,7 @@ export const useHello = () => {
82
82
 
83
83
  ## How Files Are Scanned
84
84
 
85
- Nuxt only scans files at the top level of the [`composables/` directory](/docs/guide/directory-structure/composables), e.g.:
85
+ Nuxt only scans files at the top level of the [`composables/` directory](/docs/3.x/guide/directory-structure/composables), e.g.:
86
86
 
87
87
  ```bash [Directory Structure]
88
88
  -| composables/
@@ -114,8 +114,8 @@ export default defineNuxtConfig({
114
114
  // ... or scan composables nested one level deep with a specific name and file extension
115
115
  '~/composables/*/index.{ts,js,mjs,mts}',
116
116
  // ... or scan all composables within given directory
117
- '~/composables/**'
118
- ]
119
- }
117
+ '~/composables/**',
118
+ ],
119
+ },
120
120
  })
121
121
  ```