@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,299 @@
1
+ ---
2
+ title: "plugins"
3
+ description: "Nuxt has a plugins system to use Vue plugins and more at the creation of your Vue application."
4
+ head.title: "plugins/"
5
+ navigation.icon: i-lucide-folder
6
+ ---
7
+
8
+ Nuxt automatically reads the files in the `plugins/` directory and loads them at the creation of the Vue application.
9
+
10
+ ::note
11
+ All plugins inside are auto-registered, you don't need to add them to your `nuxt.config` separately.
12
+ ::
13
+
14
+ ::note
15
+ You can use `.server` or `.client` suffix in the file name to load a plugin only on the server or client side.
16
+ ::
17
+
18
+ ## Registered Plugins
19
+
20
+ Only files at the top level of the directory (or index files within any subdirectories) will be auto-registered as plugins.
21
+
22
+ ```bash [Directory structure]
23
+ -| plugins/
24
+ ---| foo.ts // scanned
25
+ ---| bar/
26
+ -----| baz.ts // not scanned
27
+ -----| foz.vue // not scanned
28
+ -----| index.ts // currently scanned but deprecated
29
+ ```
30
+
31
+ Only `foo.ts` and `bar/index.ts` would be registered.
32
+
33
+ To add plugins in subdirectories, you can use the [`plugins`](/docs/api/nuxt-config#plugins-1) option in `nuxt.config.ts`:
34
+
35
+ ```ts twoslash [nuxt.config.ts]
36
+ export default defineNuxtConfig({
37
+ plugins: [
38
+ '~/plugins/bar/baz',
39
+ '~/plugins/bar/foz'
40
+ ]
41
+ })
42
+ ```
43
+
44
+ ## Creating Plugins
45
+
46
+ The only argument passed to a plugin is [`nuxtApp`](/docs/api/composables/use-nuxt-app).
47
+
48
+ ```ts twoslash [plugins/hello.ts]
49
+ export default defineNuxtPlugin(nuxtApp => {
50
+ // Doing something with nuxtApp
51
+ })
52
+ ```
53
+
54
+ ### Object Syntax Plugins
55
+
56
+ It is also possible to define a plugin using an object syntax, for more advanced use cases. For example:
57
+
58
+ ```ts twoslash [plugins/hello.ts]
59
+ export default defineNuxtPlugin({
60
+ name: 'my-plugin',
61
+ enforce: 'pre', // or 'post'
62
+ async setup (nuxtApp) {
63
+ // this is the equivalent of a normal functional plugin
64
+ },
65
+ hooks: {
66
+ // You can directly register Nuxt app runtime hooks here
67
+ 'app:created'() {
68
+ const nuxtApp = useNuxtApp()
69
+ // do something in the hook
70
+ }
71
+ },
72
+ env: {
73
+ // Set this value to `false` if you don't want the plugin to run when rendering server-only or island components.
74
+ islands: true
75
+ }
76
+ })
77
+ ```
78
+
79
+ :video-accordion{title="Watch a video from Alexander Lichter about the Object Syntax for Nuxt plugins" videoId="2aXZyXB1QGQ"}
80
+
81
+ ::note
82
+ If you are using the object-syntax, the properties are statically analyzed to produce a more optimized build. So you should not define them at runtime. :br
83
+ For example, setting `enforce: import.meta.server ? 'pre' : 'post'` would defeat any future optimization Nuxt is able to do for your plugins.
84
+ Nuxt does statically pre-load any hook listeners when using object-syntax, allowing you to define hooks without needing to worry about order of plugin registration.
85
+ ::
86
+
87
+ ## Registration Order
88
+
89
+ You can control the order in which plugins are registered by prefixing with 'alphabetical' numbering to the file names.
90
+
91
+ ```bash [Directory structure]
92
+ plugins/
93
+ | - 01.myPlugin.ts
94
+ | - 02.myOtherPlugin.ts
95
+ ```
96
+
97
+ In this example, `02.myOtherPlugin.ts` will be able to access anything that was injected by `01.myPlugin.ts`.
98
+
99
+ This is useful in situations where you have a plugin that depends on another plugin.
100
+
101
+ ::note
102
+ In case you're new to 'alphabetical' numbering, remember that filenames are sorted as strings, not as numeric values. For example, `10.myPlugin.ts` would come before `2.myOtherPlugin.ts`. This is why the example prefixes single digit numbers with `0`.
103
+ ::
104
+
105
+ ## Loading Strategy
106
+
107
+ ### Parallel Plugins
108
+
109
+ By default, Nuxt loads plugins sequentially. You can define a plugin as `parallel` so Nuxt won't wait until the end of the plugin's execution before loading the next plugin.
110
+
111
+ ```ts twoslash [plugins/my-plugin.ts]
112
+ export default defineNuxtPlugin({
113
+ name: 'my-plugin',
114
+ parallel: true,
115
+ async setup (nuxtApp) {
116
+ // the next plugin will be executed immediately
117
+ }
118
+ })
119
+ ```
120
+
121
+ ### Plugins With Dependencies
122
+
123
+ If a plugin needs to wait for another plugin before it runs, you can add the plugin's name to the `dependsOn` array.
124
+
125
+ ```ts twoslash [plugins/depending-on-my-plugin.ts]
126
+ export default defineNuxtPlugin({
127
+ name: 'depends-on-my-plugin',
128
+ dependsOn: ['my-plugin'],
129
+ async setup (nuxtApp) {
130
+ // this plugin will wait for the end of `my-plugin`'s execution before it runs
131
+ }
132
+ })
133
+ ```
134
+
135
+ ## Using Composables
136
+
137
+ You can use [composables](/docs/guide/directory-structure/composables) as well as [utils](/docs/guide/directory-structure/utils) within Nuxt plugins:
138
+
139
+ ```ts [plugins/hello.ts]
140
+ export default defineNuxtPlugin((nuxtApp) => {
141
+ const foo = useFoo()
142
+ })
143
+ ```
144
+
145
+ However, keep in mind there are some limitations and differences:
146
+
147
+ ::important
148
+ **If a composable depends on another plugin registered later, it might not work.** :br
149
+
150
+ Plugins are called in order sequentially and before everything else. You might use a composable that depends on another plugin which has not been called yet.
151
+ ::
152
+
153
+ ::important
154
+ **If a composable depends on the Vue.js lifecycle, it won't work.** :br
155
+
156
+ Normally, Vue.js composables are bound to the current component instance while plugins are only bound to [`nuxtApp`](/docs/api/composables/use-nuxt-app) instance.
157
+ ::
158
+
159
+ ## Providing Helpers
160
+
161
+ If you would like to provide a helper on the [`NuxtApp`](/docs/api/composables/use-nuxt-app) instance, return it from the plugin under a `provide` key.
162
+
163
+ ::code-group
164
+ ```ts twoslash [plugins/hello.ts]
165
+ export default defineNuxtPlugin(() => {
166
+ return {
167
+ provide: {
168
+ hello: (msg: string) => `Hello ${msg}!`
169
+ }
170
+ }
171
+ })
172
+ ```
173
+ ```ts twoslash [plugins/hello-object-syntax.ts]
174
+ export default defineNuxtPlugin({
175
+ name: 'hello',
176
+ setup () {
177
+ return {
178
+ provide: {
179
+ hello: (msg: string) => `Hello ${msg}!`
180
+ }
181
+ }
182
+ }
183
+ })
184
+ ```
185
+ ::
186
+
187
+ You can then use the helper in your components:
188
+
189
+ ```vue [components/Hello.vue]
190
+ <script setup lang="ts">
191
+ // alternatively, you can also use it here
192
+ const { $hello } = useNuxtApp()
193
+ </script>
194
+
195
+ <template>
196
+ <div>
197
+ {{ $hello('world') }}
198
+ </div>
199
+ </template>
200
+ ```
201
+
202
+ ::important
203
+ Note that we highly recommend using [`composables`](/docs/guide/directory-structure/composables) instead of providing helpers to avoid polluting the global namespace and keep your main bundle entry small.
204
+ ::
205
+
206
+ ::warning
207
+ **If your plugin provides a `ref` or `computed`, it will not be unwrapped in a component `<template>`.** :br
208
+ This is due to how Vue works with refs that aren't top-level to the template. You can read more about it [in the Vue documentation](https://vuejs.org/guide/essentials/reactivity-fundamentals.html#caveat-when-unwrapping-in-templates).
209
+ ::
210
+
211
+ ## Typing Plugins
212
+
213
+ If you return your helpers from the plugin, they will be typed automatically; you'll find them typed for the return of `useNuxtApp()` and within your templates.
214
+
215
+ ::note
216
+ If you need to use a provided helper _within_ another plugin, you can call [`useNuxtApp()`](/docs/api/composables/use-nuxt-app) to get the typed version. But in general, this should be avoided unless you are certain of the plugins' order.
217
+ ::
218
+
219
+ For advanced use-cases, you can declare the type of injected properties like this:
220
+
221
+ ```ts [index.d.ts]
222
+ declare module '#app' {
223
+ interface NuxtApp {
224
+ $hello (msg: string): string
225
+ }
226
+ }
227
+
228
+ declare module 'vue' {
229
+ interface ComponentCustomProperties {
230
+ $hello (msg: string): string
231
+ }
232
+ }
233
+
234
+ export {}
235
+ ```
236
+
237
+ ::note
238
+ If you are using WebStorm, you may need to augment `@vue/runtime-core` until [this issue](https://youtrack.jetbrains.com/issue/WEB-59818/VUE-TypeScript-WS-PS-does-not-correctly-display-type-of-globally-injected-properties) is resolved.
239
+ ::
240
+
241
+ ## Vue Plugins
242
+
243
+ If you want to use Vue plugins, like [vue-gtag](https://github.com/MatteoGabriele/vue-gtag) to add Google Analytics tags, you can use a Nuxt plugin to do so.
244
+
245
+ First, install the Vue plugin dependency:
246
+
247
+ ::code-group{sync="pm"}
248
+ ```bash [npm]
249
+ npm install --save-dev vue-gtag-next
250
+ ```
251
+ ```bash [yarn]
252
+ yarn add --dev vue-gtag-next
253
+ ```
254
+ ```bash [pnpm]
255
+ pnpm add -D vue-gtag-next
256
+ ```
257
+ ```bash [bun]
258
+ bun add -D vue-gtag-next
259
+ ```
260
+ ::
261
+
262
+ Then create a plugin file:
263
+
264
+ ```ts [plugins/vue-gtag.client.ts]
265
+ import VueGtag, { trackRouter } from 'vue-gtag-next'
266
+
267
+ export default defineNuxtPlugin((nuxtApp) => {
268
+ nuxtApp.vueApp.use(VueGtag, {
269
+ property: {
270
+ id: 'GA_MEASUREMENT_ID'
271
+ }
272
+ })
273
+ trackRouter(useRouter())
274
+ })
275
+ ```
276
+
277
+ ## Vue Directives
278
+
279
+ Similarly, you can register a custom Vue directive in a plugin.
280
+
281
+ ```ts twoslash [plugins/my-directive.ts]
282
+ export default defineNuxtPlugin((nuxtApp) => {
283
+ nuxtApp.vueApp.directive('focus', {
284
+ mounted (el) {
285
+ el.focus()
286
+ },
287
+ getSSRProps (binding, vnode) {
288
+ // you can provide SSR-specific props here
289
+ return {}
290
+ }
291
+ })
292
+ })
293
+ ```
294
+
295
+ ::warning
296
+ If you register a Vue directive, you _must_ register it on both client and server side unless you are only using it when rendering one side. If the directive only makes sense from a client side, you can always move it to `~/plugins/my-directive.client.ts` and provide a 'stub' directive for the server in `~/plugins/my-directive.server.ts`.
297
+ ::
298
+
299
+ :read-more{icon="i-simple-icons-vuedotjs" title="Custom Directives on Vue Docs" to="https://vuejs.org/guide/reusability/custom-directives.html" target="_blank"}
@@ -0,0 +1,27 @@
1
+ ---
2
+ title: "public"
3
+ description: "The public/ directory is used to serve your website's static assets."
4
+ head.title: "public/"
5
+ navigation.icon: i-lucide-folder
6
+ ---
7
+
8
+ Files contained within the `public/` directory are served at the root and are not modified by the build process. This is suitable for files that have to keep their names (e.g. `robots.txt`) _or_ likely won't change (e.g. `favicon.ico`).
9
+
10
+ ```bash [Directory structure]
11
+ -| public/
12
+ ---| favicon.ico
13
+ ---| og-image.png
14
+ ---| robots.txt
15
+ ```
16
+
17
+ ```vue [app.vue]
18
+ <script setup lang="ts">
19
+ useSeoMeta({
20
+ ogImage: '/og-image.png'
21
+ })
22
+ </script>
23
+ ```
24
+
25
+ ::tip{to="https://v2.nuxt.com/docs/directory-structure/static" target="_blank"}
26
+ This is known as the [`static/`] directory in Nuxt 2.
27
+ ::