@nuxt/docs 4.1.1 → 4.1.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 (200) hide show
  1. package/1.getting-started/01.introduction.md +6 -6
  2. package/1.getting-started/02.installation.md +2 -1
  3. package/1.getting-started/03.configuration.md +37 -37
  4. package/1.getting-started/04.views.md +9 -9
  5. package/1.getting-started/05.assets.md +15 -9
  6. package/1.getting-started/06.styling.md +58 -48
  7. package/1.getting-started/07.routing.md +17 -17
  8. package/1.getting-started/08.seo-meta.md +59 -46
  9. package/1.getting-started/09.transitions.md +49 -44
  10. package/1.getting-started/10.data-fetching.md +104 -81
  11. package/1.getting-started/11.state-management.md +27 -20
  12. package/1.getting-started/12.error-handling.md +22 -20
  13. package/1.getting-started/13.server.md +8 -8
  14. package/1.getting-started/14.layers.md +22 -16
  15. package/1.getting-started/15.prerendering.md +32 -32
  16. package/1.getting-started/16.deployment.md +10 -10
  17. package/1.getting-started/17.testing.md +44 -44
  18. package/1.getting-started/18.upgrade.md +53 -71
  19. package/2.guide/0.index.md +7 -7
  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/1.directory-structure/0.output.md +18 -0
  23. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/.navigation.yml +1 -1
  24. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.assets.md +4 -4
  25. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.components.md +49 -28
  26. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.composables.md +13 -13
  27. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.layouts.md +19 -15
  28. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.middleware.md +31 -25
  29. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.pages.md +39 -37
  30. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.plugins.md +25 -25
  31. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.utils.md +7 -7
  32. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app-config.md +18 -18
  33. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app.md +7 -7
  34. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.error.md +6 -6
  35. package/2.guide/{2.directory-structure → 1.directory-structure}/1.content.md +7 -4
  36. package/2.guide/{2.directory-structure → 1.directory-structure}/1.modules.md +8 -8
  37. package/2.guide/{2.directory-structure → 1.directory-structure}/1.node_modules.md +2 -2
  38. package/2.guide/{2.directory-structure → 1.directory-structure}/1.public.md +2 -2
  39. package/2.guide/{2.directory-structure → 1.directory-structure}/1.server.md +35 -35
  40. package/2.guide/{2.directory-structure → 1.directory-structure}/1.shared.md +7 -7
  41. package/2.guide/{2.directory-structure → 1.directory-structure}/2.env.md +8 -8
  42. package/2.guide/{2.directory-structure → 1.directory-structure}/2.gitignore.md +1 -1
  43. package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtignore.md +5 -4
  44. package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtrc.md +4 -4
  45. package/2.guide/{2.directory-structure → 1.directory-structure}/3.nuxt-config.md +3 -3
  46. package/2.guide/{2.directory-structure → 1.directory-structure}/3.package.md +1 -1
  47. package/2.guide/{2.directory-structure → 1.directory-structure}/3.tsconfig.md +3 -3
  48. package/2.guide/{1.concepts → 2.concepts}/1.auto-imports.md +22 -22
  49. package/2.guide/{1.concepts → 2.concepts}/10.nuxt-lifecycle.md +17 -17
  50. package/2.guide/{1.concepts → 2.concepts}/2.vuejs-development.md +13 -13
  51. package/2.guide/{1.concepts → 2.concepts}/3.rendering.md +24 -22
  52. package/2.guide/{1.concepts → 2.concepts}/4.server-engine.md +6 -6
  53. package/2.guide/{1.concepts → 2.concepts}/5.modules.md +5 -5
  54. package/2.guide/{1.concepts → 2.concepts}/7.esm.md +17 -15
  55. package/2.guide/{1.concepts → 2.concepts}/8.typescript.md +12 -12
  56. package/2.guide/3.going-further/1.events.md +3 -3
  57. package/2.guide/3.going-further/1.experimental-features.md +246 -85
  58. package/2.guide/3.going-further/1.features.md +44 -9
  59. package/2.guide/3.going-further/1.internals.md +25 -25
  60. package/2.guide/3.going-further/10.runtime-config.md +12 -12
  61. package/2.guide/3.going-further/11.nightly-release-channel.md +1 -1
  62. package/2.guide/3.going-further/2.hooks.md +14 -14
  63. package/2.guide/3.going-further/3.modules.md +96 -94
  64. package/2.guide/3.going-further/4.kit.md +7 -7
  65. package/2.guide/3.going-further/6.nuxt-app.md +8 -8
  66. package/2.guide/3.going-further/7.layers.md +62 -53
  67. package/2.guide/3.going-further/9.debugging.md +2 -2
  68. package/2.guide/4.recipes/1.custom-routing.md +30 -30
  69. package/2.guide/4.recipes/2.vite-plugin.md +4 -4
  70. package/2.guide/4.recipes/3.custom-usefetch.md +13 -13
  71. package/2.guide/4.recipes/4.sessions-and-authentication.md +35 -21
  72. package/2.guide/5.best-practices/hydration.md +4 -4
  73. package/2.guide/5.best-practices/performance.md +17 -17
  74. package/3.api/1.components/1.client-only.md +6 -3
  75. package/3.api/1.components/1.nuxt-client-fallback.md +10 -7
  76. package/3.api/1.components/10.nuxt-picture.md +1 -1
  77. package/3.api/1.components/11.teleports.md +5 -2
  78. package/3.api/1.components/12.nuxt-route-announcer.md +9 -9
  79. package/3.api/1.components/13.nuxt-time.md +44 -17
  80. package/3.api/1.components/2.nuxt-page.md +6 -6
  81. package/3.api/1.components/3.nuxt-layout.md +15 -10
  82. package/3.api/1.components/4.nuxt-link.md +42 -22
  83. package/3.api/1.components/5.nuxt-loading-indicator.md +3 -3
  84. package/3.api/1.components/6.nuxt-error-boundary.md +12 -10
  85. package/3.api/2.composables/on-prehydrate.md +2 -2
  86. package/3.api/2.composables/use-app-config.md +1 -1
  87. package/3.api/2.composables/use-async-data.md +20 -20
  88. package/3.api/2.composables/use-cookie.md +29 -21
  89. package/3.api/2.composables/use-error.md +2 -2
  90. package/3.api/2.composables/use-fetch.md +58 -32
  91. package/3.api/2.composables/use-head-safe.md +7 -7
  92. package/3.api/2.composables/use-head.md +5 -5
  93. package/3.api/2.composables/use-hydration.md +6 -6
  94. package/3.api/2.composables/use-lazy-async-data.md +4 -4
  95. package/3.api/2.composables/use-lazy-fetch.md +4 -4
  96. package/3.api/2.composables/use-loading-indicator.md +12 -12
  97. package/3.api/2.composables/use-nuxt-app.md +22 -22
  98. package/3.api/2.composables/use-nuxt-data.md +8 -8
  99. package/3.api/2.composables/use-preview-mode.md +15 -18
  100. package/3.api/2.composables/use-request-event.md +1 -1
  101. package/3.api/2.composables/use-request-fetch.md +3 -3
  102. package/3.api/2.composables/use-request-header.md +1 -1
  103. package/3.api/2.composables/use-request-headers.md +4 -4
  104. package/3.api/2.composables/use-request-url.md +1 -1
  105. package/3.api/2.composables/use-response-header.md +9 -10
  106. package/3.api/2.composables/use-route-announcer.md +4 -4
  107. package/3.api/2.composables/use-route.md +1 -1
  108. package/3.api/2.composables/use-router.md +10 -8
  109. package/3.api/2.composables/use-runtime-config.md +11 -11
  110. package/3.api/2.composables/use-runtime-hook.md +2 -2
  111. package/3.api/2.composables/use-seo-meta.md +4 -4
  112. package/3.api/2.composables/use-server-seo-meta.md +6 -6
  113. package/3.api/2.composables/use-state.md +5 -5
  114. package/3.api/3.utils/$fetch.md +10 -8
  115. package/3.api/3.utils/abort-navigation.md +3 -3
  116. package/3.api/3.utils/add-route-middleware.md +5 -5
  117. package/3.api/3.utils/call-once.md +6 -6
  118. package/3.api/3.utils/clear-error.md +3 -3
  119. package/3.api/3.utils/clear-nuxt-data.md +3 -3
  120. package/3.api/3.utils/clear-nuxt-state.md +3 -3
  121. package/3.api/3.utils/create-error.md +2 -2
  122. package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
  123. package/3.api/3.utils/define-nuxt-component.md +5 -5
  124. package/3.api/3.utils/define-nuxt-plugin.md +13 -13
  125. package/3.api/3.utils/define-nuxt-route-middleware.md +5 -5
  126. package/3.api/3.utils/define-page-meta.md +23 -23
  127. package/3.api/3.utils/define-route-rules.md +7 -7
  128. package/3.api/3.utils/navigate-to.md +11 -11
  129. package/3.api/3.utils/prefetch-components.md +1 -1
  130. package/3.api/3.utils/preload-components.md +1 -1
  131. package/3.api/3.utils/preload-route-components.md +2 -2
  132. package/3.api/3.utils/prerender-routes.md +3 -3
  133. package/3.api/3.utils/refresh-cookie.md +4 -4
  134. package/3.api/3.utils/refresh-nuxt-data.md +12 -7
  135. package/3.api/3.utils/reload-nuxt-app.md +3 -3
  136. package/3.api/3.utils/set-page-layout.md +1 -1
  137. package/3.api/3.utils/set-response-status.md +3 -3
  138. package/3.api/3.utils/show-error.md +5 -5
  139. package/3.api/3.utils/update-app-config.md +4 -3
  140. package/3.api/4.commands/add.md +1 -1
  141. package/3.api/4.commands/analyze.md +2 -1
  142. package/3.api/4.commands/build.md +2 -1
  143. package/3.api/4.commands/dev.md +5 -4
  144. package/3.api/4.commands/generate.md +3 -2
  145. package/3.api/4.commands/init.md +3 -2
  146. package/3.api/4.commands/module.md +4 -4
  147. package/3.api/4.commands/prepare.md +7 -2
  148. package/3.api/4.commands/preview.md +5 -4
  149. package/3.api/4.commands/test.md +40 -0
  150. package/3.api/4.commands/typecheck.md +5 -3
  151. package/3.api/4.commands/upgrade.md +3 -3
  152. package/3.api/5.kit/1.modules.md +36 -36
  153. package/3.api/5.kit/10.runtime-config.md +1 -1
  154. package/3.api/5.kit/10.templates.md +8 -6
  155. package/3.api/5.kit/11.nitro.md +62 -62
  156. package/3.api/5.kit/12.resolving.md +2 -2
  157. package/3.api/5.kit/14.builder.md +1 -0
  158. package/3.api/5.kit/15.examples.md +2 -2
  159. package/3.api/5.kit/16.layers.md +26 -26
  160. package/3.api/5.kit/3.compatibility.md +14 -14
  161. package/3.api/5.kit/4.autoimports.md +13 -13
  162. package/3.api/5.kit/5.components.md +7 -8
  163. package/3.api/5.kit/6.context.md +3 -3
  164. package/3.api/5.kit/7.pages.md +7 -7
  165. package/3.api/5.kit/8.layout.md +2 -2
  166. package/3.api/5.kit/9.plugins.md +5 -4
  167. package/3.api/6.advanced/1.hooks.md +3 -3
  168. package/3.api/6.advanced/2.import-meta.md +3 -3
  169. package/3.api/6.nuxt-config.md +300 -865
  170. package/3.api/index.md +7 -7
  171. package/5.community/2.getting-help.md +1 -1
  172. package/5.community/3.reporting-bugs.md +1 -1
  173. package/5.community/4.contribution.md +11 -11
  174. package/5.community/5.framework-contribution.md +4 -4
  175. package/5.community/6.roadmap.md +1 -1
  176. package/6.bridge/1.overview.md +13 -13
  177. package/6.bridge/10.configuration.md +2 -1
  178. package/6.bridge/2.typescript.md +3 -3
  179. package/6.bridge/3.bridge-composition-api.md +8 -8
  180. package/6.bridge/4.plugins-and-middleware.md +9 -9
  181. package/6.bridge/5.nuxt3-compatible-api.md +20 -17
  182. package/6.bridge/6.meta.md +21 -20
  183. package/6.bridge/7.runtime-config.md +1 -1
  184. package/6.bridge/8.nitro.md +3 -3
  185. package/6.bridge/9.vite.md +4 -4
  186. package/7.migration/1.overview.md +2 -2
  187. package/7.migration/10.bundling.md +1 -1
  188. package/7.migration/11.server.md +3 -3
  189. package/7.migration/2.configuration.md +23 -21
  190. package/7.migration/20.module-authors.md +7 -7
  191. package/7.migration/3.auto-imports.md +3 -3
  192. package/7.migration/4.meta.md +21 -18
  193. package/7.migration/5.plugins-and-middleware.md +8 -8
  194. package/7.migration/6.pages-and-layouts.md +28 -24
  195. package/7.migration/7.component-options.md +18 -18
  196. package/7.migration/8.runtime-config.md +7 -7
  197. package/package.json +1 -1
  198. package/2.guide/2.directory-structure/0.output.md +0 -18
  199. /package/2.guide/{1.concepts → 2.concepts}/.navigation.yml +0 -0
  200. /package/2.guide/{1.concepts → 2.concepts}/9.code-style.md +0 -0
