@nuxt/docs 0.0.0 → 3.17.0

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 (224) hide show
  1. package/.navigation.yml +2 -0
  2. package/1.getting-started/.navigation.yml +3 -0
  3. package/1.getting-started/01.introduction.md +81 -0
  4. package/1.getting-started/02.installation.md +109 -0
  5. package/1.getting-started/03.configuration.md +226 -0
  6. package/1.getting-started/04.views.md +163 -0
  7. package/1.getting-started/05.assets.md +48 -0
  8. package/1.getting-started/06.styling.md +565 -0
  9. package/1.getting-started/07.routing.md +149 -0
  10. package/1.getting-started/08.seo-meta.md +360 -0
  11. package/1.getting-started/09.transitions.md +473 -0
  12. package/1.getting-started/10.data-fetching.md +795 -0
  13. package/1.getting-started/11.state-management.md +223 -0
  14. package/1.getting-started/12.error-handling.md +233 -0
  15. package/1.getting-started/13.server.md +94 -0
  16. package/1.getting-started/14.layers.md +92 -0
  17. package/1.getting-started/15.prerendering.md +194 -0
  18. package/1.getting-started/16.deployment.md +130 -0
  19. package/1.getting-started/17.testing.md +728 -0
  20. package/1.getting-started/18.upgrade.md +997 -0
  21. package/2.guide/.navigation.yml +2 -0
  22. package/2.guide/0.index.md +22 -0
  23. package/2.guide/1.concepts/.navigation.yml +3 -0
  24. package/2.guide/1.concepts/1.auto-imports.md +205 -0
  25. package/2.guide/1.concepts/10.nuxt-lifecycle.md +141 -0
  26. package/2.guide/1.concepts/2.vuejs-development.md +103 -0
  27. package/2.guide/1.concepts/3.rendering.md +255 -0
  28. package/2.guide/1.concepts/4.server-engine.md +62 -0
  29. package/2.guide/1.concepts/5.modules.md +48 -0
  30. package/2.guide/1.concepts/7.esm.md +299 -0
  31. package/2.guide/1.concepts/8.typescript.md +97 -0
  32. package/2.guide/1.concepts/9.code-style.md +22 -0
  33. package/2.guide/2.directory-structure/.navigation.yml +3 -0
  34. package/2.guide/2.directory-structure/0.nuxt.md +20 -0
  35. package/2.guide/2.directory-structure/0.output.md +18 -0
  36. package/2.guide/2.directory-structure/1.assets.md +16 -0
  37. package/2.guide/2.directory-structure/1.components.md +608 -0
  38. package/2.guide/2.directory-structure/1.composables.md +121 -0
  39. package/2.guide/2.directory-structure/1.content.md +64 -0
  40. package/2.guide/2.directory-structure/1.layouts.md +180 -0
  41. package/2.guide/2.directory-structure/1.middleware.md +209 -0
  42. package/2.guide/2.directory-structure/1.modules.md +66 -0
  43. package/2.guide/2.directory-structure/1.node_modules.md +12 -0
  44. package/2.guide/2.directory-structure/1.pages.md +440 -0
  45. package/2.guide/2.directory-structure/1.plugins.md +299 -0
  46. package/2.guide/2.directory-structure/1.public.md +27 -0
  47. package/2.guide/2.directory-structure/1.server.md +546 -0
  48. package/2.guide/2.directory-structure/1.shared.md +104 -0
  49. package/2.guide/2.directory-structure/1.utils.md +49 -0
  50. package/2.guide/2.directory-structure/2.env.md +75 -0
  51. package/2.guide/2.directory-structure/2.gitignore.md +37 -0
  52. package/2.guide/2.directory-structure/2.nuxtignore.md +36 -0
  53. package/2.guide/2.directory-structure/2.nuxtrc.md +50 -0
  54. package/2.guide/2.directory-structure/3.app-config.md +177 -0
  55. package/2.guide/2.directory-structure/3.app.md +72 -0
  56. package/2.guide/2.directory-structure/3.error.md +55 -0
  57. package/2.guide/2.directory-structure/3.nuxt-config.md +34 -0
  58. package/2.guide/2.directory-structure/3.package.md +32 -0
  59. package/2.guide/2.directory-structure/3.tsconfig.md +24 -0
  60. package/2.guide/3.going-further/.navigation.yml +3 -0
  61. package/2.guide/3.going-further/1.experimental-features.md +689 -0
  62. package/2.guide/3.going-further/1.features.md +103 -0
  63. package/2.guide/3.going-further/1.internals.md +81 -0
  64. package/2.guide/3.going-further/10.runtime-config.md +174 -0
  65. package/2.guide/3.going-further/11.nightly-release-channel.md +68 -0
  66. package/2.guide/3.going-further/2.hooks.md +98 -0
  67. package/2.guide/3.going-further/3.modules.md +811 -0
  68. package/2.guide/3.going-further/4.kit.md +51 -0
  69. package/2.guide/3.going-further/6.nuxt-app.md +64 -0
  70. package/2.guide/3.going-further/7.layers.md +227 -0
  71. package/2.guide/3.going-further/9.debugging.md +115 -0
  72. package/2.guide/3.going-further/index.md +4 -0
  73. package/2.guide/4.recipes/.navigation.yml +3 -0
  74. package/2.guide/4.recipes/1.custom-routing.md +181 -0
  75. package/2.guide/4.recipes/2.vite-plugin.md +65 -0
  76. package/2.guide/4.recipes/3.custom-usefetch.md +125 -0
  77. package/2.guide/4.recipes/4.sessions-and-authentication.md +203 -0
  78. package/3.api/.navigation.yml +3 -0
  79. package/3.api/1.components/.navigation.yml +3 -0
  80. package/3.api/1.components/1.client-only.md +76 -0
  81. package/3.api/1.components/1.dev-only.md +51 -0
  82. package/3.api/1.components/1.nuxt-client-fallback.md +80 -0
  83. package/3.api/1.components/10.nuxt-picture.md +27 -0
  84. package/3.api/1.components/11.teleports.md +40 -0
  85. package/3.api/1.components/12.nuxt-route-announcer.md +56 -0
  86. package/3.api/1.components/13.nuxt-time.md +173 -0
  87. package/3.api/1.components/2.nuxt-page.md +154 -0
  88. package/3.api/1.components/3.nuxt-layout.md +156 -0
  89. package/3.api/1.components/4.nuxt-link.md +322 -0
  90. package/3.api/1.components/5.nuxt-loading-indicator.md +50 -0
  91. package/3.api/1.components/6.nuxt-error-boundary.md +65 -0
  92. package/3.api/1.components/7.nuxt-welcome.md +25 -0
  93. package/3.api/1.components/8.nuxt-island.md +70 -0
  94. package/3.api/1.components/9.nuxt-img.md +43 -0
  95. package/3.api/2.composables/.navigation.yml +3 -0
  96. package/3.api/2.composables/on-prehydrate.md +60 -0
  97. package/3.api/2.composables/use-app-config.md +19 -0
  98. package/3.api/2.composables/use-async-data.md +212 -0
  99. package/3.api/2.composables/use-cookie.md +233 -0
  100. package/3.api/2.composables/use-error.md +32 -0
  101. package/3.api/2.composables/use-fetch.md +217 -0
  102. package/3.api/2.composables/use-head-safe.md +55 -0
  103. package/3.api/2.composables/use-head.md +69 -0
  104. package/3.api/2.composables/use-hydration.md +68 -0
  105. package/3.api/2.composables/use-lazy-async-data.md +47 -0
  106. package/3.api/2.composables/use-lazy-fetch.md +55 -0
  107. package/3.api/2.composables/use-loading-indicator.md +77 -0
  108. package/3.api/2.composables/use-nuxt-app.md +294 -0
  109. package/3.api/2.composables/use-nuxt-data.md +112 -0
  110. package/3.api/2.composables/use-preview-mode.md +118 -0
  111. package/3.api/2.composables/use-request-event.md +23 -0
  112. package/3.api/2.composables/use-request-fetch.md +52 -0
  113. package/3.api/2.composables/use-request-header.md +34 -0
  114. package/3.api/2.composables/use-request-headers.md +37 -0
  115. package/3.api/2.composables/use-request-url.md +41 -0
  116. package/3.api/2.composables/use-response-header.md +48 -0
  117. package/3.api/2.composables/use-route-announcer.md +60 -0
  118. package/3.api/2.composables/use-route.md +52 -0
  119. package/3.api/2.composables/use-router.md +92 -0
  120. package/3.api/2.composables/use-runtime-config.md +142 -0
  121. package/3.api/2.composables/use-runtime-hook.md +43 -0
  122. package/3.api/2.composables/use-seo-meta.md +80 -0
  123. package/3.api/2.composables/use-server-seo-meta.md +27 -0
  124. package/3.api/2.composables/use-state.md +48 -0
  125. package/3.api/3.utils/$fetch.md +98 -0
  126. package/3.api/3.utils/.navigation.yml +3 -0
  127. package/3.api/3.utils/abort-navigation.md +73 -0
  128. package/3.api/3.utils/add-route-middleware.md +88 -0
  129. package/3.api/3.utils/call-once.md +92 -0
  130. package/3.api/3.utils/clear-error.md +29 -0
  131. package/3.api/3.utils/clear-nuxt-data.md +23 -0
  132. package/3.api/3.utils/clear-nuxt-state.md +23 -0
  133. package/3.api/3.utils/create-error.md +55 -0
  134. package/3.api/3.utils/define-nuxt-component.md +53 -0
  135. package/3.api/3.utils/define-nuxt-route-middleware.md +67 -0
  136. package/3.api/3.utils/define-page-meta.md +234 -0
  137. package/3.api/3.utils/define-route-rules.md +52 -0
  138. package/3.api/3.utils/navigate-to.md +230 -0
  139. package/3.api/3.utils/on-before-route-leave.md +11 -0
  140. package/3.api/3.utils/on-before-route-update.md +11 -0
  141. package/3.api/3.utils/on-nuxt-ready.md +25 -0
  142. package/3.api/3.utils/prefetch-components.md +28 -0
  143. package/3.api/3.utils/preload-components.md +23 -0
  144. package/3.api/3.utils/preload-route-components.md +41 -0
  145. package/3.api/3.utils/prerender-routes.md +46 -0
  146. package/3.api/3.utils/refresh-cookie.md +46 -0
  147. package/3.api/3.utils/refresh-nuxt-data.md +91 -0
  148. package/3.api/3.utils/reload-nuxt-app.md +74 -0
  149. package/3.api/3.utils/set-page-layout.md +24 -0
  150. package/3.api/3.utils/set-response-status.md +36 -0
  151. package/3.api/3.utils/show-error.md +31 -0
  152. package/3.api/3.utils/update-app-config.md +27 -0
  153. package/3.api/4.commands/.navigation.yml +3 -0
  154. package/3.api/4.commands/add.md +112 -0
  155. package/3.api/4.commands/analyze.md +41 -0
  156. package/3.api/4.commands/build-module.md +42 -0
  157. package/3.api/4.commands/build.md +46 -0
  158. package/3.api/4.commands/cleanup.md +38 -0
  159. package/3.api/4.commands/dev.md +59 -0
  160. package/3.api/4.commands/devtools.md +38 -0
  161. package/3.api/4.commands/generate.md +41 -0
  162. package/3.api/4.commands/info.md +33 -0
  163. package/3.api/4.commands/init.md +46 -0
  164. package/3.api/4.commands/module.md +84 -0
  165. package/3.api/4.commands/prepare.md +36 -0
  166. package/3.api/4.commands/preview.md +43 -0
  167. package/3.api/4.commands/typecheck.md +42 -0
  168. package/3.api/4.commands/upgrade.md +37 -0
  169. package/3.api/5.kit/.navigation.yml +3 -0
  170. package/3.api/5.kit/1.modules.md +172 -0
  171. package/3.api/5.kit/10.runtime-config.md +27 -0
  172. package/3.api/5.kit/10.templates.md +283 -0
  173. package/3.api/5.kit/11.nitro.md +409 -0
  174. package/3.api/5.kit/12.resolving.md +268 -0
  175. package/3.api/5.kit/13.logging.md +65 -0
  176. package/3.api/5.kit/14.builder.md +491 -0
  177. package/3.api/5.kit/15.examples.md +41 -0
  178. package/3.api/5.kit/2.programmatic.md +125 -0
  179. package/3.api/5.kit/3.compatibility.md +230 -0
  180. package/3.api/5.kit/4.autoimports.md +144 -0
  181. package/3.api/5.kit/5.components.md +127 -0
  182. package/3.api/5.kit/6.context.md +130 -0
  183. package/3.api/5.kit/7.pages.md +295 -0
  184. package/3.api/5.kit/8.layout.md +80 -0
  185. package/3.api/5.kit/9.plugins.md +263 -0
  186. package/3.api/6.advanced/.navigation.yml +1 -0
  187. package/3.api/6.advanced/1.hooks.md +105 -0
  188. package/3.api/6.advanced/2.import-meta.md +60 -0
  189. package/3.api/6.nuxt-config.md +12 -0
  190. package/3.api/index.md +31 -0
  191. package/5.community/.navigation.yml +3 -0
  192. package/5.community/2.getting-help.md +48 -0
  193. package/5.community/3.reporting-bugs.md +50 -0
  194. package/5.community/4.contribution.md +205 -0
  195. package/5.community/5.framework-contribution.md +142 -0
  196. package/5.community/6.roadmap.md +79 -0
  197. package/5.community/7.changelog.md +92 -0
  198. package/6.bridge/.navigation.yml +3 -0
  199. package/6.bridge/1.overview.md +137 -0
  200. package/6.bridge/10.configuration.md +96 -0
  201. package/6.bridge/2.typescript.md +46 -0
  202. package/6.bridge/3.bridge-composition-api.md +132 -0
  203. package/6.bridge/4.plugins-and-middleware.md +65 -0
  204. package/6.bridge/5.nuxt3-compatible-api.md +204 -0
  205. package/6.bridge/6.meta.md +117 -0
  206. package/6.bridge/7.runtime-config.md +38 -0
  207. package/6.bridge/8.nitro.md +102 -0
  208. package/6.bridge/9.vite.md +37 -0
  209. package/7.migration/.navigation.yml +3 -0
  210. package/7.migration/1.overview.md +24 -0
  211. package/7.migration/10.bundling.md +28 -0
  212. package/7.migration/11.server.md +17 -0
  213. package/7.migration/2.configuration.md +240 -0
  214. package/7.migration/20.module-authors.md +94 -0
  215. package/7.migration/3.auto-imports.md +18 -0
  216. package/7.migration/4.meta.md +127 -0
  217. package/7.migration/5.plugins-and-middleware.md +80 -0
  218. package/7.migration/6.pages-and-layouts.md +233 -0
  219. package/7.migration/7.component-options.md +156 -0
  220. package/7.migration/8.runtime-config.md +58 -0
  221. package/LICENSE +21 -0
  222. package/README.md +11 -0
  223. package/package.json +16 -4
  224. package/dist/.gitkeep +0 -0
