@nuxt/docs 4.2.1 → 4.3.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 (246) hide show
  1. package/1.getting-started/01.introduction.md +1 -1
  2. package/1.getting-started/02.installation.md +2 -5
  3. package/1.getting-started/03.configuration.md +27 -27
  4. package/1.getting-started/04.views.md +5 -5
  5. package/1.getting-started/05.assets.md +7 -7
  6. package/1.getting-started/06.styling.md +9 -5
  7. package/1.getting-started/07.routing.md +8 -8
  8. package/1.getting-started/08.seo-meta.md +7 -3
  9. package/1.getting-started/09.transitions.md +6 -6
  10. package/1.getting-started/10.data-fetching.md +2 -2
  11. package/1.getting-started/11.state-management.md +2 -2
  12. package/1.getting-started/12.error-handling.md +15 -9
  13. package/1.getting-started/13.server.md +2 -2
  14. package/1.getting-started/14.layers.md +50 -16
  15. package/1.getting-started/15.prerendering.md +6 -0
  16. package/1.getting-started/16.deployment.md +2 -1
  17. package/1.getting-started/17.testing.md +44 -3
  18. package/1.getting-started/18.upgrade.md +37 -24
  19. package/{2.guide/1.directory-structure → 2.directory-structure}/0.nuxt.md +1 -1
  20. package/{2.guide/1.directory-structure → 2.directory-structure}/0.output.md +1 -1
  21. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.assets.md +2 -2
  22. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.components.md +6 -2
  23. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.composables.md +2 -2
  24. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.layouts.md +35 -3
  25. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.middleware.md +1 -1
  26. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.pages.md +28 -7
  27. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.plugins.md +5 -2
  28. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.utils.md +3 -3
  29. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/3.app.md +4 -4
  30. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/3.error.md +10 -8
  31. package/{2.guide/1.directory-structure → 2.directory-structure}/1.content.md +2 -2
  32. package/2.directory-structure/1.layers.md +87 -0
  33. package/{2.guide/1.directory-structure → 2.directory-structure}/1.modules.md +13 -3
  34. package/{2.guide/1.directory-structure → 2.directory-structure}/1.node_modules.md +2 -2
  35. package/{2.guide/1.directory-structure → 2.directory-structure}/1.server.md +27 -7
  36. package/{2.guide/1.directory-structure → 2.directory-structure}/1.shared.md +3 -3
  37. package/{2.guide/1.directory-structure → 2.directory-structure}/2.env.md +2 -2
  38. package/{2.guide/1.directory-structure → 2.directory-structure}/2.nuxtignore.md +1 -1
  39. package/{2.guide/1.directory-structure → 2.directory-structure}/2.nuxtrc.md +4 -1
  40. package/{2.guide/1.directory-structure → 2.directory-structure}/3.nuxt-config.md +1 -1
  41. package/{2.guide/1.directory-structure → 2.directory-structure}/3.package.md +1 -1
  42. package/{2.guide/1.directory-structure → 2.directory-structure}/3.tsconfig.md +1 -0
  43. package/2.directory-structure/index.md +65 -0
  44. package/{2.guide → 3.guide}/0.index.md +10 -7
  45. package/{2.guide/2.concepts/3.rendering.md → 3.guide/1.concepts/1.rendering.md} +2 -27
  46. package/{2.guide/2.concepts/2.vuejs-development.md → 3.guide/1.concepts/10.vuejs-development.md} +4 -3
  47. package/{2.guide/2.concepts/10.nuxt-lifecycle.md → 3.guide/1.concepts/2.nuxt-lifecycle.md} +33 -26
  48. package/{2.guide/2.concepts/1.auto-imports.md → 3.guide/1.concepts/3.auto-imports.md} +5 -5
  49. package/{2.guide/2.concepts → 3.guide/1.concepts}/4.server-engine.md +3 -3
  50. package/{2.guide/2.concepts → 3.guide/1.concepts}/5.modules.md +15 -2
  51. package/{2.guide/2.concepts → 3.guide/1.concepts}/7.esm.md +1 -0
  52. package/{2.guide/2.concepts → 3.guide/1.concepts}/8.typescript.md +9 -5
  53. package/{2.guide/5.best-practices → 3.guide/2.best-practices}/performance.md +2 -2
  54. package/3.guide/3.ai/.navigation.yml +3 -0
  55. package/3.guide/3.ai/1.mcp.md +277 -0
  56. package/3.guide/3.ai/2.llms-txt.md +65 -0
  57. package/3.guide/4.modules/.navigation.yml +3 -0
  58. package/3.guide/4.modules/1.getting-started.md +103 -0
  59. package/3.guide/4.modules/2.module-anatomy.md +138 -0
  60. package/3.guide/4.modules/3.recipes-basics.md +330 -0
  61. package/3.guide/4.modules/4.recipes-advanced.md +243 -0
  62. package/3.guide/4.modules/5.testing.md +76 -0
  63. package/3.guide/4.modules/6.best-practices.md +104 -0
  64. package/3.guide/4.modules/7.ecosystem.md +32 -0
  65. package/3.guide/4.modules/index.md +36 -0
  66. package/{2.guide/4.recipes → 3.guide/5.recipes}/1.custom-routing.md +1 -1
  67. package/{2.guide/4.recipes → 3.guide/5.recipes}/2.vite-plugin.md +5 -1
  68. package/{2.guide/4.recipes → 3.guide/5.recipes}/3.custom-usefetch.md +2 -2
  69. package/{2.guide/4.recipes → 3.guide/5.recipes}/4.sessions-and-authentication.md +2 -2
  70. package/{2.guide/3.going-further → 3.guide/6.going-further}/1.events.md +2 -3
  71. package/{2.guide/3.going-further → 3.guide/6.going-further}/1.experimental-features.md +19 -4
  72. package/{2.guide/3.going-further → 3.guide/6.going-further}/1.internals.md +5 -4
  73. package/{2.guide/3.going-further → 3.guide/6.going-further}/10.runtime-config.md +3 -3
  74. package/{2.guide/3.going-further → 3.guide/6.going-further}/2.hooks.md +3 -3
  75. package/{2.guide/3.going-further → 3.guide/6.going-further}/4.kit.md +1 -1
  76. package/{2.guide/3.going-further → 3.guide/6.going-further}/6.nuxt-app.md +3 -3
  77. package/{2.guide/3.going-further → 3.guide/6.going-further}/7.layers.md +38 -12
  78. package/{3.api → 4.api}/1.components/1.nuxt-client-fallback.md +4 -0
  79. package/{3.api → 4.api}/1.components/12.nuxt-route-announcer.md +1 -3
  80. package/{3.api → 4.api}/1.components/13.nuxt-time.md +0 -2
  81. package/{3.api → 4.api}/1.components/2.nuxt-page.md +2 -2
  82. package/{3.api → 4.api}/1.components/3.nuxt-layout.md +6 -6
  83. package/{3.api → 4.api}/1.components/5.nuxt-loading-indicator.md +1 -1
  84. package/{3.api → 4.api}/1.components/7.nuxt-welcome.md +2 -2
  85. package/{3.api → 4.api}/1.components/8.nuxt-island.md +9 -2
  86. package/{3.api → 4.api}/2.composables/use-app-config.md +1 -1
  87. package/{3.api → 4.api}/2.composables/use-async-data.md +3 -3
  88. package/4.api/2.composables/use-cookie.md +183 -0
  89. package/{3.api → 4.api}/2.composables/use-error.md +2 -2
  90. package/{3.api → 4.api}/2.composables/use-fetch.md +33 -33
  91. package/{3.api → 4.api}/2.composables/use-head.md +16 -1
  92. package/{3.api → 4.api}/2.composables/use-lazy-fetch.md +8 -8
  93. package/{3.api → 4.api}/2.composables/use-nuxt-app.md +6 -4
  94. package/{3.api → 4.api}/2.composables/use-response-header.md +1 -1
  95. package/{3.api → 4.api}/2.composables/use-route-announcer.md +0 -2
  96. package/{3.api → 4.api}/2.composables/use-route.md +1 -1
  97. package/{3.api → 4.api}/2.composables/use-router.md +2 -2
  98. package/{3.api → 4.api}/2.composables/use-runtime-config.md +1 -1
  99. package/{3.api → 4.api}/2.composables/use-state.md +10 -0
  100. package/{3.api → 4.api}/3.utils/$fetch.md +1 -1
  101. package/{3.api → 4.api}/3.utils/abort-navigation.md +1 -1
  102. package/{3.api → 4.api}/3.utils/add-route-middleware.md +1 -1
  103. package/{3.api → 4.api}/3.utils/call-once.md +0 -2
  104. package/{3.api → 4.api}/3.utils/create-error.md +6 -6
  105. package/{3.api → 4.api}/3.utils/define-nuxt-plugin.md +12 -12
  106. package/{3.api → 4.api}/3.utils/define-nuxt-route-middleware.md +2 -2
  107. package/{3.api → 4.api}/3.utils/define-page-meta.md +14 -7
  108. package/{3.api → 4.api}/3.utils/navigate-to.md +10 -10
  109. package/{3.api → 4.api}/3.utils/refresh-cookie.md +0 -2
  110. package/{3.api → 4.api}/3.utils/set-page-layout.md +36 -0
  111. package/{3.api → 4.api}/3.utils/set-response-status.md +2 -2
  112. package/{3.api → 4.api}/3.utils/show-error.md +3 -3
  113. package/{3.api → 4.api}/3.utils/update-app-config.md +2 -2
  114. package/{3.api → 4.api}/4.commands/add.md +11 -11
  115. package/4.api/4.commands/analyze.md +42 -0
  116. package/4.api/4.commands/build-module.md +42 -0
  117. package/4.api/4.commands/build.md +47 -0
  118. package/{3.api → 4.api}/4.commands/cleanup.md +6 -6
  119. package/4.api/4.commands/dev.md +60 -0
  120. package/{3.api → 4.api}/4.commands/devtools.md +7 -7
  121. package/4.api/4.commands/generate.md +42 -0
  122. package/4.api/4.commands/info.md +33 -0
  123. package/4.api/4.commands/init.md +50 -0
  124. package/4.api/4.commands/module.md +84 -0
  125. package/4.api/4.commands/prepare.md +41 -0
  126. package/4.api/4.commands/preview.md +44 -0
  127. package/4.api/4.commands/test.md +40 -0
  128. package/4.api/4.commands/typecheck.md +44 -0
  129. package/4.api/4.commands/upgrade.md +37 -0
  130. package/{3.api → 4.api}/5.kit/1.modules.md +30 -17
  131. package/{3.api → 4.api}/5.kit/10.templates.md +23 -23
  132. package/{3.api → 4.api}/5.kit/11.nitro.md +35 -35
  133. package/{3.api → 4.api}/5.kit/14.builder.md +29 -17
  134. package/{3.api → 4.api}/5.kit/16.layers.md +12 -12
  135. package/{3.api → 4.api}/5.kit/2.programmatic.md +2 -2
  136. package/{3.api → 4.api}/5.kit/4.autoimports.md +18 -18
  137. package/4.api/5.kit/5.components.md +146 -0
  138. package/4.api/6.advanced/1.hooks.md +105 -0
  139. package/{3.api → 4.api}/6.nuxt-config.md +7 -6
  140. package/5.community/4.contribution.md +5 -5
  141. package/5.community/5.framework-contribution.md +1 -1
  142. package/5.community/6.roadmap.md +25 -25
  143. package/5.community/7.changelog.md +20 -0
  144. package/6.bridge/1.overview.md +9 -1
  145. package/6.bridge/2.typescript.md +1 -1
  146. package/6.bridge/3.bridge-composition-api.md +1 -1
  147. package/6.bridge/4.plugins-and-middleware.md +3 -3
  148. package/6.bridge/8.nitro.md +4 -0
  149. package/7.migration/11.server.md +1 -1
  150. package/7.migration/2.configuration.md +4 -4
  151. package/7.migration/20.module-authors.md +3 -3
  152. package/7.migration/3.auto-imports.md +1 -1
  153. package/7.migration/5.plugins-and-middleware.md +2 -2
  154. package/7.migration/6.pages-and-layouts.md +6 -6
  155. package/7.migration/7.component-options.md +1 -1
  156. package/package.json +1 -1
  157. package/2.guide/3.going-further/3.modules.md +0 -968
  158. package/3.api/2.composables/use-cookie.md +0 -183
  159. package/3.api/4.commands/analyze.md +0 -42
  160. package/3.api/4.commands/build-module.md +0 -42
  161. package/3.api/4.commands/build.md +0 -47
  162. package/3.api/4.commands/dev.md +0 -60
  163. package/3.api/4.commands/generate.md +0 -42
  164. package/3.api/4.commands/info.md +0 -33
  165. package/3.api/4.commands/init.md +0 -50
  166. package/3.api/4.commands/module.md +0 -84
  167. package/3.api/4.commands/prepare.md +0 -41
  168. package/3.api/4.commands/preview.md +0 -44
  169. package/3.api/4.commands/test.md +0 -40
  170. package/3.api/4.commands/typecheck.md +0 -44
  171. package/3.api/4.commands/upgrade.md +0 -37
  172. package/3.api/5.kit/5.components.md +0 -146
  173. package/3.api/6.advanced/1.hooks.md +0 -105
  174. /package/{2.guide/1.directory-structure → 2.directory-structure}/.navigation.yml +0 -0
  175. /package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/.navigation.yml +0 -0
  176. /package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/3.app-config.md +0 -0
  177. /package/{2.guide/1.directory-structure → 2.directory-structure}/1.public.md +0 -0
  178. /package/{2.guide/1.directory-structure → 2.directory-structure}/2.gitignore.md +0 -0
  179. /package/{2.guide → 3.guide}/.navigation.yml +0 -0
  180. /package/{2.guide/2.concepts → 3.guide/1.concepts}/.navigation.yml +0 -0
  181. /package/{2.guide/2.concepts → 3.guide/1.concepts}/9.code-style.md +0 -0
  182. /package/{2.guide/5.best-practices → 3.guide/2.best-practices}/.navigation.yml +0 -0
  183. /package/{2.guide/5.best-practices → 3.guide/2.best-practices}/hydration.md +0 -0
  184. /package/{2.guide/5.best-practices → 3.guide/2.best-practices}/plugins.md +0 -0
  185. /package/{2.guide/4.recipes → 3.guide/5.recipes}/.navigation.yml +0 -0
  186. /package/{2.guide/3.going-further → 3.guide/6.going-further}/.navigation.yml +0 -0
  187. /package/{2.guide/3.going-further → 3.guide/6.going-further}/1.features.md +0 -0
  188. /package/{2.guide/3.going-further → 3.guide/6.going-further}/11.nightly-release-channel.md +0 -0
  189. /package/{2.guide/3.going-further → 3.guide/6.going-further}/9.debugging.md +0 -0
  190. /package/{2.guide/3.going-further → 3.guide/6.going-further}/index.md +0 -0
  191. /package/{3.api → 4.api}/.navigation.yml +0 -0
  192. /package/{3.api → 4.api}/1.components/.navigation.yml +0 -0
  193. /package/{3.api → 4.api}/1.components/1.client-only.md +0 -0
  194. /package/{3.api → 4.api}/1.components/1.dev-only.md +0 -0
  195. /package/{3.api → 4.api}/1.components/10.nuxt-picture.md +0 -0
  196. /package/{3.api → 4.api}/1.components/11.teleports.md +0 -0
  197. /package/{3.api → 4.api}/1.components/4.nuxt-link.md +0 -0
  198. /package/{3.api → 4.api}/1.components/6.nuxt-error-boundary.md +0 -0
  199. /package/{3.api → 4.api}/1.components/9.nuxt-img.md +0 -0
  200. /package/{3.api → 4.api}/2.composables/.navigation.yml +0 -0
  201. /package/{3.api → 4.api}/2.composables/on-prehydrate.md +0 -0
  202. /package/{3.api → 4.api}/2.composables/use-head-safe.md +0 -0
  203. /package/{3.api → 4.api}/2.composables/use-hydration.md +0 -0
  204. /package/{3.api → 4.api}/2.composables/use-lazy-async-data.md +0 -0
  205. /package/{3.api → 4.api}/2.composables/use-loading-indicator.md +0 -0
  206. /package/{3.api → 4.api}/2.composables/use-nuxt-data.md +0 -0
  207. /package/{3.api → 4.api}/2.composables/use-preview-mode.md +0 -0
  208. /package/{3.api → 4.api}/2.composables/use-request-event.md +0 -0
  209. /package/{3.api → 4.api}/2.composables/use-request-fetch.md +0 -0
  210. /package/{3.api → 4.api}/2.composables/use-request-header.md +0 -0
  211. /package/{3.api → 4.api}/2.composables/use-request-headers.md +0 -0
  212. /package/{3.api → 4.api}/2.composables/use-request-url.md +0 -0
  213. /package/{3.api → 4.api}/2.composables/use-runtime-hook.md +0 -0
  214. /package/{3.api → 4.api}/2.composables/use-seo-meta.md +0 -0
  215. /package/{3.api → 4.api}/2.composables/use-server-seo-meta.md +0 -0
  216. /package/{3.api → 4.api}/3.utils/.navigation.yml +0 -0
  217. /package/{3.api → 4.api}/3.utils/clear-error.md +0 -0
  218. /package/{3.api → 4.api}/3.utils/clear-nuxt-data.md +0 -0
  219. /package/{3.api → 4.api}/3.utils/clear-nuxt-state.md +0 -0
  220. /package/{3.api → 4.api}/3.utils/define-lazy-hydration-component.md +0 -0
  221. /package/{3.api → 4.api}/3.utils/define-nuxt-component.md +0 -0
  222. /package/{3.api → 4.api}/3.utils/define-route-rules.md +0 -0
  223. /package/{3.api → 4.api}/3.utils/on-before-route-leave.md +0 -0
  224. /package/{3.api → 4.api}/3.utils/on-before-route-update.md +0 -0
  225. /package/{3.api → 4.api}/3.utils/on-nuxt-ready.md +0 -0
  226. /package/{3.api → 4.api}/3.utils/prefetch-components.md +0 -0
  227. /package/{3.api → 4.api}/3.utils/preload-components.md +0 -0
  228. /package/{3.api → 4.api}/3.utils/preload-route-components.md +0 -0
  229. /package/{3.api → 4.api}/3.utils/prerender-routes.md +0 -0
  230. /package/{3.api → 4.api}/3.utils/refresh-nuxt-data.md +0 -0
  231. /package/{3.api → 4.api}/3.utils/reload-nuxt-app.md +0 -0
  232. /package/{3.api → 4.api}/4.commands/.navigation.yml +0 -0
  233. /package/{3.api → 4.api}/5.kit/.navigation.yml +0 -0
  234. /package/{3.api → 4.api}/5.kit/10.runtime-config.md +0 -0
  235. /package/{3.api → 4.api}/5.kit/12.resolving.md +0 -0
  236. /package/{3.api → 4.api}/5.kit/13.logging.md +0 -0
  237. /package/{3.api → 4.api}/5.kit/15.examples.md +0 -0
  238. /package/{3.api → 4.api}/5.kit/3.compatibility.md +0 -0
  239. /package/{3.api → 4.api}/5.kit/6.context.md +0 -0
  240. /package/{3.api → 4.api}/5.kit/7.pages.md +0 -0
  241. /package/{3.api → 4.api}/5.kit/8.layout.md +0 -0
  242. /package/{3.api → 4.api}/5.kit/9.head.md +0 -0
  243. /package/{3.api → 4.api}/5.kit/9.plugins.md +0 -0
  244. /package/{3.api → 4.api}/6.advanced/.navigation.yml +0 -0
  245. /package/{3.api → 4.api}/6.advanced/2.import-meta.md +0 -0
  246. /package/{3.api → 4.api}/index.md +0 -0