@@ -11,25 +11,25 @@ const count = ref(1) // ref is auto-imported
11
11
  </script>
12
12
  ```
13
13
 
14
- Thanks to its opinionated directory structure, Nuxt can auto-import your [`app/components/`](/docs/guide/directory-structure/app/components), [`app/composables/`](/docs/guide/directory-structure/app/composables) and [`app/utils/`](/docs/guide/directory-structure/app/utils).
14
+ Thanks to its opinionated directory structure, Nuxt can auto-import your [`app/components/`](/docs/4.x/guide/directory-structure/app/components), [`app/composables/`](/docs/4.x/guide/directory-structure/app/composables) and [`app/utils/`](/docs/4.x/guide/directory-structure/app/utils).
15
15
 
16
16
  Contrary to a classic global declaration, Nuxt preserves typings, IDEs completions and hints, and **only includes what is used in your production code**.
17
17
 
18
18
  ::note
19
- In the docs, every function that is not explicitly imported is auto-imported by Nuxt and can be used as-is in your code. You can find a reference for auto-imported components, composables and utilities in the [API section](/docs/api).
19
+ In the docs, every function that is not explicitly imported is auto-imported by Nuxt and can be used as-is in your code. You can find a reference for auto-imported components, composables and utilities in the [API section](/docs/4.x/api).
20
20
  ::
21
21
 
22
22
  ::note
23
- In the [`server`](/docs/guide/directory-structure/server) directory, Nuxt auto-imports exported functions and variables from `server/utils/`.
23
+ In the [`server`](/docs/4.x/guide/directory-structure/server) directory, Nuxt auto-imports exported functions and variables from `server/utils/`.
24
24
  ::
25
25
 
26
26
  ::note
27
- You can also auto-import functions exported from custom folders or third-party packages by configuring the [`imports`](/docs/api/nuxt-config#imports) section of your `nuxt.config` file.
27
+ You can also auto-import functions exported from custom folders or third-party packages by configuring the [`imports`](/docs/4.x/api/nuxt-config#imports) section of your `nuxt.config` file.
28
28
  ::
29
29
 
30
30
  ## Built-in Auto-imports
31
31
 
32
- Nuxt auto-imports functions and composables to perform [data fetching](/docs/getting-started/data-fetching), get access to the [app context](/docs/api/composables/use-nuxt-app) and [runtime config](/docs/guide/going-further/runtime-config), manage [state](/docs/getting-started/state-management) or define components and plugins.
32
+ Nuxt auto-imports functions and composables to perform [data fetching](/docs/4.x/getting-started/data-fetching), get access to the [app context](/docs/4.x/api/composables/use-nuxt-app) and [runtime config](/docs/4.x/guide/going-further/runtime-config), manage [state](/docs/4.x/getting-started/state-management) or define components and plugins.
33
33
 
34
34
  ```vue twoslash