@@ -0,0 +1,51 @@
1
+ ---
2
+ title: "Nuxt Kit"
3
+ description: "@nuxt/kit provides features for module authors."
4
+ ---
5
+
6
+ Nuxt Kit provides composable utilities to make interacting with [Nuxt Hooks](/docs/api/advanced/hooks), the [Nuxt Interface](/docs/guide/going-further/internals#the-nuxt-interface) and developing [Nuxt Modules](/docs/guide/going-further/modules) super easy.
7
+
8
+ ::read-more{to="/docs/api/kit"}
9
+ Discover all Nuxt Kit utilities.
10
+ ::
11
+
12
+ ## Usage
13
+
14
+ ### Install Dependency
15
+
16
+ You can install the latest Nuxt Kit by adding it to the `dependencies` section of your `package.json`. However, please consider always explicitly installing the `@nuxt/kit` package even if it is already installed by Nuxt.
17
+
18
+ ::note
19
+ `@nuxt/kit` and `@nuxt/schema` are key dependencies for Nuxt. If you are installing it separately, make sure that the versions of `@nuxt/kit` and `@nuxt/schema` are equal to or greater than your `nuxt` version to avoid any unexpected behavior.
20
+ ::
21
+
22
+ ```json [package.json]
23
+ {
24
+ "dependencies": {
25
+ "@nuxt/kit": "npm:@nuxt/kit-nightly@latest"
26
+ }
27
+ }
28
+ ```
29
+
30
+ ### Import Kit Utilities
31
+
32
+ ```js [test.mjs]
33
+ import { useNuxt } from '@nuxt/kit'
34
+ ```
35
+
36
+ :read-more{to="/docs/api/kit"}
37
+
38
+ ::note
39
+ Nuxt Kit utilities are only available for modules and not meant to be imported in runtime (components, Vue composables, pages, plugins, or server routes).
40
+ ::
41
+
42
+ Nuxt Kit is an [esm-only package](/docs/guide/concepts/esm) meaning that you **cannot** `require('@nuxt/kit')`. As a workaround, use dynamic import in the CommonJS context:
43
+
44
+ ```js [test.cjs]
45
+ // This does NOT work!
46
+ // const kit = require('@nuxt/kit')
47
+ async function main() {
48
+ const kit = await import('@nuxt/kit')
49
+ }
50
+ main()
51
+ ```
@@ -0,0 +1,64 @@
1
+ ---
2
+ title: "NuxtApp"
3
+ description: "In Nuxt, you can access runtime app context within composables, components and plugins."
4
+ links:
5
+ - label: Source
6
+ icon: i-simple-icons-github
7
+ to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/nuxt.ts
8
+ ---
9
+
10
+ In Nuxt, you can access runtime app context within composables, components and plugins.
11
+
12
+ ::read-more{to="https://v2.nuxt.com/docs/internals-glossary/context#the-context" target="_blank"}
13
+ In Nuxt 2, this was referred to as **Nuxt context**.
14
+ ::
15
+
16
+ ## Nuxt App Interface
17
+
18
+ ::read-more{to="/docs/guide/going-further/internals#the-nuxtapp-interface"}
19
+ Jump over the `NuxtApp` interface documentation.
20
+ ::
21
+
22
+ ## The Nuxt Context
23
+
24
+ Many composables and utilities, both built-in and user-made, may require access to the Nuxt instance. This doesn't exist everywhere on your application, because a fresh instance is created on every request.
25
+
26
+ Currently, the Nuxt context is only accessible in [plugins](/docs/guide/directory-structure/plugins), [Nuxt hooks](/docs/guide/going-further/hooks), [Nuxt middleware](/docs/guide/directory-structure/middleware) (if wrapped in `defineNuxtRouteMiddleware`), and [setup functions](https://vuejs.org/api/composition-api-setup.html) (in pages and components).
27
+
28
+ If a composable is called without access to the context, you may get an error stating that 'A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function.' In that case, you can also explicitly call functions within this context by using [`nuxtApp.runWithContext`](/docs/api/composables/use-nuxt-app#runwithcontext).
29
+
30
+ ## Accessing NuxtApp
31
+
32
+ Within composables, plugins and components you can access `nuxtApp` with [`useNuxtApp()`](/docs/api/composables/use-nuxt-app):
33
+
34
+ ```ts [composables/useMyComposable.ts]
35
+ export function useMyComposable () {
36
+ const nuxtApp = useNuxtApp()
37
+ // access runtime nuxt app instance
38
+ }
39
+ ```
40
+
41
+ If your composable does not always need `nuxtApp` or you simply want to check if it is present or not, since [`useNuxtApp`](/docs/api/composables/use-nuxt-app) throws an exception, you can use [`tryUseNuxtApp`](/docs/api/composables/use-nuxt-app#tryusenuxtapp) instead.
42
+
43
+ Plugins also receive `nuxtApp` as the first argument for convenience.
44
+
45
+ :read-more{to="/docs/guide/directory-structure/plugins"}
46
+
47
+ ## Providing Helpers
48
+
49
+ You can provide helpers to be usable across all composables and application. This usually happens within a Nuxt plugin.
50
+
51
+ ```ts
52
+ const nuxtApp = useNuxtApp()
53
+ nuxtApp.provide('hello', (name) => `Hello ${name}!`)
54
+
55
+ console.log(nuxtApp.$hello('name')) // Prints "Hello name!"
56
+ ```
57
+
58
+ ::read-more{to="/docs/guide/directory-structure/plugins#providing-helpers"}
59
+ It is possible to inject helpers by returning an object with a `provide` key in plugins.
60
+ ::
61
+
62
+ ::read-more{to="https://v2.nuxt.com/docs/directory-structure/plugins#inject-in-root--context" target="_blank"}
63
+ In Nuxt 2 plugins, this was referred to as **inject function**.
64
+ ::
@@ -0,0 +1,227 @@
1
+ ---
2
+ title: Authoring Nuxt Layers
3
+ description: Nuxt provides a powerful system that allows you to extend the default files, configs, and much more.
4
+ ---
5
+
6
+ Nuxt layers are a powerful feature that you can use to share and reuse partial Nuxt applications within a monorepo, or from a git repository or npm package. The layers structure is almost identical to a standard Nuxt application, which makes them easy to author and maintain.
7
+
8
+ :read-more{to="/docs/getting-started/layers"}
9
+
10
+ A minimal Nuxt layer directory should contain a [`nuxt.config.ts`](/docs/guide/directory-structure/nuxt-config) file to indicate it is a layer.
11
+
12
+ ```ts [base/nuxt.config.ts]
13
+ export default defineNuxtConfig({})
14
+ ```
15
+
16
+ Additionally, certain other files in the layer directory will be auto-scanned and used by Nuxt for the project extending this layer.
17
+
18
+ - [`components/*`](/docs/guide/directory-structure/components) - Extend the default components
19
+ - [`composables/*`](/docs/guide/directory-structure/composables) - Extend the default composables
20
+ - [`layouts/*`](/docs/guide/directory-structure/layouts) - Extend the default layouts
21
+ - [`pages/*`](/docs/guide/directory-structure/pages) - Extend the default pages
22
+ - [`plugins/*`](/docs/guide/directory-structure/plugins) - Extend the default plugins
23
+ - [`server/*`](/docs/guide/directory-structure/server) - Extend the default server endpoints & middleware
24
+ - [`utils/*`](/docs/guide/directory-structure/utils) - Extend the default utils
25
+ - [`nuxt.config.ts`](/docs/guide/directory-structure/nuxt-config)- Extend the default nuxt config
26
+ - [`app.config.ts`](/docs/guide/directory-structure/app-config) - Extend the default app config
27
+
28
+ ## Basic Example
29
+
30
+ ::code-group
31
+
32
+ ```ts [nuxt.config.ts]
33
+ export default defineNuxtConfig({
34
+ extends: [
35
+ './base'
36
+ ]
37
+ })
38
+ ```
39
+
40
+ ```vue [app.vue]
41
+ <template>
42
+ <BaseComponent/>
43
+ </template>
44
+ ```
45
+
46
+ ```ts [base/nuxt.config.ts]
47
+ export default defineNuxtConfig({
48
+ // Extending from base nuxt.config.ts!
49
+ app: {
50
+ head: {
51
+ title: 'Extending Configs is Fun!',
52
+ meta: [
53
+ { name: 'description', content: 'I am using the extends feature in Nuxt!' }
54
+ ],
55
+ }
56
+ }
57
+ })
58
+ ```
59
+
60
+ ```vue [base/components/BaseComponent.vue]
61
+ <template>
62
+ <h1>Extending Components is Fun!</h1>
63
+ </template>
64
+ ```
65
+
66
+ ::
67
+
68
+ ## Starter Template
69
+
70
+ To get started you can initialize a layer with the [nuxt/starter/layer template](https://github.com/nuxt/starter/tree/layer). This will create a basic structure you can build upon. Execute this command within the terminal to get started:
71
+
72
+ ```bash [Terminal]
73
+ npm create nuxt -- --template layer nuxt-layer
74
+ ```
75
+
76
+ Follow up on the README instructions for the next steps.
77
+
78
+ ## Publishing Layers
79
+
80
+ You can publish and share layers by either using a remote source or an npm package.
81
+
82
+ ### Git Repository
83
+
84
+ You can use a git repository to share your Nuxt layer. Some examples:
85
+
86
+ ```ts [nuxt.config.ts]
87
+ export default defineNuxtConfig({
88
+ extends: [
89
+ 'github:username/repoName', // GitHub Remote Source
90
+ 'github:username/repoName/base', // GitHub Remote Source within /base directory
91
+ 'github:username/repoName#dev', // GitHub Remote Source from dev branch
92
+ 'github:username/repoName#v1.0.0', // GitHub Remote Source from v1.0.0 tag
93
+ 'gitlab:username/repoName', // GitLab Remote Source example
94
+ 'bitbucket:username/repoName', // Bitbucket Remote Source example
95
+ ]
96
+ })
97
+ ```
98
+
99
+ ::tip
100
+ If you want to extend a private remote source, you need to add the environment variable `GIGET_AUTH=<token>` to provide a token.
101
+ ::
102
+
103
+ ::tip
104
+ If you want to extend a remote source from a self-hosted GitHub or GitLab instance, you need to supply its URL with the `GIGET_GITHUB_URL=<url>` or `GIGET_GITLAB_URL=<url>` environment variable - or directly configure it with [the `auth` option](https://github.com/unjs/c12#extending-config-layer-from-remote-sources) in your `nuxt.config`.
105
+ ::
106
+
107
+ ::warning
108
+ Bear in mind that if you are extending a remote source as a layer, you will not be able to access its dependencies outside of Nuxt. For example, if the remote layer depends on an eslint plugin, this will not be usable in your eslint config. That is because these dependencies will be located in a special location (`node_modules/.c12/layer_name/node_modules/`) that is not accessible to your package manager.
109
+ ::
110
+
111
+ ::note
112
+ When using git remote sources, if a layer has npm dependencies and you wish to install them, you can do so by specifying `install: true` in your layer options.
113
+
114
+ ```ts [nuxt.config.ts]
115
+ export default defineNuxtConfig({
116
+ extends: [
117
+ ['github:username/repoName', { install: true }]
118
+ ]
119
+ })
120
+ ```
121
+ ::
122
+
123
+ ### npm Package
124
+
125
+ You can publish Nuxt layers as an npm package that contains the files and dependencies you want to extend. This allows you to share your config with others, use it in multiple projects or use it privately.
126
+
127
+ To extend from an npm package, you need to make sure that the module is published to npm and installed in the user's project as a devDependency. Then you can use the module name to extend the current nuxt config:
128
+
129
+ ```ts [nuxt.config.ts]
130
+ export default defineNuxtConfig({
131
+ extends: [
132
+ // Node Module with scope
133
+ '@scope/moduleName',
134
+ // or just the module name
135
+ 'moduleName'
136
+ ]
137
+ })
138
+ ```
139
+
140
+ To publish a layer directory as an npm package, you want to make sure that the `package.json` has the correct properties filled out. This will make sure that the files are included when the package is published.
141
+
142
+ ```json [package.json]
143
+ {
144
+ "name": "my-theme",
145
+ "version": "1.0.0",
146
+ "type": "module",
147
+ "main": "./nuxt.config.ts",
148
+ "dependencies": {},
149
+ "devDependencies": {
150
+ "nuxt": "^3.0.0"
151
+ }
152
+ }
153
+ ```
154
+
155
+ ::important
156
+ Make sure any dependency imported in the layer is **explicitly added** to the `dependencies`. The `nuxt` dependency, and anything only used for testing the layer before publishing, should remain in the `devDependencies` field.
157
+ ::
158
+
159
+ Now you can proceed to publish the module to npm, either publicly or privately.
160
+
161
+ ::important
162
+ When publishing the layer as a private npm package, you need to make sure you log in, to authenticate with npm to download the node module.
163
+ ::
164
+
165
+ ## Tips
166
+
167
+ ### Named Layer Aliases
168
+
169
+ Auto-scanned layers (from your `~~/layers` directory) automatically create aliases. For example, you can access your `~~/layers/test` layer via `#layers/test`.
170
+
171
+ If you want to create named layer aliases for other layers, you can specify a name in the configuration of the layer.
172
+
173
+ ```ts [nuxt.config.ts]
174
+ export default defineNuxtConfig({
175
+ $meta: {
176
+ name: 'example',
177
+ },
178
+ })
179
+ ```
180
+
181
+ This will produce an alias of `#layers/example` which points to your layer.
182
+
183
+ ### Relative Paths and Aliases
184
+
185
+ When importing using global aliases (such as `~/` and `@/`) in a layer components and composables, note that these aliases are resolved relative to the user's project paths. As a workaround, you can **use relative paths** to import them, or use named layer aliases.
186
+
187
+ Also when using relative paths in `nuxt.config` file of a layer, (with exception of nested `extends`) they are resolved relative to user's project instead of the layer. As a workaround, use full resolved paths in `nuxt.config`:
188
+
189
+ ```js [nuxt.config.ts]
190
+ import { fileURLToPath } from 'url'
191
+ import { dirname, join } from 'path'
192
+
193
+ const currentDir = dirname(fileURLToPath(import.meta.url))
194
+
195
+ export default defineNuxtConfig({
196
+ css: [
197
+ join(currentDir, './assets/main.css')
198
+ ]
199
+ })
200
+ ```
201
+
202
+ ## Multi-Layer Support for Nuxt Modules
203
+
204
+ You can use the internal array `nuxt.options._layers` to support custom multi-layer handling for your modules.
205
+
206
+ ```ts [modules/my-module.ts]
207
+ export default defineNuxtModule({
208
+ setup(_options, nuxt) {
209
+ for (const layer of nuxt.options._layers) {
210
+ // You can check for a custom directory existence to extend for each layer
211
+ console.log('Custom extension for', layer.cwd, layer.config)
212
+ }
213
+ }
214
+ })
215
+ ```
216
+
217
+ **Notes:**
218
+ - Earlier items in the `_layers` array have higher priority and override later ones
219
+ - The user's project is the first item in the `_layers` array
220
+
221
+ ## Going Deeper
222
+
223
+ Configuration loading and extends support is handled by [unjs/c12](https://github.com/unjs/c12), merged using [unjs/defu](https://github.com/unjs/defu) and remote git sources are supported using [unjs/giget](https://github.com/unjs/giget). Check the docs and source code to learn more.
224
+
225
+ ::read-more{icon="i-simple-icons-github" to="https://github.com/nuxt/nuxt/issues/13367" target="_blank"}
226
+ Checkout our ongoing development to bring more improvements for layers support on GitHub.
227
+ ::
@@ -0,0 +1,115 @@
1
+ ---
2
+ title: "Debugging"
3
+ description: "In Nuxt, you can get started with debugging your application directly in the browser as well as in your IDE."
4
+ ---
5
+
6
+ ## Sourcemaps
7
+
8
+ Sourcemaps are enabled for your server build by default, and for the client build in dev mode, but you can enable them more specifically in your configuration.
9
+
10
+ ```ts
11
+ export default defineNuxtConfig({
12
+ // or sourcemap: true
13
+ sourcemap: {
14
+ server: true,
15
+ client: true
16
+ }
17
+ })
18
+ ```
19
+
20
+ ## Debugging with Node Inspector
21
+
22
+ You can use [Node inspector](https://nodejs.org/en/learn/getting-started/debugging) to debug Nuxt server-side.
23
+
24
+ ```bash
25
+ nuxi dev --inspect
26
+ ```
27
+ This will start Nuxt in `dev` mode with debugger active. If everything is working correctly a Node.js icon will appear on your Chrome DevTools and you can attach to the debugger.
28
+
29
+ ::important
30
+ Note that the Node.js and Chrome processes need to be run on the same platform. This doesn't work inside of Docker.
31
+ ::
32
+
33
+ ## Debugging in Your IDE
34
+
35
+ It is possible to debug your Nuxt app in your IDE while you are developing it.
36
+
37
+ ### Example VS Code Debug Configuration
38
+
39
+ You may need to update the config below with a path to your web browser. For more information, visit the [VS Code documentation about debug configuration](https://go.microsoft.com/fwlink/?linkid=830387).
40
+
41
+ ::important
42
+ If you use `pnpm`, you will need to have `nuxi` installed as a devDependency for the configuration below to work.
43
+ ::
44
+
45
+ ```json5
46
+ {
47
+ // Use IntelliSense to learn about possible attributes.
48
+ // Hover to view descriptions of existing attributes.
49
+ "version": "0.2.0",
50
+ "configurations": [
51
+ {
52
+ "type": "chrome",
53
+ "request": "launch",
54
+ "name": "client: chrome",
55
+ "url": "http://localhost:3000",
56
+ "webRoot": "${workspaceFolder}"
57
+ },
58
+ {
59
+ "type": "node",
60
+ "request": "launch",
61
+ "name": "server: nuxt",
62
+ "outputCapture": "std",
63
+ "program": "${workspaceFolder}/node_modules/nuxt/bin/nuxt.mjs",
64
+ "args": [
65
+ "dev"
66
+ ],
67
+ }
68
+ ],
69
+ "compounds": [
70
+ {
71
+ "name": "fullstack: nuxt",
72
+ "configurations": [
73
+ "server: nuxt",
74
+ "client: chrome"
75
+ ]
76
+ }
77
+ ]
78
+ }
79
+ ```
80
+
81
+ If you prefer your usual browser extensions, add this to the _chrome_ configuration above:
82
+
83
+ ```json5
84
+ "userDataDir": false,
85
+ ```
86
+
87
+ ### Example JetBrains IDEs Debug Configuration
88
+
89
+ You can also debug your Nuxt app in JetBrains IDEs such as IntelliJ IDEA, WebStorm, or PhpStorm.
90
+
91
+ 1. Create a new file in your project root directory and name it `nuxt.run.xml`.
92
+
93
+ 2. Open the `nuxt.run.xml` file and paste the following debug configuration:
94
+
95
+ ```html
96
+ <component name="ProjectRunConfigurationManager">
97
+ <configuration default="false" name="client: chrome" type="JavascriptDebugType" uri="http://localhost:3000" useFirstLineBreakpoints="true">
98
+ <method v="2" />
99
+ </configuration>
100
+
101
+ <configuration default="false" name="server: nuxt" type="NodeJSConfigurationType" application-parameters="dev" path-to-js-file="$PROJECT_DIR$/node_modules/nuxt/bin/nuxt.mjs" working-dir="$PROJECT_DIR$">
102
+ <method v="2" />
103
+ </configuration>
104
+
105
+ <configuration default="false" name="fullstack: nuxt" type="CompoundRunConfigurationType">
106
+ <toRun name="client: chrome" type="JavascriptDebugType" />
107
+ <toRun name="server: nuxt" type="NodeJSConfigurationType" />
108
+ <method v="2" />
109
+ </configuration>
110
+ </component>
111
+ ```
112
+
113
+ ### Other IDEs
114
+
115
+ If you have another IDE and would like to contribute sample configuration, feel free to [open a PR](https://github.com/nuxt/nuxt/edit/main/docs/2.guide/3.going-further/9.debugging.md)!
@@ -0,0 +1,4 @@
1
+ ---
2
+ navigation: false
3
+ redirect: /guide/going-further/tooling
4
+ ---
@@ -0,0 +1,3 @@
1
+ title: Recipes
2
+ titleTemplate: '%s · Recipes'
3
+ icon: i-lucide-cooking-pot
@@ -0,0 +1,181 @@
1
+ ---
2
+ title: "Custom Routing"
3
+ description: "In Nuxt, your routing is defined by the structure of your files inside the pages directory. However, since it uses vue-router under the hood, Nuxt offers you several ways to add custom routes in your project."
4
+ ---
5
+
6
+ ## Adding custom routes
7
+
8
+ In Nuxt, your routing is defined by the structure of your files inside the [pages directory](/docs/guide/directory-structure/pages). However, since it uses [vue-router](https://router.vuejs.org) under the hood, Nuxt offers you several ways to add custom routes in your project.
9
+
10
+ ### Router Config
11
+
12
+ Using [router options](/docs/guide/recipes/custom-routing#router-options), you can optionally override or extend your routes using a function that accepts the scanned routes and returns customized routes.
13
+
14
+ If it returns `null` or `undefined`, Nuxt will fall back to the default routes (useful to modify input array).
15
+
16
+ ```ts [app/router.options.ts]
17
+ import type { RouterConfig } from '@nuxt/schema'
18
+
19
+ export default {
20
+ // https://router.vuejs.org/api/interfaces/routeroptions.html#routes
21
+ routes: (_routes) => [
22
+ {
23
+ name: 'home',
24
+ path: '/',
25
+ component: () => import('~/pages/home.vue')
26
+ }
27
+ ],
28
+ } satisfies RouterConfig
29
+ ```
30
+
31
+ ::note
32
+ Nuxt will not augment any new routes you return from the `routes` function with metadata defined in `definePageMeta` of the component you provide. If you want that to happen, you should use the `pages:extend` hook which is [called at build-time](/docs/api/advanced/hooks#nuxt-hooks-build-time).
33
+ ::
34
+
35
+ ### Pages Hook
36
+
37
+ You can add, change or remove pages from the scanned routes with the `pages:extend` nuxt hook.
38
+
39
+ For example, to prevent creating routes for any `.ts` files:
40
+
41
+ ```ts [nuxt.config.ts]
42
+ import type { NuxtPage } from '@nuxt/schema'
43
+
44
+ export default defineNuxtConfig({
45
+ hooks: {
46
+ 'pages:extend' (pages) {
47
+ // add a route
48
+ pages.push({
49
+ name: 'profile',
50
+ path: '/profile',
51
+ file: '~/extra-pages/profile.vue'
52
+ })
53
+
54
+ // remove routes
55
+ function removePagesMatching (pattern: RegExp, pages: NuxtPage[] = []) {
56
+ const pagesToRemove: NuxtPage[] = []
57
+ for (const page of pages) {
58
+ if (page.file && pattern.test(page.file)) {
59
+ pagesToRemove.push(page)
60
+ } else {
61
+ removePagesMatching(pattern, page.children)
62
+ }
63
+ }
64
+ for (const page of pagesToRemove) {
65
+ pages.splice(pages.indexOf(page), 1)
66
+ }
67
+ }
68
+ removePagesMatching(/\.ts$/, pages)
69
+ }
70
+ }
71
+ })
72
+ ```
73
+
74
+ ### Nuxt Module
75
+
76
+ If you plan to add a whole set of pages related with a specific functionality, you might want to use a [Nuxt module](/modules).
77
+
78
+ The [Nuxt kit](/docs/guide/going-further/kit) provides a few ways [to add routes](/docs/api/kit/pages):
79
+ - [`extendPages`](/docs/api/kit/pages#extendpages) (callback: pages => void)
80
+ - [`extendRouteRules`](/docs/api/kit/pages#extendrouterules) (route: string, rule: NitroRouteConfig, options: ExtendRouteRulesOptions)
81
+
82
+ ## Router Options
83
+
84
+ On top of customizing options for [`vue-router`](https://router.vuejs.org/api/interfaces/routeroptions.html), Nuxt offers [additional options](/docs/api/nuxt-config#router) to customize the router.
85
+
86
+ ### Using `app/router.options`
87
+
88
+ This is the recommended way to specify [router options](/docs/api/nuxt-config#router).
89
+
90
+ ```ts [app/router.options.ts]
91
+ import type { RouterConfig } from '@nuxt/schema'
92
+
93
+ export default {
94
+ } satisfies RouterConfig
95
+ ```
96
+
97
+ It is possible to add more router options files by adding files within the `pages:routerOptions` hook. Later items in the array override earlier ones.
98
+
99
+ ::callout
100
+ Adding a router options file in this hook will switch on page-based routing, unless `optional` is set, in which case it will only apply when page-based routing is already enabled.
101
+ ::
102
+
103
+ ```ts [nuxt.config.ts]
104
+ import { createResolver } from '@nuxt/kit'
105
+
106
+ export default defineNuxtConfig({
107
+ hooks: {
108
+ 'pages:routerOptions' ({ files }) {
109
+ const resolver = createResolver(import.meta.url)
110
+ // add a route
111
+ files.push({
112
+ path: resolver.resolve('./runtime/app/router-options'),
113
+ optional: true
114
+ })
115
+ }
116
+ }
117
+ })
118
+ ```
119
+
120
+ ### Using `nuxt.config`
121
+
122
+ **Note:** Only JSON serializable [options](/docs/api/nuxt-config#router) are configurable:
123
+
124
+ - `linkActiveClass`
125
+ - `linkExactActiveClass`
126
+ - `end`
127
+ - `sensitive`
128
+ - `strict`
129
+ - `hashMode`
130
+ - `scrollBehaviorType`
131
+
132
+ ```js [nuxt.config]
133
+ export default defineNuxtConfig({
134
+ router: {
135
+ options: {}
136
+ }
137
+ })
138
+ ```
139
+
140
+ ### Hash Mode (SPA)
141
+
142
+ You can enable hash history in SPA mode using the `hashMode` [config](/docs/api/nuxt-config#router). In this mode, router uses a hash character (#) before the actual URL that is internally passed. When enabled, the **URL is never sent to the server** and **SSR is not supported**.
143
+
144
+ ```ts [nuxt.config.ts]
145
+ export default defineNuxtConfig({
146
+ ssr: false,
147
+ router: {
148
+ options: {
149
+ hashMode: true
150
+ }
151
+ }
152
+ })
153
+ ```
154
+
155
+ ### Scroll Behavior for hash links
156
+
157
+ You can optionally customize the scroll behavior for hash links. When you set the [config](/docs/api/nuxt-config#router) to be `smooth` and you load a page with a hash link (e.g. `https://example.com/blog/my-article#comments`), you will see that the browser smoothly scrolls to this anchor.
158
+
159
+ ```ts [nuxt.config.ts]
160
+ export default defineNuxtConfig({
161
+ router: {
162
+ options: {
163
+ scrollBehaviorType: 'smooth'
164
+ }
165
+ }
166
+ })
167
+ ```
168
+
169
+ #### Custom History (advanced)
170
+
171
+ You can optionally override history mode using a function that accepts the base URL and returns the history mode. If it returns `null` or `undefined`, Nuxt will fallback to the default history.
172
+
173
+ ```ts [app/router.options.ts]
174
+ import type { RouterConfig } from '@nuxt/schema'
175
+ import { createMemoryHistory } from 'vue-router'
176
+
177
+ export default {
178
+ // https://router.vuejs.org/api/interfaces/routeroptions.html
179
+ history: base => import.meta.client ? createMemoryHistory(base) : null /* default */
180
+ } satisfies RouterConfig
181
+ ```