@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,132 @@
1
+ ---
2
+ title: Legacy Composition API
3
+ description: 'Learn how to migrate to Composition API with Nuxt Bridge.'
4
+ ---
5
+
6
+ Nuxt Bridge provides access to Composition API syntax. It is specifically designed to be aligned with Nuxt 3. Because of this, there are a few extra steps to take when enabling Nuxt Bridge, if you have been using the Composition API previously.
7
+
8
+ ## Remove Modules
9
+
10
+ - Remove `@vue/composition-api` from your dependencies.
11
+ - Remove `@nuxtjs/composition-api` from your dependencies (and from your modules in `nuxt.config`).
12
+
13
+ ## Using `@vue/composition-api`
14
+
15
+ If you have been using just `@vue/composition-api` and not `@nuxtjs/composition-api`, then things are very straightforward.
16
+
17
+ 1. First, remove the plugin where you are manually registering the Composition API. Nuxt Bridge will handle this for you.
18
+
19
+ ```diff
20
+ - import Vue from 'vue'
21
+ - import VueCompositionApi from '@vue/composition-api'
22
+ -
23
+ - Vue.use(VueCompositionApi)
24
+ ```
25
+
26
+ 2. Otherwise, there is nothing you need to do. However, if you want, you can remove your explicit imports from `@vue/composition-api` and rely on Nuxt Bridge auto-importing them for you.
27
+
28
+ ## Migrating from `@nuxtjs/composition-api`
29
+
30
+ Nuxt Bridge implements the Composition API slightly differently from `@nuxtjs/composition-api` and provides different composables (designed to be aligned with the composables that Nuxt 3 provides).
31
+
32
+ Because some composables have been removed and don't yet have a replacement, this will be a slightly more complicated process.
33
+
34
+ ### Remove `@nuxtjs/composition-api/module` from your buildModules
35
+
36
+ You don't have to immediately update your imports yet - Nuxt Bridge will automatically provide a 'shim' for most imports you currently have, to give you time to migrate to the new, Nuxt 3-compatible composables, with the following exceptions:
37
+
38
+ - `withContext` has been removed. See [below](/docs/bridge/nuxt3-compatible-api#usecontext-and-withcontext).
39
+ - `useStatic` has been removed. There is no current replacement. Feel free to raise a discussion if you have a use case for this.
40
+ - `reqRef` and `reqSsrRef`, which were deprecated, have now been removed entirely. Follow the instructions below regarding [ssrRef](/docs/bridge/nuxt3-compatible-api#ssrref-and-shallowssrref) to replace this.
41
+
42
+ ### Set `bridge.capi`
43
+
44
+ ```ts
45
+ import { defineNuxtConfig } from '@nuxt/bridge'
46
+
47
+ export default defineNuxtConfig({
48
+ bridge: {
49
+ capi: true,
50
+ nitro: false // If migration to Nitro is complete, set to true
51
+ }
52
+ })
53
+ ```
54
+
55
+ For each other composable you are using from `@nuxtjs/composition-api`, follow the steps below.
56
+
57
+ ### useFetch
58
+
59
+ `$fetchState` and `$fetch` have been removed.
60
+
61
+ ```diff
62
+ const {
63
+ - $fetch,
64
+ - $fetchState,
65
+ + fetch,
66
+ + fetchState,
67
+ } = useFetch(() => { posts.value = await $fetch('/api/posts') })
68
+ ```
69
+
70
+ ### `defineNuxtMiddleware`
71
+
72
+ This was a type-helper stub function that is now removed.
73
+
74
+ Remove the `defineNuxtMiddleware` wrapper:
75
+
76
+ ```diff
77
+ - import { defineNuxtMiddleware } from '@nuxtjs/composition-api`
78
+ - export default defineNuxtMiddleware((ctx) => {})
79
+ + export default (ctx) => {}
80
+ ```
81
+
82
+ For typescript support, you can use `@nuxt/types`:
83
+
84
+ ```ts
85
+ import type { Middleware } from '@nuxt/types'
86
+
87
+ export default <Middleware> function (ctx) { }
88
+ ```
89
+
90
+ ### `defineNuxtPlugin`
91
+
92
+ This was a type-helper stub function that is now removed.
93
+
94
+ You may also keep using Nuxt 2-style plugins, by removing the function (as with [defineNuxtMiddleware](#definenuxtmiddleware)).
95
+
96
+ Remove the `defineNuxtPlugin` wrapper:
97
+
98
+ ```diff
99
+ - import { defineNuxtPlugin } from '@nuxtjs/composition-api'
100
+ - export default defineNuxtPlugin((ctx, inject) => {})
101
+ + export default (ctx, inject) => {}
102
+ ```
103
+
104
+ For typescript support, you can use `@nuxt/types`:
105
+
106
+ ```ts
107
+ import type { Plugin } from '@nuxt/types'
108
+
109
+ export default <Plugin> function (ctx, inject) {}
110
+ ```
111
+
112
+ ::warning
113
+ While this example is valid, Nuxt 3 introduces a new defineNuxtPlugin function that has a slightly different signature.
114
+ ::
115
+
116
+ :ReadMore{link="/docs/guide/directory-structure/plugins#creating-plugins"}
117
+
118
+ ### `useRouter` and `useRoute`
119
+
120
+ Nuxt Bridge provides direct replacements for these composables via [`useRouter`](/docs/api/composables/use-router) and `useRoute`.
121
+
122
+ The only key difference is that [`useRoute`](/docs/api/composables/use-route) no longer returns a computed property.
123
+
124
+ ```diff
125
+ - import { useRouter, useRoute } from '@nuxtjs/composition-api'
126
+
127
+ const router = useRouter()
128
+ const route = useRoute()
129
+
130
+ - console.log(route.value.path)
131
+ + console.log(route.path)
132
+ ```
@@ -0,0 +1,65 @@
1
+ ---
2
+ title: Plugins and Middleware
3
+ description: 'Learn how to migrate from Nuxt 2 to Nuxt Bridge new plugins and middleware.'
4
+ ---
5
+
6
+ ## New Plugins Format
7
+
8
+ You can now migrate to the Nuxt 3 plugins API, which is slightly different in format from Nuxt 2.
9
+
10
+ Plugins now take only one argument (`nuxtApp`). You can find out more in [the docs](/docs/guide/directory-structure/plugins).
11
+
12
+ ```js [plugins/hello.ts]
13
+ export default defineNuxtPlugin(nuxtApp => {
14
+ nuxtApp.provide('injected', () => 'my injected function')
15
+ // now available on `nuxtApp.$injected`
16
+ })
17
+ ```
18
+
19
+ ::note
20
+ If you want to use the new Nuxt composables (such as [`useNuxtApp`](/docs/api/composables/use-nuxt-app) or `useRuntimeConfig`) within your plugins, you will need to use the `defineNuxtPlugin` helper for those plugins.
21
+ ::
22
+
23
+ ::warning
24
+ Although a compatibility interface is provided via `nuxtApp.vueApp` you should avoid registering plugins, directives, mixins or components this way without adding your own logic to ensure they are not installed more than once, or this may cause a memory leak.
25
+ ::
26
+
27
+ ## New Middleware Format
28
+
29
+ You can now migrate to the Nuxt 3 middleware API, which is slightly different in format from Nuxt 2.
30
+
31
+ Middleware now take only two argument (`to`, `from`). You can find out more in [the docs](/docs/guide/directory-structure/middleware).
32
+
33
+ ```ts twoslash
34
+ export default defineNuxtRouteMiddleware((to) => {
35
+ if (to.path !== '/') {
36
+ return navigateTo('/')
37
+ }
38
+ })
39
+ ```
40
+
41
+ ::important
42
+ Use of `defineNuxtRouteMiddleware` is not supported outside of the middleware directory.
43
+ ::
44
+
45
+ ## definePageMeta
46
+
47
+ You can also use [`definePageMeta`](/docs/api/utils/define-page-meta) in Nuxt Bridge.
48
+
49
+ You can be enabled with the `macros.pageMeta` option in your configuration file
50
+
51
+ ```ts [nuxt.config.ts]
52
+ import { defineNuxtConfig } from '@nuxt/bridge'
53
+
54
+ export default defineNuxtConfig({
55
+ bridge: {
56
+ macros: {
57
+ pageMeta: true
58
+ }
59
+ }
60
+ })
61
+ ```
62
+
63
+ ::note
64
+ But only for `middleware` and `layout`.
65
+ ::
@@ -0,0 +1,204 @@
1
+ ---
2
+ title: New Composition API
3
+ description: Nuxt Bridge implements composables compatible with Nuxt 3.
4
+ ---
5
+
6
+ By migrating from `@nuxtjs/composition-api` to the Nuxt 3 compatible API, there will be less rewriting when migrating to Nuxt 3.
7
+
8
+ ## `ssrRef` and `shallowSsrRef`
9
+
10
+ These two functions have been replaced with a new composable that works very similarly under the hood: `useState`.
11
+
12
+ The key differences are that you must provide a _key_ for this state (which Nuxt generated automatically for `ssrRef` and `shallowSsrRef`), and that it can only be called within a Nuxt 3 plugin (which is defined by `defineNuxtPlugin`) or a component instance. (In other words, you cannot use [`useState`](/docs/api/composables/use-state) with a global/ambient context, because of the danger of shared state across requests.)
13
+
14
+ ```diff
15
+ - import { ssrRef } from '@nuxtjs/composition-api'
16
+
17
+ - const ref1 = ssrRef('initialData')
18
+ - const ref2 = ssrRef(() => 'factory function')
19
+ + const ref1 = useState('ref1-key', () => 'initialData')
20
+ + const ref2 = useState('ref2-key', () => 'factory function')
21
+ // accessing the state
22
+ console.log(ref1.value)
23
+ ```
24
+
25
+ Because the state is keyed, you can access the same state from multiple locations, as long as you are using the same key.
26
+
27
+ You can read more about how to use this composable in [the Nuxt 3 docs](/docs/api/composables/use-state).
28
+
29
+ ## `ssrPromise`
30
+
31
+ This function has been removed, and you will need to find an alternative implementation if you were using it. If you have a use case for `ssrPromise`, please let us know via a discussion.
32
+
33
+ ## `onGlobalSetup`
34
+
35
+ This function has been removed, but its use cases can be met by using [`useNuxtApp`](/docs/api/composables/use-nuxt-app) or [`useState`](/docs/api/composables/use-state) within `defineNuxtPlugin`. You can also run any custom code within the `setup()` function of a layout.
36
+
37
+ ```diff
38
+ - import { onGlobalSetup } from '@nuxtjs/composition-api'
39
+
40
+ - export default () => {
41
+ - onGlobalSetup(() => {
42
+ + export default defineNuxtPlugin((nuxtApp) => {
43
+ + nuxtApp.hook('vue:setup', () => {
44
+ // ...
45
+ })
46
+ - }
47
+ + })
48
+ ```
49
+
50
+ ## `useStore`
51
+
52
+ In order to access Vuex store instance, you can use `useNuxtApp().$store`.
53
+
54
+ ```diff
55
+ - import { useStore } from '@nuxtjs/composition-api`
56
+ + const { $store } = useNuxtApp()
57
+ ```
58
+
59
+ ## `useContext` and `withContext`
60
+
61
+ You can access injected helpers using `useNuxtApp`.
62
+
63
+ ```diff
64
+ - import { useContext } from '@nuxtjs/composition-api`
65
+ + const { $axios } = useNuxtApp()
66
+ ```
67
+
68
+ ::note
69
+ `useNuxtApp()` also provides a key called `nuxt2Context` which contains all the same properties you would normally access from Nuxt 2 context, but it's advised _not_ to use this directly, as it won't exist in Nuxt 3. Instead, see if there is another way to access what you need. (If not, please raise a feature request or discussion.)
70
+ ::
71
+
72
+ ## `wrapProperty`
73
+
74
+ This helper function is not provided any more but you can replace it with the following code:
75
+
76
+ ```js
77
+ const wrapProperty = (property, makeComputed = true) => () => {
78
+ const vm = getCurrentInstance().proxy
79
+ return makeComputed ? computed(() => vm[property]) : vm[property]
80
+ }
81
+ ```
82
+
83
+ ## `useAsync` and `useFetch`
84
+
85
+ These two composables can be replaced with `useLazyAsyncData` and `useLazyFetch`, which are documented [in the Nuxt 3 docs](/docs/getting-started/data-fetching). Just like the previous `@nuxtjs/composition-api` composables, these composables do not block route navigation on the client-side (hence the 'lazy' part of the name).
86
+
87
+ ::important
88
+ Note that the API is entirely different, despite similar sounding names. Importantly, you should not attempt to change the value of other variables outside the composable (as you may have been doing with the previous `useFetch`).
89
+ ::
90
+
91
+ ::warning
92
+ The `useLazyFetch` must have been configured for [Nitro](/docs/bridge/nitro).
93
+ ::
94
+
95
+ Migrating to the new composables from `useAsync`:
96
+
97
+ ```diff
98
+ <script setup>
99
+ - import { useAsync } from '@nuxtjs/composition-api'
100
+ - const posts = useAsync(() => $fetch('/api/posts'))
101
+ + const { data: posts } = useLazyAsyncData('posts', () => $fetch('/api/posts'))
102
+ + // or, more simply!
103
+ + const { data: posts } = useLazyFetch('/api/posts')
104
+ </script>
105
+ ```
106
+
107
+ Migrating to the new composables from `useFetch`:
108
+
109
+ ```diff
110
+ <script setup>
111
+ - import { useFetch } from '@nuxtjs/composition-api'
112
+ - const posts = ref([])
113
+ - const { fetch } = useFetch(() => { posts.value = await $fetch('/api/posts') })
114
+ + const { data: posts, refresh } = useLazyAsyncData('posts', () => $fetch('/api/posts'))
115
+ + // or, more simply!
116
+ + const { data: posts, refresh } = useLazyFetch('/api/posts')
117
+ function updatePosts() {
118
+ - return fetch()
119
+ + return refresh()
120
+ }
121
+ </script>
122
+ ```
123
+
124
+ ### `useMeta`
125
+
126
+ In order to interact with `vue-meta`, you may use `useNuxt2Meta`, which will work in Nuxt Bridge (but not Nuxt 3) and will allow you to manipulate your meta tags in a `vue-meta`-compatible way.
127
+
128
+ ```diff
129
+ <script setup>
130
+ - import { useMeta } from '@nuxtjs/composition-api'
131
+ useNuxt2Meta({
132
+ title: 'My Nuxt App',
133
+ })
134
+ </script>
135
+ ```
136
+
137
+ You can also pass in computed values or refs, and the meta values will be updated reactively:
138
+
139
+ ```ts
140
+ <script setup>
141
+ const title = ref('my title')
142
+ useNuxt2Meta({
143
+ title,
144
+ })
145
+ title.value = 'new title'
146
+ </script>
147
+ ```
148
+
149
+ ::note
150
+ Be careful not to use both `useNuxt2Meta()` and the Options API `head()` within the same component, as behavior may be unpredictable.
151
+ ::
152
+
153
+ Nuxt Bridge also provides a Nuxt 3-compatible meta implementation that can be accessed with the [`useHead`](/docs/api/composables/use-head) composable.
154
+
155
+ ```diff
156
+ <script setup>
157
+ - import { useMeta } from '@nuxtjs/composition-api'
158
+ useHead({
159
+ title: 'My Nuxt App',
160
+ })
161
+ </script>
162
+ ```
163
+
164
+ You will also need to enable it explicitly in your `nuxt.config`:
165
+
166
+ ```js
167
+ import { defineNuxtConfig } from '@nuxt/bridge'
168
+ export default defineNuxtConfig({
169
+ bridge: {
170
+ meta: true
171
+ }
172
+ })
173
+ ```
174
+
175
+ This [`useHead`](/docs/api/composables/use-head) composable uses `@unhead/vue` under the hood (rather than `vue-meta`) to manipulate your `<head>`. Accordingly, it is recommended not to use both the native Nuxt 2 `head()` properties as well as [`useHead`](/docs/api/composables/use-head) , as they may conflict.
176
+
177
+ For more information on how to use this composable, see [the Nuxt 3 docs](/docs/getting-started/seo-meta).
178
+
179
+ ### Explicit Imports
180
+
181
+ Nuxt exposes every auto-import with the `#imports` alias that can be used to make the import explicit if needed:
182
+
183
+ ```vue
184
+ <script setup lang="ts">
185
+ import { ref, computed } from '#imports'
186
+
187
+ const count = ref(1)
188
+ const double = computed(() => count.value * 2)
189
+ </script>
190
+ ```
191
+
192
+ ### Disabling Auto-imports
193
+
194
+ If you want to disable auto-importing composables and utilities, you can set `imports.autoImport` to `false` in the `nuxt.config` file.
195
+
196
+ ```ts [nuxt.config.ts]
197
+ export default defineNuxtConfig({
198
+ imports: {
199
+ autoImport: false
200
+ }
201
+ })
202
+ ```
203
+
204
+ This will disable auto-imports completely but it's still possible to use [explicit imports](#explicit-imports) from `#imports`.
@@ -0,0 +1,117 @@
1
+ ---
2
+ title: Meta Tags
3
+ description: 'Learn how to migrate from Nuxt 2 to Nuxt Bridge new meta tags.'
4
+ ---
5
+
6
+ If you need to access the component state with `head`, you should migrate to using [`useHead`](/docs/api/composables/use-head) .
7
+
8
+ If you need to use the Options API, there is a `head()` method you can use when you use `defineNuxtComponent`.
9
+
10
+ ## Migration
11
+
12
+ ### Set `bridge.meta`
13
+
14
+ ```js
15
+ import { defineNuxtConfig } from '@nuxt/bridge'
16
+ export default defineNuxtConfig({
17
+ bridge: {
18
+ meta: true,
19
+ nitro: false // If migration to Nitro is complete, set to true
20
+ }
21
+ })
22
+ ```
23
+
24
+ ### Update head properties
25
+
26
+ In your `nuxt.config`, rename `head` to `meta`. (Note that objects no longer have a `hid` key for deduplication.)
27
+
28
+ ::code-group
29
+
30
+ ```ts [Nuxt 2]
31
+ export default {
32
+ head: {
33
+ titleTemplate: '%s - Nuxt',
34
+ meta: [
35
+ { charset: 'utf-8' },
36
+ { name: 'viewport', content: 'width=device-width, initial-scale=1' },
37
+ { hid: 'description', name: 'description', content: 'Meta description' }
38
+ ]
39
+ }
40
+ }
41
+ ```
42
+
43
+ ```ts [Nuxt 3]
44
+ export default defineNuxtConfig({
45
+ app: {
46
+ head: {
47
+ titleTemplate: '%s - Nuxt',
48
+ meta: [
49
+ { charset: 'utf-8' },
50
+ { name: 'viewport', content: 'width=device-width, initial-scale=1' },
51
+ { name: 'description', content: 'Meta description' }
52
+ ]
53
+ }
54
+ }
55
+ })
56
+ ```
57
+
58
+ ::
59
+
60
+ ## `useHead` Composables
61
+
62
+ Nuxt Bridge provides a new Nuxt 3 meta API that can be accessed with a new [`useHead`](/docs/api/composables/use-head) composable.
63
+
64
+ ```vue
65
+ <script setup lang="ts">
66
+ useHead({
67
+ title: 'My Nuxt App',
68
+ })
69
+ </script>
70
+ ```
71
+
72
+ ::tip
73
+ This [`useHead`](/docs/api/composables/use-head) composable uses `@unhead/vue` under the hood (rather than `vue-meta`) to manipulate your `<head>`.
74
+ ::
75
+
76
+ ::warning
77
+ We recommend not using the native Nuxt 2 `head()` properties in addition to [`useHead`](/docs/api/composables/use-head) , as they may conflict.
78
+ ::
79
+
80
+ For more information on how to use this composable, see [the docs](/docs/getting-started/seo-meta).
81
+
82
+ ## Options API
83
+
84
+ ```vue
85
+ <script>
86
+ // if using options API `head` method you must use `defineNuxtComponent`
87
+ export default defineNuxtComponent({
88
+ head (nuxtApp) {
89
+ // `head` receives the nuxt app but cannot access the component instance
90
+ return {
91
+ meta: [{
92
+ name: 'description',
93
+ content: 'This is my page description.'
94
+ }]
95
+ }
96
+ }
97
+ })
98
+ </script>
99
+ ```
100
+
101
+ ::warning
102
+ Possible breaking change: `head` receives the nuxt app but cannot access the component instance. If the code in your `head` tries to access the data object through `this` or `this.$data`, you will need to migrate to the `useHead` composable.
103
+ ::
104
+
105
+ ## Title Template
106
+
107
+ If you want to use a function (for full control), then this cannot be set in your nuxt.config, and it is recommended instead to set it within your `/layouts` directory.
108
+
109
+ ```vue [layouts/default.vue]
110
+ <script setup lang="ts">
111
+ useHead({
112
+ titleTemplate: (titleChunk) => {
113
+ return titleChunk ? `${titleChunk} - Site Title` : 'Site Title';
114
+ }
115
+ })
116
+ </script>
117
+ ```
@@ -0,0 +1,38 @@
1
+ ---
2
+ title: Runtime Config
3
+ description: 'Nuxt provides a runtime config API to expose configuration and secrets within your application.'
4
+ ---
5
+
6
+ ::warning
7
+ When using `runtimeConfig` option, [nitro](/docs/bridge/nitro) must have been configured.
8
+ ::
9
+
10
+ ## Update Runtime Config
11
+
12
+ Nuxt 3 approaches runtime config differently than Nuxt 2, using a new combined `runtimeConfig` option.
13
+
14
+ First, you'll need to combine your `publicRuntimeConfig` and `privateRuntimeConfig` properties into a new one called `runtimeConfig`, with the public config within a key called `public`.
15
+
16
+ ```diff
17
+ // nuxt.config.js
18
+ - privateRuntimeConfig: {
19
+ - apiKey: process.env.NUXT_API_KEY || 'super-secret-key'
20
+ - },
21
+ - publicRuntimeConfig: {
22
+ - websiteURL: 'https://public-data.com'
23
+ - }
24
+ + runtimeConfig: {
25
+ + apiKey: process.env.NUXT_API_KEY || 'super-secret-key',
26
+ + public: {
27
+ + websiteURL: 'https://public-data.com'
28
+ + }
29
+ + }
30
+ ```
31
+
32
+ This also means that when you need to access public runtime config, it's behind a property called `public`. If you use public runtime config, you'll need to update your code.
33
+
34
+ ```diff
35
+ // MyWidget.vue
36
+ - <div>Website: {{ $config.websiteURL }}</div>
37
+ + <div>Website: {{ $config.public.websiteURL }}</div>
38
+ ```
@@ -0,0 +1,102 @@
1
+ ---
2
+ title: Nitro
3
+ description: 'Activate Nitro to your Nuxt 2 application with Nuxt Bridge.'
4
+ ---
5
+
6
+ ## Remove Modules
7
+
8
+ - Remove `@nuxt/nitro`: Bridge injects same functionality
9
+
10
+ ## Update Config
11
+
12
+ ```ts [nuxt.config.ts]
13
+ import { defineNuxtConfig } from '@nuxt/bridge'
14
+
15
+ export default defineNuxtConfig({
16
+ bridge: {
17
+ nitro: true
18
+ }
19
+ })
20
+ ```
21
+
22
+ ## Update Your Scripts
23
+
24
+ You will also need to update your scripts within your `package.json` to reflect the fact that Nuxt will now produce a Nitro server as build output.
25
+
26
+ ### Install Nuxi
27
+
28
+ Install `nuxi` as a development dependency:
29
+
30
+ ::code-group{sync="pm"}
31
+
32
+ ```bash [npm]
33
+ npm install -D nuxi
34
+ ```
35
+
36
+ ```bash [yarn]
37
+ yarn add --dev nuxi
38
+ ```
39
+
40
+ ```bash [pnpm]
41
+ pnpm add -D nuxi
42
+ ```
43
+
44
+ ```bash [bun]
45
+ bun add -D nuxi
46
+ ```
47
+
48
+ ::
49
+
50
+ ### Nuxi
51
+
52
+ Nuxt 3 introduced the new Nuxt CLI command [`nuxi`](/docs/api/commands/add). Update your scripts as follows to leverage the better support from Nuxt Bridge:
53
+
54
+ ```diff
55
+ {
56
+ "scripts": {
57
+ - "dev": "nuxt",
58
+ + "dev": "nuxi dev",
59
+ - "build": "nuxt build",
60
+ + "build": "nuxi build",
61
+ - "start": "nuxt start",
62
+ + "start": "nuxi preview"
63
+ }
64
+ }
65
+ ```
66
+
67
+ ::tip
68
+ If `nitro: false`, use the `nuxt2` command.
69
+ ::
70
+
71
+ ### Static Target
72
+
73
+ If you have set `target: 'static'` in your `nuxt.config` then you need to ensure that you update your build script to be `nuxi generate`.
74
+
75
+ ```json [package.json]
76
+ {
77
+ "scripts": {
78
+ "build": "nuxi generate"
79
+ }
80
+ }
81
+ ```
82
+
83
+ ### Server Target
84
+
85
+ For all other situations, you can use the `nuxi build` command.
86
+
87
+ ```json [package.json]
88
+ {
89
+ "scripts": {
90
+ "build": "nuxi build",
91
+ "start": "nuxi preview"
92
+ }
93
+ }
94
+ ```
95
+
96
+ ## Exclude Built Nitro Folder From Git
97
+
98
+ Add the folder `.output` to the `.gitignore` file.
99
+
100
+ ## Ensure Everything Goes Well
101
+
102
+ ✔️ Try with `nuxi dev` and `nuxi build` (or `nuxi generate`) to see if everything goes well.
@@ -0,0 +1,37 @@
1
+ ---
2
+ title: Vite
3
+ description: 'Activate Vite to your Nuxt 2 application with Nuxt Bridge.'
4
+ ---
5
+
6
+ ::warning
7
+ When using `vite`, [nitro](/docs/bridge/nitro) must have been configured.
8
+ ::
9
+
10
+ ## Remove Modules
11
+
12
+ - Remove `nuxt-vite`: Bridge enables same functionality
13
+
14
+ ## Update Config
15
+
16
+ ```ts [nuxt.config.ts]
17
+ import { defineNuxtConfig } from '@nuxt/bridge'
18
+
19
+ export default defineNuxtConfig({
20
+ bridge: {
21
+ vite: true,
22
+ nitro: true
23
+ }
24
+ })
25
+ ```
26
+
27
+ ## Configuration
28
+
29
+ ```ts [nuxt.config.ts]
30
+ import { defineNuxtConfig } from '@nuxt/bridge'
31
+
32
+ export default defineNuxtConfig({
33
+ vite: {
34
+ // Config for Vite
35
+ }
36
+ })
37
+ ```
@@ -0,0 +1,3 @@
1
+ title: 'Migrate to Nuxt 3'
2
+ titleTemplate: 'Migrate to Nuxt 3: %s'
3
+ icon: i-lucide-circle-arrow-up