35
35
  <script setup lang="ts">
@@ -66,7 +66,7 @@ If you get an error message like `Nuxt instance is unavailable` then it probably
66
66
  When using a composable that requires the Nuxt context inside a non-SFC component, you need to wrap your component with `defineNuxtComponent` instead of `defineComponent`
67
67
  ::
68
68
 
69
- ::read-more{to="/docs/guide/going-further/experimental-features#asynccontext" icon="i-lucide-star"}
69
+ ::read-more{to="/docs/4.x/guide/going-further/experimental-features#asynccontext" icon="i-lucide-star"}
70
70
  Checkout the `asyncContext` experimental feature to use Nuxt composables in async functions.
71
71
  ::
72
72
 
@@ -101,11 +101,11 @@ export const useMyComposable = () => {
101
101
 
102
102
  Nuxt directly auto-imports files created in defined directories:
103
103
 
104
- - `app/components/` for [Vue components](/docs/guide/directory-structure/app/components).
105
- - `app/composables/` for [Vue composables](/docs/guide/directory-structure/app/composables).
104
+ - `app/components/` for [Vue components](/docs/4.x/guide/directory-structure/app/components).
105
+ - `app/composables/` for [Vue composables](/docs/4.x/guide/directory-structure/app/composables).
106
106
  - `app/utils/` for helper functions and other utilities.
107
107
 
108
- :link-example{to="/docs/examples/features/auto-imports"}
108
+ :link-example{to="/docs/4.x/examples/features/auto-imports"}
109
109
 
110
110
  ::warning
111
111
  **Auto-imported `ref` and `computed` won't be unwrapped in a component `<template>`.** :br
@@ -120,7 +120,7 @@ Nuxt exposes every auto-import with the `#imports` alias that can be used to mak
120
120
 
121
121
  ```vue
122
122
  <script setup lang="ts">
123
- import { ref, computed } from '#imports'
123
+ import { computed, ref } from '#imports'
124
124
 
125
125
  const count = ref(1)
126
126
  const double = computed(() => count.value * 2)
@@ -134,12 +134,12 @@ If you want to disable auto-importing composables and utilities, you can set `im
134
134
  ```ts twoslash [nuxt.config.ts]
135
135
  export default defineNuxtConfig({
136
136
  imports: {
137
- autoImport: false
138
- }
137
+ autoImport: false,
138
+ },
139
139
  })
140
140
  ```
141
141
 
142
- This will disable auto-imports completely but it's still possible to use [explicit imports](#explicit-imports) from `#imports`.
142
+ This will disable auto-imports completely but it's still possible to use [explicit imports](/docs/4.x/guide/concepts/auto-imports#explicit-imports) from `#imports`.
143
143
 
144
144
  ### Partially Disabling Auto-imports
145
145
 
@@ -148,8 +148,8 @@ If you want framework-specific functions like `ref` to remain auto-imported but
148
148
  ```ts
149
149
  export default defineNuxtConfig({
150
150
  imports: {
151
- scan: false
152
- }
151
+ scan: false,
152
+ },
153
153
  })
154
154
  ```
155
155
 
@@ -167,15 +167,15 @@ With this configuration:
167
167
 
168
168
  Nuxt also automatically imports components from your `~/components` directory, although this is configured separately from auto-importing composables and utility functions.
169
169
 
170
- :read-more{to="/docs/guide/directory-structure/app/components"}
170
+ :read-more{to="/docs/4.x/guide/directory-structure/app/components"}
171
171
 
172
172
  To disable auto-importing components from your own `~/components` directory, you can set `components.dirs` to an empty array (though note that this will not affect components added by modules).
173
173
 
174
174
  ```ts twoslash [nuxt.config.ts]
175
175
  export default defineNuxtConfig({
176
176
  components: {
177
- dirs: []
178
- }
177
+ dirs: [],
178
+ },
179
179
  })
180
180
  ```
181
181
 
@@ -195,10 +195,10 @@ export default defineNuxtConfig({
195
195
  presets: [
196
196
  {
197
197
  from: 'vue-i18n',
198
- imports: ['useI18n']
199
- }
200
- ]
201
- }
198
+ imports: ['useI18n'],
199
+ },
200
+ ],
201
+ },
202
202
  })
203
203
  ```
204
204
 
@@ -22,7 +22,7 @@ When Nitro starts, it initializes and executes the plugins under the `/server/pl
22
22
  Nitro plugins are executed only once when the server starts. In a serverless environment, the server boots on each incoming request, and so do the Nitro plugins. However, they are not awaited.
23
23
  ::