@@ -0,0 +1,65 @@
1
+ ---
2
+ title: Nuxt LLMs.txt
3
+ description: How to get AI tools like Cursor, Windsurf, GitHub Copilot, ChatGPT, and Claude to understand Nuxt concepts, APIs, and best practices.
4
+ navigation.title: LLMs.txt
5
+ ---
6
+
7
+ ## What is LLMs.txt?
8
+
9
+ LLMs.txt is a structured documentation format specifically designed for large language models (LLMs). Nuxt provides LLMs.txt files that contain comprehensive information about the framework, making it easy for AI tools to understand and assist with Nuxt development.
10
+
11
+ These files are optimized for AI consumption and contain structured information about concepts, APIs, usage patterns, and best practices.
12
+
13
+ ## Available routes
14
+
15
+ We provide LLMs.txt routes to help AI tools access our documentation:
16
+
17
+ - **`/llms.txt`** - Contains a structured overview of all documentation pages and their links (~5K tokens)
18
+ - **`/llms-full.txt`** - Provides comprehensive documentation including getting started guides, API references, blog posts, and deployment guides (~1M+ tokens)
19
+
20
+ ## Choosing the Right File
21
+
22
+ ::note{icon="i-lucide-info"}
23
+ **Most users should start with `/llms.txt`** - it contains all essential information and works with standard LLM context windows.
24
+
25
+ Use `/llms-full.txt` only if you need comprehensive implementation details and your AI tool supports large contexts (200K+ tokens).
26
+ ::
27
+
28
+ ## Important usage notes
29
+
30
+ ::warning{icon="i-lucide-alert-triangle"}
31
+ **@-symbol must be typed manually** - When using tools like Cursor or Windsurf, the `@` symbol must be typed by hand in the chat interface. Copy-pasting breaks the tool's ability to recognize it as a context reference.
32
+ ::
33
+
34
+ ## Usage with AI Tools
35
+
36
+ ### Cursor
37
+
38
+ Nuxt provides specialized LLMs.txt files that you can reference in Cursor for better AI assistance with Nuxt development.
39
+
40
+ #### How to use
41
+
42
+ 1. **Direct reference**: Mention the LLMs.txt URLs when asking questions
43
+ 2. Add these specific URLs to your project context using `@docs`
44
+
45
+ [Read more about Cursor Web and Docs Search](https://cursor.com/docs/context/symbols)
46
+
47
+ ### Windsurf
48
+
49
+ Windsurf can directly access the Nuxt LLMs.txt files to understand framework usage and best practices.
50
+
51
+ #### Using LLMs.txt with Windsurf
52
+
53
+ - Use `@docs` to reference specific LLMs.txt URLs
54
+ - Create persistent rules referencing these URLs in your workspace
55
+
56
+ [Read more about Windsurf Web and Docs Search](https://docs.windsurf.com/windsurf/cascade/web-search)
57
+
58
+ ### Other AI Tools
59
+
60
+ Any AI tool that supports LLMs.txt can use these routes to better understand Nuxt.
61
+
62
+ #### Examples for ChatGPT, Claude, or other LLMs
63
+
64
+ - "Using Nuxt documentation from https://nuxt.com/llms.txt"
65
+ - "Follow complete Nuxt guidelines from https://nuxt.com/llms-full.txt"
@@ -0,0 +1,3 @@
1
+ title: Module Author Guide
2
+ titleTemplate: '%s · Nuxt Modules Author Guide'
3
+ icon: i-lucide-box
@@ -0,0 +1,103 @@
1
+ ---
2
+ title: "Create Your First Module"
3
+ description: "Learn how to create your first Nuxt module using the official starter template."
4
+ ---
5
+
6
+ ## Create a Module
7
+
8
+ We recommend you get started with Nuxt modules using our [starter template](https://github.com/nuxt/starter/tree/module):
9
+
10
+ ::code-group{sync="pm"}
11
+
12
+ ```bash [npm]
13
+ npm create nuxt -- -t module my-module
14
+ ```
15
+
16
+ ```bash [yarn]
17
+ yarn create nuxt -t module my-module
18
+ ```
19
+
20
+ ```bash [pnpm]
21
+ pnpm create nuxt -t module my-module
22
+ ```
23
+
24
+ ```bash [bun]
25
+ bun create nuxt --template=module my-module
26
+ ```
27
+ ::
28
+
29
+ This will create a `my-module` project with all the boilerplate necessary to develop and publish your module.
30
+
31
+ **Next steps:**
32
+
33
+ 1. Open `my-module` in your IDE of choice
34
+ 2. Install dependencies using your favorite package manager
35
+ 3. Prepare local files for development using `npm run dev:prepare`
36
+ 4. Follow this document to learn more about Nuxt modules
37
+
38
+ ## Use the Starter Template
39
+
40
+ Learn how to perform basic tasks with the module starter.
41
+
42
+ ::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/navigating-the-official-starter-template?friend=nuxt" target="_blank"}
43
+ Watch Vue School video about Nuxt module starter template.
44
+ ::
45
+
46
+ ### Develop Your Module
47
+
48
+ While your module source code lives inside the `src` directory, to develop a module you often need a Nuxt application to test it against. That's what the `playground` directory is for. It's a Nuxt application you can tinker with that is already configured to run with your module.
49
+
50
+ You can interact with the playground like with any Nuxt application.
51
+
52
+ - Launch its development server with `npm run dev`, it should reload itself as you make changes to your module in the `src` directory
53
+ - Build it with `npm run dev:build`
54
+
55
+ ::note
56
+ All other `nuxt` commands can be used against the `playground` directory (e.g. `nuxt <COMMAND> playground`). Feel free to declare additional `dev:*` scripts within your `package.json` referencing them for convenience.
57
+ ::
58
+
59
+ ### Run Tests
60
+
61
+ The module starter comes with a basic test suite:
62
+
63
+ - A linter powered by [ESLint](https://eslint.org), run it with `npm run lint`
64
+ - A test runner powered by [Vitest](https://vitest.dev), run it with `npm run test` or `npm run test:watch`
65
+
66
+ ::tip
67
+ Feel free to augment this default test strategy to better suit your needs.
68
+ ::
69
+
70
+ ### Build Your Module
71
+
72
+ Nuxt modules come with their own builder provided by [`@nuxt/module-builder`](https://github.com/nuxt/module-builder#readme). This builder doesn't require any configuration on your end, supports TypeScript, and makes sure your assets are properly bundled to be distributed to other Nuxt applications.
73
+
74
+ You can build your module by running `npm run prepack`.
75
+
76
+ ::tip
77
+ While building your module can be useful in some cases, most of the time you won't need to build it on your own: the `playground` takes care of it while developing, and the release script also has you covered when publishing.
78
+ ::
79
+
80
+ ### Publish to npm
81
+
82
+ ::important
83
+ Before publishing your module to npm, makes sure you have an [npmjs.com](https://www.npmjs.com) account and that you're authenticated to it locally with `npm login`.
84
+ ::
85
+
86
+ While you can publish your module by bumping its version and using the `npm publish` command, the module starter comes with a release script that helps you make sure you publish a working version of your module to npm and more.
87
+
88
+ To use the release script, first, commit all your changes (we recommend you follow [Conventional Commits](https://www.conventionalcommits.org) to also take advantage of automatic version bump and changelog update), then run the release script with `npm run release`.
89
+
90
+ When running the release script, the following will happen:
91
+
92
+ - First, it will run your test suite by:
93
+ - Running the linter (`npm run lint`)
94
+ - Running unit, integration, and e2e tests (`npm run test`)
95
+ - Building the module (`npm run prepack`)
96
+ - Then, if your test suite went well, it will proceed to publish your module by:
97
+ - Bumping your module version and generating a changelog according to your Conventional Commits
98
+ - Publishing the module to npm (for that purpose, the module will be built again to ensure its updated version number is taken into account in the published artifact)
99
+ - Pushing a git tag representing the newly published version to your git remote origin
100
+
101
+ ::tip
102
+ As with other scripts, feel free to fine-tune the default `release` script in your `package.json` to better suit your needs.
103
+ ::
@@ -0,0 +1,138 @@
1
+ ---
2
+ title: "Understand Module Structure"
3
+ description: "Learn how Nuxt modules are structured and how to define them."
4
+ ---
5
+
6
+ There are two types of Nuxt modules:
7
+
8
+ - published modules are distributed on npm - you can see a list of some community modules on [the Nuxt website](/modules).
9
+ - "local" modules exist within a Nuxt project, either [inlined in Nuxt config](/docs/4.x/api/nuxt-config#modules) or within [the `modules` directory](/docs/4.x/directory-structure/modules).
10
+
11
+ In either case, they work in the same way.
12
+
13
+ ## Define Your Module
14
+
15
+ ::note
16
+ When using the starter, your module definition is available at `src/module.ts`.
17
+ ::
18
+
19
+ The module definition is the entry point of your module. It's what gets loaded by Nuxt when your module is referenced within a Nuxt configuration.
20
+
21
+ At a low level, a Nuxt module definition is a simple, potentially asynchronous, function accepting inline user options and a `nuxt` object to interact with Nuxt.
22
+
23
+ ```ts
24
+ export default function (inlineOptions, nuxt) {
25
+ // You can do whatever you like here..
26
+ console.log(inlineOptions.token) // `123`
27
+ console.log(nuxt.options.dev) // `true` or `false`
28
+ nuxt.hook('ready', (nuxt) => {
29
+ console.log('Nuxt is ready')
30
+ })
31
+ }
32
+ ```
33
+
34
+ You can get type hinting for this function using the higher-level `defineNuxtModule` helper provided by [Nuxt Kit](/docs/4.x/guide/going-further/kit).
35
+
36
+ ```ts
37
+ import { defineNuxtModule } from '@nuxt/kit'
38
+
39
+ export default defineNuxtModule((options, nuxt) => {
40
+ nuxt.hook('pages:extend', (pages) => {
41
+ console.log(`Discovered ${pages.length} pages`)
42
+ })
43
+ })
44
+ ```
45
+
46
+ However, **we do not recommend** using this low-level function definition. Instead, to define a module, **we recommend** using the object-syntax with `meta` property to identify your module, especially when publishing to npm.
47
+
48
+ This helper makes writing Nuxt modules more straightforward by implementing many common patterns needed by modules, guaranteeing future compatibility and improving the experience for both module authors and users.
49
+
50
+ ```ts
51
+ import { defineNuxtModule } from '@nuxt/kit'
52
+
53
+ export default defineNuxtModule({
54
+ meta: {
55
+ // Usually the npm package name of your module
56
+ name: '@nuxtjs/example',
57
+ // The key in `nuxt.config` that holds your module options
58
+ configKey: 'sample',
59
+ // Compatibility constraints
60
+ compatibility: {
61
+ // Semver version of supported nuxt versions
62
+ nuxt: '>=3.0.0',
63
+ },
64
+ },
65
+ // Default configuration options for your module, can also be a function returning those
66
+ defaults: {},
67
+ // Shorthand sugar to register Nuxt hooks
68
+ hooks: {},
69
+ // Configuration for other modules - this does not ensure the module runs before
70
+ // your module, but it allows you to change the other module's configuration before it runs
71
+ moduleDependencies: {
72
+ 'some-module': {
73
+ // You can specify a version constraint for the module. If the user has a different
74
+ // version installed, Nuxt will throw an error on startup.
75
+ version: '>=2',
76
+ // By default moduleDependencies will be added to the list of modules to be installed
77
+ // by Nuxt unless `optional` is set.
78
+ optional: true,
79
+ // Any configuration that should override `nuxt.options`.
80
+ overrides: {},
81
+ // Any configuration that should be set. It will override module defaults but
82
+ // will not override any configuration set in `nuxt.options`.
83
+ defaults: {},
84
+ },
85
+ },
86
+ // The function holding your module logic, it can be asynchronous
87
+ setup (moduleOptions, nuxt) {
88
+ // ...
89
+ },
90
+ })
91
+ ```
92
+
93
+ `defineNuxtModule` returns a wrapper function with the lower level `(inlineOptions, nuxt)` module signature. This wrapper function applies defaults and other necessary steps before calling your `setup` function:
94
+
95
+ - Support `defaults` and `meta.configKey` for automatically merging module options
96
+ - Type hints and automated type inference
97
+ - Ensure module gets installed only once using a unique key computed from `meta.name` or `meta.configKey`
98
+ - Automatically register Nuxt hooks
99
+ - Automatically check for compatibility issues based on module meta
100
+ - Expose `getOptions` and `getMeta` for internal usage of Nuxt
101
+ - Ensuring backward and upward compatibility as long as the module is using `defineNuxtModule` from the latest version of `@nuxt/kit`
102
+ - Integration with module builder tooling
103
+
104
+ ## Add Runtime Code
105
+
106
+ ::note
107
+ When using the starter, the runtime directory is `src/runtime/`.
108
+ ::
109
+
110
+ Modules, like everything in a Nuxt configuration, aren't included in your application runtime. However, you might want your module to provide, or inject runtime code to the application it's installed on. That's what the runtime directory enables you to do.
111
+
112
+ Inside the runtime directory, you can provide any kind of assets related to the Nuxt app:
113
+ - Vue components
114
+ - Composables
115
+ - [Nuxt plugins](/docs/4.x/directory-structure/app/plugins)
116
+
117
+ To the [server engine](/docs/4.x/guide/concepts/server-engine), Nitro:
118
+ - API routes
119
+ - Middlewares
120
+ - Nitro plugins
121
+
122
+ Or any other kind of asset you want to inject in users' Nuxt applications:
123
+ - Stylesheets
124
+ - 3D models
125
+ - Images
126
+ - etc.
127
+
128
+ You'll then be able to inject all those assets inside the application from your [module definition](#define-your-module).
129
+
130
+ ::tip
131
+ Learn more about asset injection in [the recipes section](/docs/4.x/guide/modules/recipes-basics).
132
+ ::
133
+
134
+ ::warning
135
+ Published modules cannot leverage auto-imports for assets within their runtime directory. Instead, they have to import them explicitly from `#imports` or alike.
136
+ :br :br
137
+ Auto-imports are not enabled for files within `node_modules` (the location where a published module will eventually live) for performance reasons.
138
+ ::
@@ -0,0 +1,330 @@
1
+ ---
2
+ title: "Add Plugins, Components & More"
3
+ description: "Learn how to inject plugins, components, composables and server routes from your module."
4
+ ---
5
+
6
+ Here are some common patterns used by module authors.
7
+
8
+ ## Modify Nuxt Configuration
9
+
10
+ Nuxt configuration can be read and altered by modules. Here's an example of a module enabling an experimental feature.
11
+
12
+ ```js
13
+ import { defineNuxtModule } from '@nuxt/kit'
14
+
15
+ export default defineNuxtModule({
16
+ setup (options, nuxt) {
17
+ // We create the `experimental` object if it doesn't exist yet
18
+ nuxt.options.experimental ||= {}
19
+ nuxt.options.experimental.componentIslands = true
20
+ },
21
+ })
22
+ ```
23
+
24
+ When you need to handle more complex configuration alterations, you should consider using [defu](https://github.com/unjs/defu).
25
+
26
+ ::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/extending-and-altering-nuxt-configuration-and-options?friend=nuxt" target="_blank"}
27
+ Watch Vue School video about altering Nuxt configuration.
28
+ ::
29
+
30
+ ## Expose Options to Runtime
31
+
32
+ Because modules aren't part of the application runtime, their options aren't either. However, in many cases, you might need access to some of these module options within your runtime code. We recommend exposing the needed config using Nuxt's [`runtimeConfig`](/docs/4.x/api/nuxt-config#runtimeconfig).
33
+
34
+ <!-- TODO: Update after #18466 (or equivalent) -->
35
+
36
+ ```js
37
+ import { defineNuxtModule } from '@nuxt/kit'
38
+ import { defu } from 'defu'
39
+
40
+ export default defineNuxtModule({
41
+ setup (options, nuxt) {
42
+ nuxt.options.runtimeConfig.public.myModule = defu(nuxt.options.runtimeConfig.public.myModule, {
43
+ foo: options.foo,
44
+ })
45
+ },
46
+ })
47
+ ```
48
+
49
+ Note that we use [`defu`](https://github.com/unjs/defu) to extend the public runtime configuration the user provides instead of overwriting it.
50
+
51
+ You can then access your module options in a plugin, component, the application like any other runtime configuration:
52
+
53
+ ```js
54
+ import { useRuntimeConfig } from '@nuxt/kit'
55
+
56
+ const options = useRuntimeConfig().public.myModule
57
+ ```
58
+
59
+ ::warning
60
+ Be careful not to expose any sensitive module configuration on the public runtime config, such as private API keys, as they will end up in the public bundle.
61
+ ::
62
+
63
+ :read-more{to="/docs/4.x/guide/going-further/runtime-config"}
64
+
65
+ ::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/passing-and-exposing-module-options?friend=nuxt" target="_blank"}
66
+ Watch Vue School video about passing and exposing Nuxt module options.
67
+ ::
68
+
69
+ ## Add Plugins
70
+
71
+ Plugins are a common way for a module to add runtime logic. You can use the `addPlugin` utility to register them from your module.
72
+
73
+ ```js
74
+ import { addPlugin, createResolver, defineNuxtModule } from '@nuxt/kit'
75
+
76
+ export default defineNuxtModule({
77
+ setup (options, nuxt) {
78
+ // Create resolver to resolve relative paths
79
+ const resolver = createResolver(import.meta.url)
80
+
81
+ addPlugin(resolver.resolve('./runtime/plugin'))
82
+ },
83
+ })
84
+ ```
85
+
86
+ :read-more{to="/docs/4.x/guide/going-further/kit"}
87
+
88
+ ## Add Components
89
+
90
+ If your module should provide Vue components, you can use the `addComponent` utility to add them as auto-imports for Nuxt to resolve.
91
+
92
+ ```ts twoslash
93
+ import { addComponent, createResolver, defineNuxtModule, useRuntimeConfig } from '@nuxt/kit'
94
+
95
+ export default defineNuxtModule({
96
+ setup (options, nuxt) {
97
+ const resolver = createResolver(import.meta.url)
98
+
99
+ // From the runtime directory
100
+ addComponent({
101
+ name: 'MySuperComponent', // name of the component to be used in vue templates
102
+ export: 'MySuperComponent', // (optional) if the component is a named (rather than default) export
103
+ filePath: resolver.resolve('runtime/app/components/MySuperComponent.vue'),
104
+ })
105
+
106
+ // From a library
107
+ addComponent({
108
+ name: 'MyAwesomeComponent', // name of the component to be used in vue templates
109
+ export: 'MyAwesomeComponent', // (optional) if the component is a named (rather than default) export
110
+ filePath: '@vue/awesome-components',
111
+ })
112
+ },
113
+ })
114
+ ```
115
+
116
+ Alternatively, you can add an entire directory by using `addComponentsDir`.
117
+
118
+ ```ts
119
+ import { addComponentsDir, defineNuxtModule } from '@nuxt/kit'
120
+
121
+ export default defineNuxtModule({
122
+ setup (options, nuxt) {
123
+ const resolver = createResolver(import.meta.url)
124
+
125
+ addComponentsDir({
126
+ path: resolver.resolve('runtime/app/components'),
127
+ })
128
+ },
129
+ })
130
+ ```
131
+
132
+ ::tip{icon="i-lucide-lightbulb"}
133
+ It is highly recommended to prefix your exports to avoid conflicts with user code or other modules.
134
+
135
+ :read-more{to="/docs/4.x/guide/modules/best-practices#prefix-your-exports"}
136
+ ::
137
+
138
+ ::note
139
+ Note that all components, pages, composables and other files that would be normally placed in your `app/` folder need to be in `runtime/app/`. This will mean they can be type checked properly.
140
+ ::
141
+
142
+ ## Add Composables
143
+
144
+ If your module should provide composables, you can use the `addImports` utility to add them as auto-imports for Nuxt to resolve.
145
+
146
+ ```ts
147
+ import { addImports, createResolver, defineNuxtModule } from '@nuxt/kit'
148
+
149
+ export default defineNuxtModule({
150
+ setup (options, nuxt) {
151
+ const resolver = createResolver(import.meta.url)
152
+
153
+ addImports({
154
+ name: 'useComposable', // name of the composable to be used
155
+ as: 'useMyComposable', // optional alias that will be available for the consuming apps
156
+ from: resolver.resolve('runtime/app/composables/useComposable'), // path of composable
157
+ })
158
+ },
159
+ })
160
+ ```
161
+
162
+ Multiple entries can be passed as an array:
163
+
164
+ ```ts
165
+ import { addImports, createResolver, defineNuxtModule } from '@nuxt/kit'
166
+
167
+ export default defineNuxtModule({
168
+ setup (options, nuxt) {
169
+ const resolver = createResolver(import.meta.url)
170
+
171
+ addImports([
172
+ { name: 'useFirstComposable', from: resolver.resolve('runtime/composables/useFirstComposable') },
173
+ { name: 'useSecondComposable', from: resolver.resolve('runtime/composables/useSecondComposable') },
174
+ ])
175
+ },
176
+ })
177
+ ```
178
+
179
+ Alternatively, you can add an entire directory by using `addImportsDir`.
180
+
181
+ ```ts
182
+ import { addImportsDir, createResolver, defineNuxtModule } from '@nuxt/kit'
183
+
184
+ export default defineNuxtModule({
185
+ setup (options, nuxt) {
186
+ const resolver = createResolver(import.meta.url)
187
+
188
+ addImportsDir(resolver.resolve('runtime/composables'))
189
+ },
190
+ })
191
+ ```
192
+
193
+ ::tip{icon="i-lucide-lightbulb"}
194
+ It is highly recommended to prefix your exports to avoid conflicts with user code or other modules.
195
+
196
+ :read-more{to="/docs/4.x/guide/modules/best-practices#prefix-your-exports"}
197
+ ::
198
+
199
+ ::note
200
+ Note that all components, pages, composables and other files that would be normally placed in your `app/` folder need to be in `runtime/app/`. This will mean they can be type checked properly.
201
+ ::
202
+
203
+ ## Add Server Routes
204
+
205
+ ```ts
206
+ import { addServerHandler, createResolver, defineNuxtModule } from '@nuxt/kit'
207
+
208
+ export default defineNuxtModule({
209
+ setup (options, nuxt) {
210
+ const resolver = createResolver(import.meta.url)
211
+
212
+ addServerHandler({
213
+ route: '/api/_my-module/hello',
214
+ handler: resolver.resolve('./runtime/server/api/hello/index.get'),
215
+ })
216
+ },
217
+ })
218
+ ```
219
+
220
+ You can also add a dynamic server route:
221
+
222
+ ```ts
223
+ import { addServerHandler, createResolver, defineNuxtModule } from '@nuxt/kit'
224
+
225
+ export default defineNuxtModule({
226
+ setup (options, nuxt) {
227
+ const resolver = createResolver(import.meta.url)
228
+
229
+ addServerHandler({
230
+ route: '/api/_my-module/hello/:name',
231
+ handler: resolver.resolve('./runtime/server/api/hello/[name].get'),
232
+ })
233
+
234
+ // Or using a catch all route
235
+ addServerHandler({
236
+ route: '/api/_my-module/files/**:path',
237
+ handler: resolver.resolve('./runtime/server/api/files/[...path].get'),
238
+ })
239
+ },
240
+ })
241
+ ```
242
+
243
+ ::tip{icon="i-lucide-lightbulb"}
244
+ It is highly recommended to prefix your server routes to avoid conflicts with user-defined routes. Common paths like `/api/auth`, `/api/login`, or `/api/user` may already be used by the application.
245
+
246
+ :read-more{to="/docs/4.x/guide/modules/best-practices#prefix-your-exports"}
247
+ ::
248
+
249
+ ## Add Other Assets
250
+
251
+ If your module should provide other kinds of assets, they can also be injected. Here's a simple example module injecting a stylesheet through Nuxt's `css` array.
252
+
253
+ ```js
254
+ import { addPlugin, createResolver, defineNuxtModule } from '@nuxt/kit'
255
+
256
+ export default defineNuxtModule({
257
+ setup (options, nuxt) {
258
+ const resolver = createResolver(import.meta.url)
259
+
260
+ nuxt.options.css.push(resolver.resolve('./runtime/style.css'))
261
+ },
262
+ })
263
+ ```
264
+
265
+ And a more advanced one, exposing a folder of assets through [Nitro](/docs/4.x/guide/concepts/server-engine)'s `publicAssets` option:
266
+
267
+ ```js
268
+ import { createResolver, defineNuxtModule } from '@nuxt/kit'
269
+
270
+ export default defineNuxtModule({
271
+ setup (options, nuxt) {
272
+ const resolver = createResolver(import.meta.url)
273
+
274
+ nuxt.hook('nitro:config', (nitroConfig) => {
275
+ nitroConfig.publicAssets ||= []
276
+ nitroConfig.publicAssets.push({
277
+ dir: resolver.resolve('./runtime/public'),
278
+ maxAge: 60 * 60 * 24 * 365, // 1 year
279
+ })
280
+ })
281
+ },
282
+ })
283
+ ```
284
+
285
+ ## Use Other Modules
286
+
287
+ If your module depends on other modules, you can specify them using the `moduleDependencies` option. This provides a more robust way to handle module dependencies with version constraints and configuration merging:
288
+
289
+ ```ts
290
+ import { createResolver, defineNuxtModule } from '@nuxt/kit'
291
+
292
+ const resolver = createResolver(import.meta.url)
293
+
294
+ export default defineNuxtModule<ModuleOptions>({
295
+ meta: {
296
+ name: 'my-module',
297
+ },
298
+ moduleDependencies: {
299
+ '@nuxtjs/tailwindcss': {
300
+ // You can specify a version constraint for the module
301
+ version: '>=6',
302
+ // Any configuration that should override `nuxt.options`
303
+ overrides: {
304
+ exposeConfig: true,
305
+ },
306
+ // Any configuration that should be set. It will override module defaults but
307
+ // will not override any configuration set in `nuxt.options`
308
+ defaults: {
309
+ config: {
310
+ darkMode: 'class',
311
+ content: {
312
+ files: [
313
+ resolver.resolve('./runtime/components/**/*.{vue,mjs,ts}'),
314
+ resolver.resolve('./runtime/*.{mjs,js,ts}'),
315
+ ],
316
+ },
317
+ },
318
+ },
319
+ },
320
+ },
321
+ setup (options, nuxt) {
322
+ // We can inject our CSS file which includes Tailwind's directives
323
+ nuxt.options.css.push(resolver.resolve('./runtime/assets/styles.css'))
324
+ },
325
+ })
326
+ ```
327
+
328
+ ::callout{type="info"}
329
+ The `moduleDependencies` option replaces the deprecated `installModule` function and ensures proper setup order and configuration merging.
330
+ ::