@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,295 @@
1
+ ---
2
+ title: Pages
3
+ description: Nuxt Kit provides a set of utilities to help you create and use pages. You can use these utilities to manipulate the pages configuration or to define route rules.
4
+ links:
5
+ - label: Source
6
+ icon: i-simple-icons-github
7
+ to: https://github.com/nuxt/nuxt/blob/main/packages/kit/src/pages.ts
8
+ size: xs
9
+ ---
10
+
11
+ ## `extendPages`
12
+
13
+ In Nuxt, routes are automatically generated based on the structure of the files in the `pages` directory. However, there may be scenarios where you'd want to customize these routes. For instance, you might need to add a route for a dynamic page not generated by Nuxt, remove an existing route, or modify the configuration of a route. For such customizations, Nuxt offers the `extendPages` feature, which allows you to extend and alter the pages configuration.
14
+
15
+ ::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/extend-and-alter-nuxt-pages?friend=nuxt" target="_blank"}
16
+ Watch Vue School video about extendPages.
17
+ ::
18
+
19
+ ### Type
20
+
21
+ ```ts
22
+ function extendPages (callback: (pages: NuxtPage[]) => void): void
23
+
24
+ type NuxtPage = {
25
+ name?: string
26
+ path: string
27
+ file?: string
28
+ meta?: Record<string, any>
29
+ alias?: string[] | string
30
+ redirect?: RouteLocationRaw
31
+ children?: NuxtPage[]
32
+ }
33
+ ```
34
+
35
+ ### Parameters
36
+
37
+ #### `callback`
38
+
39
+ **Type**: `(pages: NuxtPage[]) => void`
40
+
41
+ **Required**: `true`
42
+
43
+ A function that will be called with the pages configuration. You can alter this array by adding, deleting, or modifying its elements. Note: You should modify the provided pages array directly, as changes made to a copied array will not be reflected in the configuration.
44
+
45
+ ### Examples
46
+
47
+ ```ts
48
+ // https://github.com/nuxt-modules/prismic/blob/master/src/module.ts
49
+ import { createResolver, defineNuxtModule, extendPages } from '@nuxt/kit'
50
+
51
+ export default defineNuxtModule({
52
+ setup(options) {
53
+ const resolver = createResolver(import.meta.url)
54
+
55
+ extendPages((pages) => {
56
+ pages.unshift({
57
+ name: 'prismic-preview',
58
+ path: '/preview',
59
+ file: resolver.resolve('runtime/preview.vue')
60
+ })
61
+ })
62
+ }
63
+ })
64
+ ```
65
+
66
+ ## `extendRouteRules`
67
+
68
+ Nuxt is powered by the [Nitro](https://nitro.unjs.io) server engine. With Nitro, you can incorporate high-level logic directly into your configuration, which is useful for actions like redirects, proxying, caching, and appending headers to routes. This configuration works by associating route patterns with specific route settings.
69
+
70
+ ::tip
71
+ You can read more about Nitro route rules in the [Nitro documentation](https://nitro.unjs.io/guide/routing#route-rules).
72
+ ::
73
+
74
+ ::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/adding-route-rules-and-route-middlewares?friend=nuxt" target="_blank"}
75
+ Watch Vue School video about adding route rules and route middelwares.
76
+ ::
77
+
78
+ ### Type
79
+
80
+ ```ts
81
+ function extendRouteRules (route: string, rule: NitroRouteConfig, options: ExtendRouteRulesOptions): void
82
+
83
+ interface NitroRouteConfig {
84
+ cache?: CacheOptions | false;
85
+ headers?: Record<string, string>;
86
+ redirect?: string | { to: string; statusCode?: HTTPStatusCode };
87
+ prerender?: boolean;
88
+ proxy?: string | ({ to: string } & ProxyOptions);
89
+ isr?: number | boolean;
90
+ cors?: boolean;
91
+ swr?: boolean | number;
92
+ static?: boolean | number;
93
+ }
94
+
95
+ interface ExtendRouteRulesOptions {
96
+ override?: boolean
97
+ }
98
+
99
+ interface CacheOptions {
100
+ swr?: boolean
101
+ name?: string
102
+ group?: string
103
+ integrity?: any
104
+ maxAge?: number
105
+ staleMaxAge?: number
106
+ base?: string
107
+ headersOnly?: boolean
108
+ }
109
+
110
+ // See https://www.jsdocs.io/package/h3#ProxyOptions
111
+ interface ProxyOptions {
112
+ headers?: RequestHeaders | HeadersInit;
113
+ fetchOptions?: RequestInit & { duplex?: Duplex } & {
114
+ ignoreResponseError?: boolean;
115
+ };
116
+ fetch?: typeof fetch;
117
+ sendStream?: boolean;
118
+ streamRequest?: boolean;
119
+ cookieDomainRewrite?: string | Record<string, string>;
120
+ cookiePathRewrite?: string | Record<string, string>;
121
+ onResponse?: (event: H3Event, response: Response) => void;
122
+ }
123
+ ```
124
+
125
+ ### Parameters
126
+
127
+ #### `route`
128
+
129
+ **Type**: `string`
130
+
131
+ **Required**: `true`
132
+
133
+ A route pattern to match against.
134
+
135
+ #### `rule`
136
+
137
+ **Type**: `NitroRouteConfig`
138
+
139
+ **Required**: `true`
140
+
141
+ A route configuration to apply to the matched route.
142
+
143
+ #### `options`
144
+
145
+ **Type**: `ExtendRouteRulesOptions`
146
+
147
+ **Default**: `{}`
148
+
149
+ Options to pass to the route configuration. If `override` is set to `true`, it will override the existing route configuration.
150
+
151
+ ### Examples
152
+
153
+ ```ts
154
+ // https://github.com/directus/website/blob/main/modules/redirects.ts
155
+ import { createResolver, defineNuxtModule, extendRouteRules, extendPages } from '@nuxt/kit'
156
+
157
+ export default defineNuxtModule({
158
+ setup(options) {
159
+ const resolver = createResolver(import.meta.url)
160
+
161
+ extendPages((pages) => {
162
+ pages.unshift({
163
+ name: 'preview-new',
164
+ path: '/preview-new',
165
+ file: resolver.resolve('runtime/preview.vue')
166
+ })
167
+ })
168
+
169
+ extendRouteRules('/preview', {
170
+ redirect: {
171
+ to: '/preview-new',
172
+ statusCode: 302
173
+ }
174
+ })
175
+
176
+ extendRouteRules('/preview-new', {
177
+ cache: {
178
+ maxAge: 60 * 60 * 24 * 7
179
+ }
180
+ })
181
+ }
182
+ })
183
+ ```
184
+
185
+ ## `addRouteMiddleware`
186
+
187
+ Registers route middlewares to be available for all routes or for specific routes.
188
+
189
+ Route middlewares can be also defined in plugins via [`addRouteMiddleware`](/docs/api/utils/add-route-middleware) composable.
190
+
191
+ ::tip
192
+ Read more about route middlewares in the [Route middleware documentation](/docs/getting-started/routing#route-middleware).
193
+ ::
194
+
195
+ ::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/adding-route-rules-and-route-middlewares?friend=nuxt" target="_blank"}
196
+ Watch Vue School video about adding route rules and route middelwares.
197
+ ::
198
+
199
+ ### Type
200
+
201
+ ```ts
202
+ function addRouteMiddleware (input: NuxtMiddleware | NuxtMiddleware[], options: AddRouteMiddlewareOptions): void
203
+
204
+ type NuxtMiddleware = {
205
+ name: string
206
+ path: string
207
+ global?: boolean
208
+ }
209
+
210
+ interface AddRouteMiddlewareOptions {
211
+ override?: boolean
212
+ prepend?: boolean
213
+ }
214
+ ```
215
+
216
+ ### Parameters
217
+
218
+ #### `input`
219
+
220
+ **Type**: `NuxtMiddleware | NuxtMiddleware[]`
221
+
222
+ **Required**: `true`
223
+
224
+ A middleware object or an array of middleware objects with the following properties:
225
+
226
+ - `name` (required)
227
+
228
+ **Type**: `string`
229
+
230
+ Middleware name.
231
+
232
+ - `path` (required)
233
+
234
+ **Type**: `string`
235
+
236
+ Path to the middleware.
237
+
238
+ - `global` (optional)
239
+
240
+ **Type**: `boolean`
241
+
242
+ If enabled, registers middleware to be available for all routes.
243
+
244
+ #### `options`
245
+
246
+ **Type**: `AddRouteMiddlewareOptions`
247
+
248
+ **Default**: `{}`
249
+
250
+ - `override` (optional)
251
+
252
+ **Type**: `boolean`
253
+
254
+ **Default**: `false`
255
+
256
+ If enabled, overrides the existing middleware with the same name.
257
+
258
+ - `prepend` (optional)
259
+
260
+ **Type**: `boolean`
261
+
262
+ **Default**: `false`
263
+
264
+ If enabled, prepends the middleware to the list of existing middleware.
265
+
266
+ ### Examples
267
+
268
+ ::code-group
269
+
270
+ ```ts [runtime/auth.ts]
271
+ export default defineNuxtRouteMiddleware((to, from) => {
272
+ // isAuthenticated() is an example method verifying if a user is authenticated
273
+ if (to.path !== '/login' && isAuthenticated() === false) {
274
+ return navigateTo('/login')
275
+ }
276
+ })
277
+ ```
278
+
279
+ ```ts [module.ts]
280
+ import { createResolver, defineNuxtModule, addRouteMiddleware } from '@nuxt/kit'
281
+
282
+ export default defineNuxtModule({
283
+ setup() {
284
+ const resolver = createResolver(import.meta.url)
285
+
286
+ addRouteMiddleware({
287
+ name: 'auth',
288
+ path: resolver.resolve('runtime/auth.ts'),
289
+ global: true
290
+ }, { prepend: true })
291
+ }
292
+ })
293
+ ```
294
+
295
+ ::
@@ -0,0 +1,80 @@
1
+ ---
2
+ title: "Layout"
3
+ description: "Nuxt Kit provides a set of utilities to help you work with layouts."
4
+ links:
5
+ - label: Source
6
+ icon: i-simple-icons-github
7
+ to: https://github.com/nuxt/nuxt/blob/main/packages/kit/src/layout.ts
8
+ size: xs
9
+ ---
10
+
11
+ Layouts is used to be a wrapper around your pages. It can be used to wrap your pages with common components, for example, a header and a footer. Layouts can be registered using `addLayout` utility.
12
+
13
+ ## `addLayout`
14
+
15
+ Register template as layout and add it to the layouts.
16
+
17
+ ::note
18
+ In Nuxt 2 `error` layout can also be registered using this utility. In Nuxt 3+ `error` layout [replaced](/docs/getting-started/error-handling#rendering-an-error-page) with `error.vue` page in project root.
19
+ ::
20
+
21
+ ### Type
22
+
23
+ ```ts
24
+ function addLayout (layout: NuxtTemplate | string, name: string): void
25
+
26
+ interface NuxtTemplate {
27
+ src?: string
28
+ filename?: string
29
+ dst?: string
30
+ options?: Record<string, any>
31
+ getContents?: (data: Record<string, any>) => string | Promise<string>
32
+ write?: boolean
33
+ }
34
+ ```
35
+
36
+ ### Parameters
37
+
38
+ #### `layout`
39
+
40
+ **Type**: `NuxtTemplate | string`
41
+
42
+ **Required**: `true`
43
+
44
+ A template object or a string with the path to the template. If a string is provided, it will be converted to a template object with `src` set to the string value. If a template object is provided, it must have the following properties:
45
+
46
+ - `src` (optional)
47
+
48
+ **Type**: `string`
49
+
50
+ Path to the template. If `src` is not provided, `getContents` must be provided instead.
51
+
52
+ - `filename` (optional)
53
+
54
+ **Type**: `string`
55
+
56
+ Filename of the template. If `filename` is not provided, it will be generated from the `src` path. In this case, the `src` option is required.
57
+
58
+ - `dst` (optional)
59
+
60
+ **Type**: `string`
61
+
62
+ Path to the destination file. If `dst` is not provided, it will be generated from the `filename` path and nuxt `buildDir` option.
63
+
64
+ - `options` (optional)
65
+
66
+ **Type**: `Options`
67
+
68
+ Options to pass to the template.
69
+
70
+ - `getContents` (optional)
71
+
72
+ **Type**: `(data: Options) => string | Promise<string>`
73
+
74
+ A function that will be called with the `options` object. It should return a string or a promise that resolves to a string. If `src` is provided, this function will be ignored.
75
+
76
+ - `write` (optional)
77
+
78
+ **Type**: `boolean`
79
+
80
+ If set to `true`, the template will be written to the destination file. Otherwise, the template will be used only in virtual filesystem.
@@ -0,0 +1,263 @@
1
+ ---
2
+ title: Plugins
3
+ description: Nuxt Kit provides a set of utilities to help you create and use plugins. You can add plugins or plugin templates to your module using these functions.
4
+ links:
5
+ - label: Source
6
+ icon: i-simple-icons-github
7
+ to: https://github.com/nuxt/nuxt/blob/main/packages/kit/src/plugin.ts
8
+ size: xs
9
+ ---
10
+
11
+ Plugins are self-contained code that usually add app-level functionality to Vue. In Nuxt, plugins are automatically imported from the `plugins` directory. However, if you need to ship a plugin with your module, Nuxt Kit provides the `addPlugin` and `addPluginTemplate` methods. These utils allow you to customize the plugin configuration to better suit your needs.
12
+
13
+ ## `addPlugin`
14
+
15
+ Registers a Nuxt plugin and to the plugins array.
16
+
17
+ ::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/injecting-plugins?friend=nuxt" target="_blank"}
18
+ Watch Vue School video about addPlugin.
19
+ ::
20
+
21
+ ### Type
22
+
23
+ ```ts
24
+ function addPlugin (plugin: NuxtPlugin | string, options: AddPluginOptions): NuxtPlugin
25
+
26
+ interface NuxtPlugin {
27
+ src: string
28
+ mode?: 'all' | 'server' | 'client'
29
+ order?: number
30
+ }
31
+
32
+ interface AddPluginOptions { append?: boolean }
33
+ ```
34
+
35
+ ### Parameters
36
+
37
+ #### `plugin`
38
+
39
+ **Type**: `NuxtPlugin | string`
40
+
41
+ **Required**: `true`
42
+
43
+ A plugin object or a string with the path to the plugin. If a string is provided, it will be converted to a plugin object with `src` set to the string value. If a plugin object is provided, it must have the following properties:
44
+
45
+ - `src` (required)
46
+
47
+ **Type**: `string`
48
+
49
+ Path to the plugin.
50
+
51
+ - `mode` (optional)
52
+
53
+ **Type**: `'all' | 'server' | 'client'`
54
+
55
+ **Default**: `'all'`
56
+
57
+ If set to `'all'`, the plugin will be included in both client and server bundles. If set to `'server'`, the plugin will only be included in the server bundle. If set to `'client'`, the plugin will only be included in the client bundle. You can also use `.client` and `.server` modifiers when specifying `src` option to use plugin only in client or server side.
58
+
59
+ - `order` (optional)
60
+
61
+ **Type**: `number`
62
+
63
+ **Default**: `0`
64
+
65
+ Order of the plugin. This allows more granular control over plugin order and should only be used by advanced users. Lower numbers run first, and user plugins default to `0`. It's recommended to set `order` to a number between `-20` for `pre`-plugins (plugins that run before Nuxt plugins) and `20` for `post`-plugins (plugins that run after Nuxt plugins).
66
+
67
+ ::warning
68
+ Don't use `order` unless you know what you're doing. For most plugins, the default `order` of `0` is sufficient. To append a plugin to the end of the plugins array, use the `append` option instead.
69
+ ::
70
+
71
+ #### `options`
72
+
73
+ **Type**: `AddPluginOptions`
74
+
75
+ **Default**: `{}`
76
+
77
+ Options to pass to the plugin. If `append` is set to `true`, the plugin will be appended to the plugins array instead of prepended.
78
+
79
+ ### Examples
80
+
81
+ ::code-group
82
+
83
+ ```ts [module.ts]
84
+ import { createResolver, defineNuxtModule, addPlugin } from '@nuxt/kit'
85
+
86
+ export default defineNuxtModule({
87
+ setup() {
88
+ const resolver = createResolver(import.meta.url)
89
+
90
+ addPlugin({
91
+ src: resolver.resolve('runtime/plugin.js'),
92
+ mode: 'client'
93
+ })
94
+ }
95
+ })
96
+ ```
97
+
98
+ ```ts [runtime/plugin.js]
99
+ // https://github.com/nuxt/nuxters
100
+ export default defineNuxtPlugin((nuxtApp) => {
101
+ const colorMode = useColorMode()
102
+
103
+ nuxtApp.hook('app:mounted', () => {
104
+ if (colorMode.preference !== 'dark') {
105
+ colorMode.preference = 'dark'
106
+ }
107
+ })
108
+ })
109
+ ```
110
+
111
+ ::
112
+
113
+ ## `addPluginTemplate`
114
+
115
+ Adds a template and registers as a nuxt plugin. This is useful for plugins that need to generate code at build time.
116
+
117
+ ::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/injecting-plugin-templates?friend=nuxt" target="_blank"}
118
+ Watch Vue School video about addPluginTemplate.
119
+ ::
120
+
121
+ ### Type
122
+
123
+ ```ts
124
+ function addPluginTemplate (pluginOptions: NuxtPluginTemplate, options: AddPluginOptions): NuxtPlugin
125
+
126
+ interface NuxtPluginTemplate<Options = Record<string, any>> {
127
+ src?: string,
128
+ filename?: string,
129
+ dst?: string,
130
+ mode?: 'all' | 'server' | 'client',
131
+ options?: Options,
132
+ getContents?: (data: Options) => string | Promise<string>,
133
+ write?: boolean,
134
+ order?: number
135
+ }
136
+
137
+ interface AddPluginOptions { append?: boolean }
138
+
139
+ interface NuxtPlugin {
140
+ src: string
141
+ mode?: 'all' | 'server' | 'client'
142
+ order?: number
143
+ }
144
+ ```
145
+
146
+ ### Parameters
147
+
148
+ #### `pluginOptions`
149
+
150
+ **Type**: `NuxtPluginTemplate`
151
+
152
+ **Required**: `true`
153
+
154
+ A plugin template object with the following properties:
155
+
156
+ - `src` (optional)
157
+
158
+ **Type**: `string`
159
+
160
+ Path to the template. If `src` is not provided, `getContents` must be provided instead.
161
+
162
+ - `filename` (optional)
163
+
164
+ **Type**: `string`
165
+
166
+ Filename of the template. If `filename` is not provided, it will be generated from the `src` path. In this case, the `src` option is required.
167
+
168
+ - `dst` (optional)
169
+
170
+ **Type**: `string`
171
+
172
+ Path to the destination file. If `dst` is not provided, it will be generated from the `filename` path and nuxt `buildDir` option.
173
+
174
+ - `mode` (optional)
175
+
176
+ **Type**: `'all' | 'server' | 'client'`
177
+
178
+ **Default**: `'all'`
179
+
180
+ If set to `'all'`, the plugin will be included in both client and server bundles. If set to `'server'`, the plugin will only be included in the server bundle. If set to `'client'`, the plugin will only be included in the client bundle. You can also use `.client` and `.server` modifiers when specifying `src` option to use plugin only in client or server side.
181
+
182
+ - `options` (optional)
183
+
184
+ **Type**: `Options`
185
+
186
+ Options to pass to the template.
187
+
188
+ - `getContents` (optional)
189
+
190
+ **Type**: `(data: Options) => string | Promise<string>`
191
+
192
+ A function that will be called with the `options` object. It should return a string or a promise that resolves to a string. If `src` is provided, this function will be ignored.
193
+
194
+ - `write` (optional)
195
+
196
+ **Type**: `boolean`
197
+
198
+ If set to `true`, the template will be written to the destination file. Otherwise, the template will be used only in virtual filesystem.
199
+
200
+ - `order` (optional)
201
+
202
+ **Type**: `number`
203
+
204
+ **Default**: `0`
205
+
206
+ Order of the plugin. This allows more granular control over plugin order and should only be used by advanced users. Lower numbers run first, and user plugins default to `0`. It's recommended to set `order` to a number between `-20` for `pre`-plugins (plugins that run before Nuxt plugins) and `20` for `post`-plugins (plugins that run after Nuxt plugins).
207
+
208
+ ::warning
209
+ Don't use `order` unless you know what you're doing. For most plugins, the default `order` of `0` is sufficient. To append a plugin to the end of the plugins array, use the `append` option instead.
210
+ ::
211
+
212
+ #### `options`
213
+
214
+ **Type**: `AddPluginOptions`
215
+
216
+ **Default**: `{}`
217
+
218
+ Options to pass to the plugin. If `append` is set to `true`, the plugin will be appended to the plugins array instead of prepended.
219
+
220
+ ### Examples
221
+
222
+ ::code-group
223
+
224
+ ```ts [module.ts]
225
+ // https://github.com/vuejs/vuefire
226
+ import { createResolver, defineNuxtModule, addPluginTemplate } from '@nuxt/kit'
227
+
228
+ export default defineNuxtModule({
229
+ setup() {
230
+ const resolver = createResolver(import.meta.url)
231
+
232
+ addPluginTemplate({
233
+ src: resolve(templatesDir, 'plugin.ejs'),
234
+ filename: 'plugin.mjs',
235
+ options: {
236
+ ...options,
237
+ ssr: nuxt.options.ssr,
238
+ },
239
+ })
240
+ }
241
+ })
242
+ ```
243
+
244
+ ```ts [runtime/plugin.ejs]
245
+ import { VueFire, useSSRInitialState } from 'vuefire'
246
+ import { defineNuxtPlugin } from '#imports'
247
+
248
+ export default defineNuxtPlugin((nuxtApp) => {
249
+ const firebaseApp = nuxtApp.$firebaseApp
250
+
251
+ nuxtApp.vueApp.use(VueFire, { firebaseApp })
252
+
253
+ <% if(options.ssr) { %>
254
+ if (import.meta.server) {
255
+ nuxtApp.payload.vuefire = useSSRInitialState(undefined, firebaseApp)
256
+ } else if (nuxtApp.payload?.vuefire) {
257
+ useSSRInitialState(nuxtApp.payload.vuefire, firebaseApp)
258
+ }
259
+ <% } %>
260
+ })
261
+ ```
262
+
263
+ ::
@@ -0,0 +1 @@
1
+ icon: i-lucide-brain