24
24
 
25
- :read-more{to="/docs/guide/directory-structure/server#server-plugins"}
25
+ :read-more{to="/docs/4.x/guide/directory-structure/server#server-plugins"}
26
26
 
27
27
  ### Step 2: Nitro Server Middleware
28
28
 
@@ -32,7 +32,7 @@ After initializing the Nitro server, middleware under `server/middleware/` is ex
32
32
  Returning a value from middleware will terminate the request and send the returned value as the response. This behavior should generally be avoided to ensure proper request handling!
33
33
  ::
34
34
 
35
- :read-more{to="/docs/guide/directory-structure/server#server-middleware"}
35
+ :read-more{to="/docs/4.x/guide/directory-structure/server#server-middleware"}
36
36
 
37
37
  ### Step 3: Initialize Nuxt and Execute Nuxt App Plugins
38
38
 
@@ -40,13 +40,13 @@ The Vue and Nuxt instances are created first. Afterward, Nuxt executes its serve
40
40
  - Built-in plugins, such as Vue Router and `unhead`.
41
41
  - Custom plugins located in the `app/plugins/` directory, including those without a suffix (e.g., `myPlugin.ts`) and those with the `.server` suffix (e.g., `myServerPlugin.server.ts`).
42
42
 
43
- Plugins execute in a specific order and may have dependencies on one another. For more details, including execution order and parallelism, refer to the [Plugins documentation](/docs/guide/directory-structure/plugins).
43
+ Plugins execute in a specific order and may have dependencies on one another. For more details, including execution order and parallelism, refer to the [Plugins documentation](/docs/4.x/guide/directory-structure/plugins).
44
44
 
45
45
  ::callout{icon="i-lucide-lightbulb"}
46
- After this step, Nuxt calls the [`app:created`](/docs/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
46
+ After this step, Nuxt calls the [`app:created`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
47
47
  ::
48
48
 
49
- :read-more{to="/docs/guide/directory-structure/plugins"}
49
+ :read-more{to="/docs/4.x/guide/directory-structure/plugins"}
50
50
 
51
51
  ### Step 4: Route Validation
52
52
 
@@ -55,9 +55,9 @@ After initializing plugins and before executing middleware, Nuxt calls the `vali
55
55
  - The `validate` function should return `true` if the parameters are valid.
56
56
  - If validation fails, it should return `false` or an object containing a `statusCode` and/or `statusMessage` to terminate the request.
57
57
 
58
- For more information, see the [Route Validation documentation](/docs/getting-started/routing#route-validation).
58
+ For more information, see the [Route Validation documentation](/docs/4.x/getting-started/routing#route-validation).
59
59
 
60
- :read-more{to="/docs/getting-started/routing#route-validation"}
60
+ :read-more{to="/docs/4.x/getting-started/routing#route-validation"}
61
61
 
62
62
  ### Step 5: Execute Nuxt App Middleware
63
63
 
@@ -70,11 +70,11 @@ In Nuxt, there are three types of middleware:
70
70
 
71
71
  Nuxt executes all global middleware on the initial page load (both on server and client) and then again before any client-side navigation. Named and anonymous middleware are executed only on the routes specified in the middleware property of the page(route) meta defined in the corresponding page components.
72
72
 
73
- For details about each type and examples, see the [Middleware documentation](/docs/guide/directory-structure/app/middleware).
73
+ For details about each type and examples, see the [Middleware documentation](/docs/4.x/guide/directory-structure/app/middleware).
74
74
 
75
75
  Any redirection on the server will result in a `Location:` header being sent to the browser; the browser then makes a fresh request to this new location. All application state will be reset when this happens, unless persisted in a cookie.
76
76
 
77
- :read-more{to="/docs/guide/directory-structure/app/middleware"}
77
+ :read-more{to="/docs/4.x/guide/directory-structure/app/middleware"}
78
78
 
79
79
  ### Step 6: Render Page and Components
80
80
 
@@ -99,11 +99,11 @@ Watch a video from Daniel Roe explaining Server Rendering and Global State.
99
99
  After all required data is fetched and the components are rendered, Nuxt combines the rendered components with settings from `unhead` to generate a complete HTML document. This HTML, along with the associated data, is then sent back to the client to complete the SSR process.
100
100
 
101
101
  ::callout{icon="i-lucide-lightbulb"}
102
- After rendering the Vue application to HTML, Nuxt calls the [`app:rendered`](/docs/api/advanced/hooks#app-hooks-runtime) hook.
102
+ After rendering the Vue application to HTML, Nuxt calls the [`app:rendered`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook.
103
103
  ::
104
104
 
105
105
  ::callout{icon="i-lucide-lightbulb"}
106
- Before finalizing and sending the HTML, Nitro will call the [`render:html`](/docs/api/advanced/hooks#nitro-app-hooks-runtime-server-side) hook. This hook allows you to manipulate the generated HTML, such as injecting additional scripts or modifying meta tags.
106
+ Before finalizing and sending the HTML, Nitro will call the [`render:html`](/docs/4.x/api/advanced/hooks#nitro-app-hooks-runtime-server-side) hook. This hook allows you to manipulate the generated HTML, such as injecting additional scripts or modifying meta tags.
107
107
  ::
108
108
 
109
109
  ## Client (browser)
@@ -117,10 +117,10 @@ This step is similar to the server-side execution and includes both built-in and
117
117
  Custom plugins in the `app/plugins/` directory, such as those without a suffix (e.g., `myPlugin.ts`) and with the `.client` suffix (e.g., `myClientPlugin.client.ts`), are executed on the client side.
118
118
 
119
119
  ::callout{icon="i-lucide-lightbulb"}
120
- After this step, Nuxt calls the [`app:created`](/docs/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
120
+ After this step, Nuxt calls the [`app:created`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
121
121
  ::
122
122
 
123
- :read-more{to="/docs/guide/directory-structure/plugins"}
123
+ :read-more{to="/docs/4.x/guide/directory-structure/plugins"}
124
124
 
125
125
  ### Step 2: Route Validation
126
126
 
@@ -130,20 +130,20 @@ This step is the same as the server-side execution and includes the `validate` m
130
130
 
131
131
  Nuxt middleware runs on both the server and the client. If you want certain code to run in specific environments, consider splitting it by using `import.meta.client` for the client and `import.meta.server` for the server.
132
132
 
133
- :read-more{to="/docs/guide/directory-structure/app/middleware#when-middleware-runs"}
133
+ :read-more{to="/docs/4.x/guide/directory-structure/app/middleware#when-middleware-runs"}
134
134
 
135
135
  ### Step 4: Mount Vue Application and Hydration
136
136
 
137
- Calling `app.mount('#__nuxt')` mounts the Vue application to the DOM. If the application uses SSR or SSG mode, Vue performs a hydration step to make the client-side application interactive. During hydration, Vue recreates the application (excluding [Server Components](/docs/guide/directory-structure/app/components#server-components)), matches each component to its corresponding DOM nodes, and attaches DOM event listeners.
137
+ Calling `app.mount('#__nuxt')` mounts the Vue application to the DOM. If the application uses SSR or SSG mode, Vue performs a hydration step to make the client-side application interactive. During hydration, Vue recreates the application (excluding [Server Components](/docs/4.x/guide/directory-structure/app/components#server-components)), matches each component to its corresponding DOM nodes, and attaches DOM event listeners.
138
138
 
139
139
  To ensure proper hydration, it's important to maintain consistency between the data on the server and the client. For API requests, it is recommended to use `useAsyncData`, `useFetch`, or other SSR-friendly composables. These methods ensure that the data fetched on the server side is reused during hydration, avoiding repeated requests. Any new requests should only be triggered after hydration, preventing hydration errors.
140
140
 
141
141
  ::callout{icon="i-lucide-lightbulb"}
142
- Before mounting the Vue application, Nuxt calls the [`app:beforeMount`](/docs/api/advanced/hooks#app-hooks-runtime) hook.
142
+ Before mounting the Vue application, Nuxt calls the [`app:beforeMount`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook.
143
143
  ::
144
144
 
145
145
  ::callout{icon="i-lucide-lightbulb"}
146
- After mounting the Vue application, Nuxt calls the [`app:mounted`](/docs/api/advanced/hooks#app-hooks-runtime) hook.
146
+ After mounting the Vue application, Nuxt calls the [`app:mounted`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook.
147
147
  ::
148
148
 
149
149
  ### Step 5: Vue Lifecycle
@@ -25,17 +25,17 @@ We chose to build Nuxt on top of Vue for these reasons:
25
25
 
26
26
  ### Auto-imports
27
27
 
28
- Every Vue component created in the [`app/components/`](/docs/guide/directory-structure/app/components) directory of a Nuxt project will be available in your project without having to import it. If a component is not used anywhere, your production’s code will not include it.
28
+ Every Vue component created in the [`app/components/`](/docs/4.x/guide/directory-structure/app/components) directory of a Nuxt project will be available in your project without having to import it. If a component is not used anywhere, your production’s code will not include it.
29
29
 
30
- :read-more{to="/docs/guide/concepts/auto-imports"}
30
+ :read-more{to="/docs/4.x/guide/concepts/auto-imports"}
31
31
 
32
32
  ### Vue Router
33
33
 
34
- Most applications need multiple pages and a way to navigate between them. This is called **routing**. Nuxt uses an [`app/pages/`](/docs/guide/directory-structure/app/pages) directory and naming conventions to directly create routes mapped to your files using the official [Vue Router library](https://router.vuejs.org).
34
+ Most applications need multiple pages and a way to navigate between them. This is called **routing**. Nuxt uses an [`app/pages/`](/docs/4.x/guide/directory-structure/app/pages) directory and naming conventions to directly create routes mapped to your files using the official [Vue Router library](https://router.vuejs.org).
35
35
 
36
- :read-more{to="/docs/getting-started/routing"}
36
+ :read-more{to="/docs/4.x/getting-started/routing"}
37
37
 
38
- :link-example{to="/docs/examples/features/auto-imports"}
38
+ :link-example{to="/docs/4.x/examples/features/auto-imports"}
39
39
 
40
40
  ## Differences with Nuxt 2 / Vue 2
41
41
 
@@ -64,16 +64,16 @@ The only way to provide data and logic to components in Vue 2 was through the Op
64
64
  ```vue twoslash
65
65
  <script>
66
66
  export default {
67
- data() {
67
+ data () {
68
68
  return {
69
- count: 0
69
+ count: 0,
70
70
  }
71
71
  },
72
72
  methods: {
73
- increment(){
73
+ increment () {
74
74
  this.count++
75
- }
76
- }
75
+ },
76
+ },
77
77
  }
78
78
  </script>
79
79
  ```
@@ -91,13 +91,13 @@ const increment = () => count.value++
91
91
 
92
92
  The goal of Nuxt is to provide a great developer experience around the Composition API.
93
93
 
94
- - Use auto-imported [Reactivity functions](https://vuejs.org/api/reactivity-core.html) from Vue and Nuxt [built-in composables](/docs/api/composables/use-async-data).
95
- - Write your own auto-imported reusable functions in the [`app/composables/` directory](/docs/guide/directory-structure/app/composables).
94
+ - Use auto-imported [Reactivity functions](https://vuejs.org/api/reactivity-core.html) from Vue and Nuxt [built-in composables](/docs/4.x/api/composables/use-async-data).
95
+ - Write your own auto-imported reusable functions in the [`app/composables/` directory](/docs/4.x/guide/directory-structure/app/composables).
96
96
 
97
97
  ### TypeScript Support
98
98
 
99
99
  Both Vue 3 and Nuxt 3+ are written in TypeScript. A fully typed codebase prevents mistakes and documents APIs usage. This doesn’t mean that you have to write your application in TypeScript to take advantage of it. With Nuxt 3, you can opt-in by renaming your file from `.js` to `.ts` , or add `<script setup lang="ts">` in a component.
100
100
 
101
- ::read-more{to="/docs/guide/concepts/typescript"}
101
+ ::read-more{to="/docs/4.x/guide/concepts/typescript"}
102
102
  Read the details about TypeScript in Nuxt
103
103
  ::
@@ -3,11 +3,11 @@ title: 'Rendering Modes'
3
3
  description: 'Learn about the different rendering modes available in Nuxt.'
4
4
  ---
5
5
 
6
- Nuxt supports different rendering modes, [universal rendering](#universal-rendering), [client-side rendering](#client-side-rendering) but also offers [hybrid-rendering](#hybrid-rendering) and the possibility to render your application on [CDN Edge Servers](#edge-side-rendering).
6
+ Nuxt supports different rendering modes, [universal rendering](/docs/4.x/guide/concepts/rendering#universal-rendering), [client-side rendering](/docs/4.x/guide/concepts/rendering#client-side-rendering) but also offers [hybrid-rendering](/docs/4.x/guide/concepts/rendering#hybrid-rendering) and the possibility to render your application on [CDN Edge Servers](/docs/4.x/guide/concepts/rendering#edge-side-rendering).
7
7
 
8
8
  Both the browser and server can interpret JavaScript code to turn Vue.js components into HTML elements. This step is called **rendering**. Nuxt supports both **universal** and **client-side** rendering. The two approaches have benefits and downsides that we will cover.
9
9
 
10
- By default, Nuxt uses **universal rendering** to provide better user experience, performance and to optimize search engine indexing, but you can switch rendering modes in [one line of configuration](/docs/api/nuxt-config#ssr).
10
+ By default, Nuxt uses **universal rendering** to provide better user experience, performance and to optimize search engine indexing, but you can switch rendering modes in [one line of configuration](/docs/4.x/api/nuxt-config#ssr).
11
11
 
12
12
  ## Universal Rendering
13
13
 
@@ -25,24 +25,26 @@ It is normal to ask which parts of a Vue file runs on the server and/or the clie
25
25
 
26
26
  ```vue [app/app.vue]
27
27
  <script setup lang="ts">
28
- const counter = ref(0); // executes in server and client environments
28
+ const counter = ref(0) // executes in server and client environments
29
29
 
30
30
  const handleClick = () => {
31
- counter.value++; // executes only in a client environment
32
- };
31
+ counter.value++ // executes only in a client environment
32
+ }
33
33
  </script>
34
34
 
35
35
  <template>
36
36
  <div>
37
37
  <p>Count: {{ counter }}</p>
38
- <button @click="handleClick">Increment</button>
38
+ <button @click="handleClick">
39
+ Increment
40
+ </button>
39
41
  </div>
40
42
  </template>
41
43
  ```
42
44
 
43
45
  On the initial request, the `counter` ref is initialized in the server since it is rendered inside the `<p>` tag. The contents of `handleClick` is never executed here. During hydration in the browser, the `counter` ref is re-initialized. The `handleClick` finally binds itself to the button; Therefore it is reasonable to deduce that the body of `handleClick` will always run in a browser environment.
44
46
 
45
- [Middlewares](/docs/guide/directory-structure/app/middleware) and [pages](/docs/guide/directory-structure/app/pages) run in the server and on the client during hydration. [Plugins](/docs/guide/directory-structure/plugins) can be rendered on the server or client or both. [Components](/docs/guide/directory-structure/app/components) can be forced to run on the client only as well. [Composables](/docs/guide/directory-structure/app/composables) and [utilities](/docs/guide/directory-structure/app/utils) are rendered based on the context of their usage.
47
+ [Middlewares](/docs/4.x/guide/directory-structure/app/middleware) and [pages](/docs/4.x/guide/directory-structure/app/pages) run in the server and on the client during hydration. [Plugins](/docs/4.x/guide/directory-structure/plugins) can be rendered on the server or client or both. [Components](/docs/4.x/guide/directory-structure/app/components) can be forced to run on the client only as well. [Composables](/docs/4.x/guide/directory-structure/app/composables) and [utilities](/docs/4.x/guide/directory-structure/app/utils) are rendered based on the context of their usage.
46
48
 
47
49
  **Benefits of server-side rendering:**
48
50
  - **Performance**: Users can get immediate access to the page's content because browsers can display static content much faster than JavaScript-generated content. At the same time, Nuxt preserves the interactivity of a web application during the hydration process.
@@ -50,7 +52,7 @@ On the initial request, the `counter` ref is initialized in the server since it
50
52
 
51
53
  **Downsides of server-side rendering:**
52
54
  - **Development constraints:** Server and browser environments don't provide the same APIs, and it can be tricky to write code that can run on both sides seamlessly. Fortunately, Nuxt provides guidelines and specific variables to help you determine where a piece of code is executed.
53
- - **Cost:** A server needs to be running in order to render pages on the fly. This adds a monthly cost like any traditional server. However, the server calls are highly reduced thanks to universal rendering with the browser taking over on client-side navigation. A cost reduction is possible by leveraging [edge-side-rendering](#edge-side-rendering).
55
+ - **Cost:** A server needs to be running in order to render pages on the fly. This adds a monthly cost like any traditional server. However, the server calls are highly reduced thanks to universal rendering with the browser taking over on client-side navigation. A cost reduction is possible by leveraging [edge-side-rendering](/docs/4.x/guide/concepts/rendering#edge-side-rendering).
54
56
 
55
57
  Universal rendering is very versatile and can fit almost any use case, and is especially appropriate for any content-oriented websites: **blogs, marketing websites, portfolios, e-commerce sites, and marketplaces.**
56
58
 
@@ -83,20 +85,20 @@ You can enable client-side only rendering with Nuxt in your `nuxt.config.ts`:
83
85
 
84
86
  ```ts [nuxt.config.ts]
85
87
  export default defineNuxtConfig({
86
- ssr: false
88
+ ssr: false,
87
89
  })
88
90
  ```
89
91
 
90
92
  ::note
91
93
  If you do use `ssr: false`, you should also place an HTML file in `~/spa-loading-template.html` with some HTML you would like to use to render a loading screen that will be rendered until your app is hydrated.
92
- :read-more{title="SPA Loading Template" to="/docs/api/configuration/nuxt-config#spaloadingtemplate"}
94
+ :read-more{title="SPA Loading Template" to="/docs/4.x/api/configuration/nuxt-config#spaloadingtemplate"}
93
95
  ::
94
96
 
95
97
  :video-accordion{title="Watch a video from Alexander Lichter about Building a plain SPA with Nuxt" videoId="7Lr0QTP1Ro8"}
96
98
 
97
99
  ### Deploying a Static Client-Rendered App
98
100
 
99
- If you deploy your app to [static hosting](/docs/getting-started/deployment#static-hosting) with the `nuxt generate` or `nuxt build --prerender` commands, then by default, Nuxt will render every page as a separate static HTML file.
101
+ If you deploy your app to [static hosting](/docs/4.x/getting-started/deployment#static-hosting) with the `nuxt generate` or `nuxt build --prerender` commands, then by default, Nuxt will render every page as a separate static HTML file.
100
102
 
101
103
  ::warning
102
104
  If you prerender your app with the `nuxt generate` or `nuxt build --prerender` commands, then you will not be able to use any server endpoints as no server will be included in your output folder. If you need server functionality, use `nuxt build` instead.
@@ -104,14 +106,14 @@ If you prerender your app with the `nuxt generate` or `nuxt build --prerender` c
104
106
 
105
107
  If you are using purely client-side rendering, then this might be unnecessary. You might only need a single `index.html` file, plus `200.html` and `404.html` fallbacks, which you can tell your static web host to serve up for all requests.
106
108
 
107
- In order to achieve this we can change how the routes are prerendered. Just add this to [your hooks](/docs/api/advanced/hooks#nuxt-hooks-build-time) in your `nuxt.config.ts`:
109
+ In order to achieve this we can change how the routes are prerendered. Just add this to [your hooks](/docs/4.x/api/advanced/hooks#nuxt-hooks-build-time) in your `nuxt.config.ts`:
108
110
 
109
111
  ```ts twoslash [nuxt.config.ts]
110
112
  export default defineNuxtConfig({
111
113
  hooks: {
112
114
  'prerender:routes' ({ routes }) {
113
115
  routes.clear() // Do not generate any routes (except the defaults)
114
- }
116
+ },
115
117
  },
116
118
  })
117
119
  ```
@@ -126,21 +128,21 @@ The `200.html` and `404.html` might be useful for the hosting provider you are u
126
128
 
127
129
  #### Skipping Client Fallback Generation
128
130
 
129
- When prerendering a client-rendered app, Nuxt will generate `index.html`, `200.html` and `404.html` files by default. However, if you need to prevent any (or all) of these files from being generated in your build, you can use the `'prerender:generate'` hook from [Nitro](/docs/getting-started/prerendering#prerendergenerate-nitro-hook).
131
+ When prerendering a client-rendered app, Nuxt will generate `index.html`, `200.html` and `404.html` files by default. However, if you need to prevent any (or all) of these files from being generated in your build, you can use the `'prerender:generate'` hook from [Nitro](/docs/4.x/getting-started/prerendering#prerendergenerate-nitro-hook).
130
132
 
131
133
  ```ts twoslash [nuxt.config.ts]
132
134
  export default defineNuxtConfig({
133
135
  ssr: false,
134
136
  nitro: {
135
137
  hooks: {
136
- 'prerender:generate'(route) {
138
+ 'prerender:generate' (route) {
137
139
  const routesToSkip = ['/index.html', '/200.html', '/404.html']
138
140
  if (routesToSkip.includes(route.route)) {
139
141
  route.skip = true
140
142
  }
141
- }
142
- }
143
- }
143
+ },
144
+ },
145
+ },
144
146
  })
145
147
  ```
146
148
 
@@ -172,8 +174,8 @@ export default defineNuxtConfig({
172
174
  // Add cors headers on API routes
173
175
  '/api/**': { cors: true },
174
176
  // Redirects legacy urls
175
- '/old-page': { redirect: '/new-page' }
176
- }
177
+ '/old-page': { redirect: '/new-page' },
178
+ },
177
179
  })
178
180
  ```
179
181
 
@@ -193,7 +195,7 @@ The different properties you can use are the following:
193
195
  Whenever possible, route rules will be automatically applied to the deployment platform's native rules for optimal performances (Netlify and Vercel are currently supported).
194
196
 
195
197
  ::important
196
- Note that Hybrid Rendering is not available when using [`nuxt generate`](/docs/api/commands/generate).
198
+ Note that Hybrid Rendering is not available when using [`nuxt generate`](/docs/4.x/api/commands/generate).
197
199
  ::
198
200
 
199
201
  **Examples:**
@@ -219,7 +221,7 @@ With ESR, the rendering process is pushed to the 'edge' of the network - the CDN
219
221
 
220
222
  When a request for a page is made, instead of going all the way to the original server, it's intercepted by the nearest edge server. This server generates the HTML for the page and sends it back to the user. This process minimizes the physical distance the data has to travel, **reducing latency and loading the page faster**.
221
223
 
222
- Edge-side rendering is possible thanks to [Nitro](https://nitro.build/), the [server engine](/docs/guide/concepts/server-engine) that powers Nuxt. It offers cross-platform support for Node.js, Deno, Cloudflare Workers, and more.
224
+ Edge-side rendering is possible thanks to [Nitro](https://nitro.build/), the [server engine](/docs/4.x/guide/concepts/server-engine) that powers Nuxt. It offers cross-platform support for Node.js, Deno, Cloudflare Workers, and more.
223
225
 
224
226
  The current platforms where you can leverage ESR are:
225
227
  - [Cloudflare Pages](https://pages.cloudflare.com) with zero configuration using the git integration and the `nuxt build` command
@@ -16,7 +16,7 @@ It is shipped with many features:
16
16
 
17
17
  ## API Layer
18
18
 
19
- Server [API endpoints](/docs/guide/directory-structure/server#api-routes) and [Middleware](/docs/guide/directory-structure/server#server-middleware) are added by Nitro that internally uses [h3](https://github.com/h3js/h3).
19
+ Server [API endpoints](/docs/4.x/guide/directory-structure/server#server-routes) and [Middleware](/docs/4.x/guide/directory-structure/server#server-middleware) are added by Nitro that internally uses [h3](https://github.com/h3js/h3).
20
20
 
21
21
  Key features include:
22
22
 
@@ -26,15 +26,15 @@ Key features include:
26
26
 
27
27
  Check out [the h3 docs](https://github.com/h3js/h3) for more information.
28
28
 
29
- ::read-more{to="/docs/guide/directory-structure/server#server-routes"}
29
+ ::read-more{to="/docs/4.x/guide/directory-structure/server#server-routes"}
30
30
  Learn more about the API layer in the `server/` directory.
31
31
  ::
32
32
 
33
33
  ## Direct API Calls
34
34
 
35
- Nitro allows 'direct' calling of routes via the globally-available [`$fetch`](/docs/api/utils/dollarfetch) helper. This will make an API call to the server if run on the browser, but will directly call the relevant function if run on the server, **saving an additional API call**.
35
+ Nitro allows 'direct' calling of routes via the globally-available [`$fetch`](/docs/4.x/api/utils/dollarfetch) helper. This will make an API call to the server if run on the browser, but will directly call the relevant function if run on the server, **saving an additional API call**.
36
36
 
37
- [`$fetch`](/docs/api/utils/dollarfetch) API is using [ofetch](https://github.com/unjs/ofetch), with key features including:
37
+ [`$fetch`](/docs/4.x/api/utils/dollarfetch) API is using [ofetch](https://github.com/unjs/ofetch), with key features including:
38
38
 
39
39
  - Automatic parsing of JSON responses (with access to raw response if needed)
40
40
  - Request body and params are automatically handled, with correct `Content-Type` headers
@@ -45,7 +45,7 @@ For more information on `$fetch` features, check out [ofetch](https://github.com
45
45
 
46
46
  When using API routes (or middleware), Nitro will generate typings for these routes as long as you are returning a value instead of using `res.end()` to send a response.
47
47
 
48
- You can access these types when using [`$fetch()`](/docs/api/utils/dollarfetch) or [`useFetch()`](/docs/api/composables/use-fetch).
48
+ You can access these types when using [`$fetch()`](/docs/4.x/api/utils/dollarfetch) or [`useFetch()`](/docs/4.x/api/composables/use-fetch).
49
49
 
50
50
  ## Standalone Server
51
51
 
@@ -53,7 +53,7 @@ Nitro produces a standalone server dist that is independent of `node_modules`.
53
53
 
54
54
  The server in Nuxt 2 is not standalone and requires part of Nuxt core to be involved by running `nuxt start` (with the [`nuxt-start`](https://www.npmjs.com/package/nuxt-start) or [`nuxt`](https://www.npmjs.com/package/nuxt) distributions) or custom programmatic usage, which is fragile and prone to breakage and not suitable for serverless and service worker environments.
55
55
 
56
- Nuxt generates this dist when running `nuxt build` into a [`.output`](/docs/guide/directory-structure/output) directory.
56
+ Nuxt generates this dist when running `nuxt build` into a [`.output`](/docs/4.x/guide/directory-structure/output) directory.
57
57
 
58
58
  The output contains runtime code to run your Nuxt server in any environment (including experimental browser service workers!) and serve your static files, making it a true hybrid framework for the JAMstack. In addition, Nuxt implements a native storage layer, supporting multi-source drivers and local assets.
59
59
 
@@ -7,7 +7,7 @@ description: "Nuxt provides a module system to extend the framework core and sim
7
7
 
8
8
  When developing production-grade applications with Nuxt you might find that the framework's core functionality is not enough. Nuxt can be extended with configuration options and plugins, but maintaining these customizations across multiple projects can be tedious, repetitive and time-consuming. On the other hand, supporting every project's needs out of the box would make Nuxt very complex and hard to use.
9
9
 
10
- This is one of the reasons why Nuxt provides a module system that makes it possible to extend the core. Nuxt modules are async functions that sequentially run when starting Nuxt in development mode using [`nuxt dev`](/docs/api/commands/dev) or building a project for production with [`nuxt build`](/docs/api/commands/build). They can override templates, configure webpack loaders, add CSS libraries, and perform many other useful tasks.
10
+ This is one of the reasons why Nuxt provides a module system that makes it possible to extend the core. Nuxt modules are async functions that sequentially run when starting Nuxt in development mode using [`nuxt dev`](/docs/4.x/api/commands/dev) or building a project for production with [`nuxt build`](/docs/4.x/api/commands/build). They can override templates, configure webpack loaders, add CSS libraries, and perform many other useful tasks.
11
11
 
12
12
  Best of all, Nuxt modules can be distributed in npm packages. This makes it possible for them to be reused across projects and shared with the community, helping create an ecosystem of high-quality add-ons.
13
13
 
@@ -17,7 +17,7 @@ Explore Nuxt Modules
17
17
 
18
18
  ## Add Nuxt Modules
19
19
 
20
- Once you have installed the modules you can add them to your [`nuxt.config.ts`](/docs/guide/directory-structure/nuxt-config) file under the `modules` property. Module developers usually provide additional steps and details for usage.
20
+ Once you have installed the modules you can add them to your [`nuxt.config.ts`](/docs/4.x/guide/directory-structure/nuxt-config) file under the `modules` property. Module developers usually provide additional steps and details for usage.
21
21
 
22
22
  ```ts twoslash [nuxt.config.ts]
23
23
  export default defineNuxtConfig({
@@ -32,8 +32,8 @@ export default defineNuxtConfig({
32
32
  ['./modules/example', { token: '123' }],
33
33
 
34
34
  // Inline module definition
35
- async (inlineOptions, nuxt) => { }
36
- ]
35
+ async (inlineOptions, nuxt) => { },
36
+ ],
37
37
  })
38
38
  ```
39
39
 
@@ -45,4 +45,4 @@ Nuxt modules are now build-time-only, and the `buildModules` property used in Nu
45
45
 
46
46
  Everyone has the opportunity to develop modules and we cannot wait to see what you will build.
47
47
 
48
- :read-more{to="/docs/guide/going-further/modules" title="Module Author Guide"}
48
+ :read-more{to="/docs/4.x/guide/going-further/modules" title="Module Author Guide"}
@@ -32,7 +32,7 @@ export { a }
32
32
 
33
33
  Before ECMAScript Modules (ESM) became a standard (it took more than 10 years!), tooling like
34
34
  [webpack](https://webpack.js.org/guides/ecma-script-modules) and even languages like TypeScript started supporting so-called **ESM syntax**.
35
- However, there are some key differences with actual spec; here's [a helpful explainer](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive).
35
+ However, there are some key differences with actual spec; here's [a helpful explainer](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/).
36
36
 
37
37
  ### What is 'Native' ESM?
38
38
 
@@ -111,7 +111,7 @@ const { named } = pkg;
111
111
 
112
112
  ## Troubleshooting ESM Issues
113
113
 
114
- If you encounter these errors, the issue is almost certainly with the upstream library. They need to [fix their library](#library-author-guide) to support being imported by Node.
114
+ If you encounter these errors, the issue is almost certainly with the upstream library. They need to [fix their library](/docs/4.x/guide/concepts/esm#library-author-guide) to support being imported by Node.
115
115
 
116
116
  ### Transpiling Libraries
117
117
 
@@ -120,8 +120,8 @@ In the meantime, you can tell Nuxt not to try to import these libraries by addin
120
120
  ```ts twoslash
121
121
  export default defineNuxtConfig({
122
122
  build: {
123
- transpile: ['sample-library']
124
- }
123
+ transpile: ['sample-library'],
124
+ },
125
125
  })
126
126
  ```
127
127
 
@@ -134,8 +134,8 @@ In some cases, you may also need to manually alias the library to the CJS versio
134
134
  ```ts twoslash
135
135
  export default defineNuxtConfig({
136
136
  alias: {
137
- 'sample-library': 'sample-library/dist/sample-library.cjs.js'
138
- }
137
+ 'sample-library': 'sample-library/dist/sample-library.cjs.js',
138
+ },
139
139
  })
140
140
  ```
141
141
 
@@ -182,6 +182,8 @@ import('cjs-pkg').then(console.log) // [Module: null prototype] { default: { tes
182
182
 
183
183
  In this case, we need to manually interop the default export:
184
184
 
185
+ <!-- eslint-disable import/no-named-default -->
186
+
185
187
  ```js
186
188
  // Static import
187
189
  import { default as pkg } from 'cjs-pkg'
@@ -219,16 +221,16 @@ The initial step from CJS to ESM is updating any usage of `require` to use `impo
219
221
 
220
222
  ::code-group
221
223
 
222
- ```js [Before]
223
- module.exports = ...
224
+ ```ts [Before]
225
+ module.exports = function () { /* ... */ }
224
226
 
225
- exports.hello = ...
227
+ exports.hello = 'world'
226
228
  ```
227
229
 
228
- ```js [After]
229
- export default ...
230
+ ```ts [After]
231
+ export default function () { /* ... */ }
230
232
 
231
- export const hello = ...
233
+ export const hello = 'world'
232
234
  ```
233
235
 
234
236
  ::
@@ -242,7 +244,7 @@ const myLib = require('my-lib')
242
244
  ```js [After]
243
245
  import myLib from 'my-lib'
244
246
  // or
245
- const myLib = await import('my-lib').then(lib => lib.default || lib)
247
+ const dynamicMyLib = await import('my-lib').then(lib => lib.default || lib)
246
248
  ```
247
249
 
248
250
  ::
@@ -253,7 +255,7 @@ and should be replaced with `import()` and `import.meta.filename`.
253
255
  ::code-group
254
256
 
255
257
  ```js [Before]
256
- import { join } from 'path'
258
+ const { join } = require('node:path')
257
259
 
258
260
  const newDir = join(__dirname, 'new-dir')
259
261
  ```
@@ -282,7 +284,7 @@ const someFile = await resolvePath('my-lib', { url: import.meta.url })
282
284
 
283
285
  ### Best Practices
284
286
 
285
- - Prefer named exports rather than default export. This helps reduce CJS conflicts. (see [Default exports](#default-exports) section)
287
+ - Prefer named exports rather than default export. This helps reduce CJS conflicts. (see [Default exports](/docs/4.x/guide/concepts/esm#default-exports) section)
286
288
 
287
289
  - Avoid depending on Node.js built-ins and CommonJS or Node.js-only dependencies as much as possible to make your library usable in Browsers and Edge Workers without needing Nitro polyfills.
288
290