@nuxt/docs 0.0.0 → 3.17.1
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.
- package/.navigation.yml +2 -0
- package/1.getting-started/.navigation.yml +3 -0
- package/1.getting-started/01.introduction.md +81 -0
- package/1.getting-started/02.installation.md +109 -0
- package/1.getting-started/03.configuration.md +226 -0
- package/1.getting-started/04.views.md +163 -0
- package/1.getting-started/05.assets.md +48 -0
- package/1.getting-started/06.styling.md +565 -0
- package/1.getting-started/07.routing.md +149 -0
- package/1.getting-started/08.seo-meta.md +360 -0
- package/1.getting-started/09.transitions.md +473 -0
- package/1.getting-started/10.data-fetching.md +795 -0
- package/1.getting-started/11.state-management.md +223 -0
- package/1.getting-started/12.error-handling.md +233 -0
- package/1.getting-started/13.server.md +94 -0
- package/1.getting-started/14.layers.md +92 -0
- package/1.getting-started/15.prerendering.md +194 -0
- package/1.getting-started/16.deployment.md +130 -0
- package/1.getting-started/17.testing.md +728 -0
- package/1.getting-started/18.upgrade.md +997 -0
- package/2.guide/.navigation.yml +2 -0
- package/2.guide/0.index.md +22 -0
- package/2.guide/1.concepts/.navigation.yml +3 -0
- package/2.guide/1.concepts/1.auto-imports.md +205 -0
- package/2.guide/1.concepts/10.nuxt-lifecycle.md +141 -0
- package/2.guide/1.concepts/2.vuejs-development.md +103 -0
- package/2.guide/1.concepts/3.rendering.md +255 -0
- package/2.guide/1.concepts/4.server-engine.md +62 -0
- package/2.guide/1.concepts/5.modules.md +48 -0
- package/2.guide/1.concepts/7.esm.md +299 -0
- package/2.guide/1.concepts/8.typescript.md +97 -0
- package/2.guide/1.concepts/9.code-style.md +22 -0
- package/2.guide/2.directory-structure/.navigation.yml +3 -0
- package/2.guide/2.directory-structure/0.nuxt.md +20 -0
- package/2.guide/2.directory-structure/0.output.md +18 -0
- package/2.guide/2.directory-structure/1.assets.md +16 -0
- package/2.guide/2.directory-structure/1.components.md +608 -0
- package/2.guide/2.directory-structure/1.composables.md +121 -0
- package/2.guide/2.directory-structure/1.content.md +64 -0
- package/2.guide/2.directory-structure/1.layouts.md +180 -0
- package/2.guide/2.directory-structure/1.middleware.md +209 -0
- package/2.guide/2.directory-structure/1.modules.md +66 -0
- package/2.guide/2.directory-structure/1.node_modules.md +12 -0
- package/2.guide/2.directory-structure/1.pages.md +440 -0
- package/2.guide/2.directory-structure/1.plugins.md +299 -0
- package/2.guide/2.directory-structure/1.public.md +27 -0
- package/2.guide/2.directory-structure/1.server.md +546 -0
- package/2.guide/2.directory-structure/1.shared.md +104 -0
- package/2.guide/2.directory-structure/1.utils.md +49 -0
- package/2.guide/2.directory-structure/2.env.md +75 -0
- package/2.guide/2.directory-structure/2.gitignore.md +37 -0
- package/2.guide/2.directory-structure/2.nuxtignore.md +36 -0
- package/2.guide/2.directory-structure/2.nuxtrc.md +50 -0
- package/2.guide/2.directory-structure/3.app-config.md +177 -0
- package/2.guide/2.directory-structure/3.app.md +72 -0
- package/2.guide/2.directory-structure/3.error.md +55 -0
- package/2.guide/2.directory-structure/3.nuxt-config.md +34 -0
- package/2.guide/2.directory-structure/3.package.md +32 -0
- package/2.guide/2.directory-structure/3.tsconfig.md +24 -0
- package/2.guide/3.going-further/.navigation.yml +3 -0
- package/2.guide/3.going-further/1.experimental-features.md +689 -0
- package/2.guide/3.going-further/1.features.md +103 -0
- package/2.guide/3.going-further/1.internals.md +81 -0
- package/2.guide/3.going-further/10.runtime-config.md +174 -0
- package/2.guide/3.going-further/11.nightly-release-channel.md +68 -0
- package/2.guide/3.going-further/2.hooks.md +98 -0
- package/2.guide/3.going-further/3.modules.md +811 -0
- package/2.guide/3.going-further/4.kit.md +51 -0
- package/2.guide/3.going-further/6.nuxt-app.md +64 -0
- package/2.guide/3.going-further/7.layers.md +227 -0
- package/2.guide/3.going-further/9.debugging.md +115 -0
- package/2.guide/3.going-further/index.md +4 -0
- package/2.guide/4.recipes/.navigation.yml +3 -0
- package/2.guide/4.recipes/1.custom-routing.md +181 -0
- package/2.guide/4.recipes/2.vite-plugin.md +65 -0
- package/2.guide/4.recipes/3.custom-usefetch.md +125 -0
- package/2.guide/4.recipes/4.sessions-and-authentication.md +203 -0
- package/3.api/.navigation.yml +3 -0
- package/3.api/1.components/.navigation.yml +3 -0
- package/3.api/1.components/1.client-only.md +76 -0
- package/3.api/1.components/1.dev-only.md +51 -0
- package/3.api/1.components/1.nuxt-client-fallback.md +80 -0
- package/3.api/1.components/10.nuxt-picture.md +27 -0
- package/3.api/1.components/11.teleports.md +40 -0
- package/3.api/1.components/12.nuxt-route-announcer.md +56 -0
- package/3.api/1.components/13.nuxt-time.md +173 -0
- package/3.api/1.components/2.nuxt-page.md +154 -0
- package/3.api/1.components/3.nuxt-layout.md +156 -0
- package/3.api/1.components/4.nuxt-link.md +322 -0
- package/3.api/1.components/5.nuxt-loading-indicator.md +50 -0
- package/3.api/1.components/6.nuxt-error-boundary.md +65 -0
- package/3.api/1.components/7.nuxt-welcome.md +25 -0
- package/3.api/1.components/8.nuxt-island.md +70 -0
- package/3.api/1.components/9.nuxt-img.md +43 -0
- package/3.api/2.composables/.navigation.yml +3 -0
- package/3.api/2.composables/on-prehydrate.md +60 -0
- package/3.api/2.composables/use-app-config.md +19 -0
- package/3.api/2.composables/use-async-data.md +212 -0
- package/3.api/2.composables/use-cookie.md +233 -0
- package/3.api/2.composables/use-error.md +32 -0
- package/3.api/2.composables/use-fetch.md +217 -0
- package/3.api/2.composables/use-head-safe.md +55 -0
- package/3.api/2.composables/use-head.md +69 -0
- package/3.api/2.composables/use-hydration.md +68 -0
- package/3.api/2.composables/use-lazy-async-data.md +47 -0
- package/3.api/2.composables/use-lazy-fetch.md +55 -0
- package/3.api/2.composables/use-loading-indicator.md +77 -0
- package/3.api/2.composables/use-nuxt-app.md +294 -0
- package/3.api/2.composables/use-nuxt-data.md +112 -0
- package/3.api/2.composables/use-preview-mode.md +118 -0
- package/3.api/2.composables/use-request-event.md +23 -0
- package/3.api/2.composables/use-request-fetch.md +52 -0
- package/3.api/2.composables/use-request-header.md +34 -0
- package/3.api/2.composables/use-request-headers.md +37 -0
- package/3.api/2.composables/use-request-url.md +41 -0
- package/3.api/2.composables/use-response-header.md +48 -0
- package/3.api/2.composables/use-route-announcer.md +60 -0
- package/3.api/2.composables/use-route.md +52 -0
- package/3.api/2.composables/use-router.md +92 -0
- package/3.api/2.composables/use-runtime-config.md +142 -0
- package/3.api/2.composables/use-runtime-hook.md +43 -0
- package/3.api/2.composables/use-seo-meta.md +80 -0
- package/3.api/2.composables/use-server-seo-meta.md +27 -0
- package/3.api/2.composables/use-state.md +48 -0
- package/3.api/3.utils/$fetch.md +98 -0
- package/3.api/3.utils/.navigation.yml +3 -0
- package/3.api/3.utils/abort-navigation.md +73 -0
- package/3.api/3.utils/add-route-middleware.md +88 -0
- package/3.api/3.utils/call-once.md +92 -0
- package/3.api/3.utils/clear-error.md +29 -0
- package/3.api/3.utils/clear-nuxt-data.md +23 -0
- package/3.api/3.utils/clear-nuxt-state.md +23 -0
- package/3.api/3.utils/create-error.md +55 -0
- package/3.api/3.utils/define-nuxt-component.md +53 -0
- package/3.api/3.utils/define-nuxt-route-middleware.md +67 -0
- package/3.api/3.utils/define-page-meta.md +234 -0
- package/3.api/3.utils/define-route-rules.md +52 -0
- package/3.api/3.utils/navigate-to.md +230 -0
- package/3.api/3.utils/on-before-route-leave.md +11 -0
- package/3.api/3.utils/on-before-route-update.md +11 -0
- package/3.api/3.utils/on-nuxt-ready.md +25 -0
- package/3.api/3.utils/prefetch-components.md +28 -0
- package/3.api/3.utils/preload-components.md +23 -0
- package/3.api/3.utils/preload-route-components.md +41 -0
- package/3.api/3.utils/prerender-routes.md +46 -0
- package/3.api/3.utils/refresh-cookie.md +46 -0
- package/3.api/3.utils/refresh-nuxt-data.md +91 -0
- package/3.api/3.utils/reload-nuxt-app.md +74 -0
- package/3.api/3.utils/set-page-layout.md +24 -0
- package/3.api/3.utils/set-response-status.md +36 -0
- package/3.api/3.utils/show-error.md +31 -0
- package/3.api/3.utils/update-app-config.md +27 -0
- package/3.api/4.commands/.navigation.yml +3 -0
- package/3.api/4.commands/add.md +112 -0
- package/3.api/4.commands/analyze.md +41 -0
- package/3.api/4.commands/build-module.md +42 -0
- package/3.api/4.commands/build.md +46 -0
- package/3.api/4.commands/cleanup.md +38 -0
- package/3.api/4.commands/dev.md +59 -0
- package/3.api/4.commands/devtools.md +38 -0
- package/3.api/4.commands/generate.md +41 -0
- package/3.api/4.commands/info.md +33 -0
- package/3.api/4.commands/init.md +46 -0
- package/3.api/4.commands/module.md +84 -0
- package/3.api/4.commands/prepare.md +36 -0
- package/3.api/4.commands/preview.md +43 -0
- package/3.api/4.commands/typecheck.md +42 -0
- package/3.api/4.commands/upgrade.md +37 -0
- package/3.api/5.kit/.navigation.yml +3 -0
- package/3.api/5.kit/1.modules.md +172 -0
- package/3.api/5.kit/10.runtime-config.md +27 -0
- package/3.api/5.kit/10.templates.md +283 -0
- package/3.api/5.kit/11.nitro.md +409 -0
- package/3.api/5.kit/12.resolving.md +268 -0
- package/3.api/5.kit/13.logging.md +65 -0
- package/3.api/5.kit/14.builder.md +491 -0
- package/3.api/5.kit/15.examples.md +41 -0
- package/3.api/5.kit/2.programmatic.md +125 -0
- package/3.api/5.kit/3.compatibility.md +230 -0
- package/3.api/5.kit/4.autoimports.md +144 -0
- package/3.api/5.kit/5.components.md +127 -0
- package/3.api/5.kit/6.context.md +130 -0
- package/3.api/5.kit/7.pages.md +295 -0
- package/3.api/5.kit/8.layout.md +80 -0
- package/3.api/5.kit/9.plugins.md +263 -0
- package/3.api/6.advanced/.navigation.yml +1 -0
- package/3.api/6.advanced/1.hooks.md +105 -0
- package/3.api/6.advanced/2.import-meta.md +60 -0
- package/3.api/6.nuxt-config.md +12 -0
- package/3.api/index.md +31 -0
- package/5.community/.navigation.yml +3 -0
- package/5.community/2.getting-help.md +48 -0
- package/5.community/3.reporting-bugs.md +50 -0
- package/5.community/4.contribution.md +205 -0
- package/5.community/5.framework-contribution.md +142 -0
- package/5.community/6.roadmap.md +79 -0
- package/5.community/7.changelog.md +92 -0
- package/6.bridge/.navigation.yml +3 -0
- package/6.bridge/1.overview.md +137 -0
- package/6.bridge/10.configuration.md +96 -0
- package/6.bridge/2.typescript.md +46 -0
- package/6.bridge/3.bridge-composition-api.md +132 -0
- package/6.bridge/4.plugins-and-middleware.md +65 -0
- package/6.bridge/5.nuxt3-compatible-api.md +204 -0
- package/6.bridge/6.meta.md +117 -0
- package/6.bridge/7.runtime-config.md +38 -0
- package/6.bridge/8.nitro.md +102 -0
- package/6.bridge/9.vite.md +37 -0
- package/7.migration/.navigation.yml +3 -0
- package/7.migration/1.overview.md +24 -0
- package/7.migration/10.bundling.md +28 -0
- package/7.migration/11.server.md +17 -0
- package/7.migration/2.configuration.md +240 -0
- package/7.migration/20.module-authors.md +94 -0
- package/7.migration/3.auto-imports.md +18 -0
- package/7.migration/4.meta.md +127 -0
- package/7.migration/5.plugins-and-middleware.md +80 -0
- package/7.migration/6.pages-and-layouts.md +233 -0
- package/7.migration/7.component-options.md +156 -0
- package/7.migration/8.runtime-config.md +58 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/package.json +16 -4
- package/dist/.gitkeep +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Overview
|
|
3
|
+
description: Nuxt 3 is a complete rewrite of Nuxt 2, and also based on a new set of underlying technologies.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
There are significant changes when migrating a Nuxt 2 app to Nuxt 3, although you can expect migration to become more straightforward as we move toward a stable release.
|
|
7
|
+
|
|
8
|
+
::note
|
|
9
|
+
This migration guide is under progress to align with the development of Nuxt 3.
|
|
10
|
+
::
|
|
11
|
+
|
|
12
|
+
Some of these significant changes include:
|
|
13
|
+
|
|
14
|
+
1. Moving from Vue 2 to Vue 3, including defaulting to the Composition API and script setup.
|
|
15
|
+
1. Moving from webpack 4 and Babel to Vite or webpack 5 and esbuild.
|
|
16
|
+
1. Moving from a runtime Nuxt dependency to a minimal, standalone server compiled with nitropack.
|
|
17
|
+
|
|
18
|
+
::tip
|
|
19
|
+
If you need to remain on Nuxt 2, but want to benefit from Nuxt 3 features in Nuxt 2, you can alternatively check out [how to get started with Bridge](/docs/bridge/overview).
|
|
20
|
+
::
|
|
21
|
+
|
|
22
|
+
## Next Steps
|
|
23
|
+
|
|
24
|
+
- Learn about differences in [configuration](/docs/migration/configuration)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Build Tooling
|
|
3
|
+
description: 'Learn how to migrate from Nuxt 2 to Nuxt 3 build tooling.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
We use the following build tools by default:
|
|
7
|
+
|
|
8
|
+
- [Vite](https://vite.dev) or [webpack](https://webpack.js.org)
|
|
9
|
+
- [Rollup](https://rollupjs.org)
|
|
10
|
+
- [PostCSS](https://postcss.org)
|
|
11
|
+
- [esbuild](https://esbuild.github.io)
|
|
12
|
+
|
|
13
|
+
For this reason, most of your previous `build` configuration in `nuxt.config` will now be ignored, including any custom babel configuration.
|
|
14
|
+
|
|
15
|
+
If you need to configure any of Nuxt's build tools, you can do so in your `nuxt.config`, using the new top-level `vite`, `webpack` and `postcss` keys.
|
|
16
|
+
|
|
17
|
+
In addition, Nuxt ships with TypeScript support.
|
|
18
|
+
|
|
19
|
+
:read-more{to="/docs/guide/concepts/typescript"}
|
|
20
|
+
|
|
21
|
+
## Steps
|
|
22
|
+
|
|
23
|
+
1. Remove `@nuxt/typescript-build` and `@nuxt/typescript-runtime` from your dependencies and modules.
|
|
24
|
+
2. Remove any unused babel dependencies from your project.
|
|
25
|
+
3. Remove any explicit core-js dependencies.
|
|
26
|
+
4. Migrate `require` to `import`.
|
|
27
|
+
|
|
28
|
+
<!-- TODO: Enabling webpack builder -->
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Server
|
|
3
|
+
description: 'Learn how to migrate from Nuxt 2 to Nuxt 3 server.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
In a built Nuxt 3 application, there is no runtime Nuxt dependency. That means your site will be highly performant, and ultra-slim. But it also means you can no longer hook into runtime Nuxt server hooks.
|
|
7
|
+
|
|
8
|
+
:read-more{to="/docs/guide/concepts/server-engine"}
|
|
9
|
+
|
|
10
|
+
## Steps
|
|
11
|
+
|
|
12
|
+
1. Remove the `render` key in your `nuxt.config`.
|
|
13
|
+
2. Any files in `~/server/api` and `~/server/middleware` will be automatically registered; you can remove them from your `serverMiddleware` array.
|
|
14
|
+
3. Update any other items in your `serverMiddleware` array to point to files or npm packages directly, rather than using inline functions.
|
|
15
|
+
|
|
16
|
+
:read-more{to="/docs/guide/directory-structure/server"}
|
|
17
|
+
:read-more{to="/docs/guide/going-further/hooks#server-hooks-runtime"}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Configuration
|
|
3
|
+
description: 'Learn how to migrate from Nuxt 2 to Nuxt 3 new configuration.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## `nuxt.config`
|
|
7
|
+
|
|
8
|
+
The starting point for your Nuxt app remains your `nuxt.config` file.
|
|
9
|
+
|
|
10
|
+
::note
|
|
11
|
+
Nuxt configuration will be loaded using [`unjs/jiti`](https://github.com/unjs/jiti) and [`unjs/c12`](https://github.com/unjs/c12).
|
|
12
|
+
::
|
|
13
|
+
|
|
14
|
+
### Migration
|
|
15
|
+
|
|
16
|
+
1. You should migrate to the new `defineNuxtConfig` function that provides a typed configuration schema.
|
|
17
|
+
|
|
18
|
+
::code-group
|
|
19
|
+
|
|
20
|
+
```ts [Nuxt 2]
|
|
21
|
+
export default {
|
|
22
|
+
// ...
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```ts [Nuxt 3]
|
|
27
|
+
export default defineNuxtConfig({
|
|
28
|
+
// ...
|
|
29
|
+
})
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
::
|
|
33
|
+
|
|
34
|
+
1. If you were using `router.extendRoutes` you can migrate to the new `pages:extend` hook:
|
|
35
|
+
|
|
36
|
+
::code-group
|
|
37
|
+
|
|
38
|
+
```ts [Nuxt 2]
|
|
39
|
+
export default {
|
|
40
|
+
router: {
|
|
41
|
+
extendRoutes (routes) {
|
|
42
|
+
//
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```ts [Nuxt 3]
|
|
49
|
+
export default defineNuxtConfig({
|
|
50
|
+
hooks: {
|
|
51
|
+
'pages:extend' (routes) {
|
|
52
|
+
//
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
::
|
|
59
|
+
|
|
60
|
+
1. If you were using `router.routeNameSplitter` you can achieve same result by updating route name generation logic in the new `pages:extend` hook:
|
|
61
|
+
|
|
62
|
+
::code-group
|
|
63
|
+
|
|
64
|
+
```ts [Nuxt 2]
|
|
65
|
+
export default {
|
|
66
|
+
router: {
|
|
67
|
+
routeNameSplitter: '/'
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```ts [Nuxt 3]
|
|
73
|
+
import { createResolver } from '@nuxt/kit'
|
|
74
|
+
|
|
75
|
+
export default defineNuxtConfig({
|
|
76
|
+
hooks: {
|
|
77
|
+
'pages:extend' (routes) {
|
|
78
|
+
const routeNameSplitter = '/'
|
|
79
|
+
const root = createResolver(import.meta.url).resolve('./pages')
|
|
80
|
+
|
|
81
|
+
function updateName(routes) {
|
|
82
|
+
if (!routes) return
|
|
83
|
+
|
|
84
|
+
for (const route of routes) {
|
|
85
|
+
const relativePath = route.file.substring(root.length + 1)
|
|
86
|
+
route.name = relativePath.slice(0, -4).replace(/\/index$/, '').replace(/\//g, routeNameSplitter)
|
|
87
|
+
|
|
88
|
+
updateName(route.children)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
updateName(routes)
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
::
|
|
98
|
+
|
|
99
|
+
#### ESM Syntax
|
|
100
|
+
|
|
101
|
+
Nuxt 3 is an [ESM native framework](/docs/guide/concepts/esm). Although [`unjs/jiti`](https://github.com/unjs/jiti) provides semi compatibility when loading `nuxt.config` file, avoid any usage of `require` and `module.exports` in this file.
|
|
102
|
+
|
|
103
|
+
1. Change `module.exports` to `export default`
|
|
104
|
+
1. Change `const lib = require('lib')` to `import lib from 'lib'`
|
|
105
|
+
|
|
106
|
+
#### Async Configuration
|
|
107
|
+
|
|
108
|
+
In order to make Nuxt loading behavior more predictable, async config syntax is deprecated. Consider using Nuxt hooks for async operations.
|
|
109
|
+
|
|
110
|
+
#### Dotenv
|
|
111
|
+
|
|
112
|
+
Nuxt has built-in support for loading `.env` files. Avoid directly importing it from `nuxt.config`.
|
|
113
|
+
|
|
114
|
+
## Modules
|
|
115
|
+
|
|
116
|
+
Nuxt and Nuxt Modules are now build-time-only.
|
|
117
|
+
|
|
118
|
+
### Migration
|
|
119
|
+
|
|
120
|
+
1. Move all your `buildModules` into `modules`.
|
|
121
|
+
2. Check for Nuxt 3 compatibility of modules.
|
|
122
|
+
3. If you have any local modules pointing to a directory you should update this to point to the entry file:
|
|
123
|
+
|
|
124
|
+
```diff
|
|
125
|
+
export default defineNuxtConfig({
|
|
126
|
+
modules: [
|
|
127
|
+
- '~/modules/my-module'
|
|
128
|
+
+ '~/modules/my-module/index'
|
|
129
|
+
]
|
|
130
|
+
})
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
::tip
|
|
134
|
+
If you are a module author, you can check out [more information about module compatibility](/docs/migration/module-authors) and [our module author guide](/docs/guide/going-further/modules).
|
|
135
|
+
::
|
|
136
|
+
|
|
137
|
+
## Directory Changes
|
|
138
|
+
|
|
139
|
+
The `static/` (for storing static assets) has been renamed to `public/`. You can either rename your `static` directory to `public`, or keep the name by setting `dir.public` in your `nuxt.config`.
|
|
140
|
+
|
|
141
|
+
:read-more{to="/docs/guide/directory-structure/public"}
|
|
142
|
+
|
|
143
|
+
## TypeScript
|
|
144
|
+
|
|
145
|
+
It will be much easier to migrate your application if you use Nuxt's TypeScript integration. This does not mean you need to write your application in TypeScript, just that Nuxt will provide automatic type hints for your editor.
|
|
146
|
+
|
|
147
|
+
You can read more about Nuxt's TypeScript support [in the docs](/docs/guide/concepts/typescript).
|
|
148
|
+
|
|
149
|
+
::note
|
|
150
|
+
Nuxt can type-check your app using [`vue-tsc`](https://github.com/vuejs/language-tools/tree/master/packages/tsc) with `nuxi typecheck` command.
|
|
151
|
+
::
|
|
152
|
+
|
|
153
|
+
### Migration
|
|
154
|
+
|
|
155
|
+
1. Create a `tsconfig.json` with the following content:
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"extends": "./.nuxt/tsconfig.json"
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
1. Run `npx nuxi prepare` to generate `.nuxt/tsconfig.json`.
|
|
164
|
+
1. Install Volar following the instructions in the [docs](/docs/getting-started/introduction#prerequisites).
|
|
165
|
+
|
|
166
|
+
## Vue Changes
|
|
167
|
+
|
|
168
|
+
There are a number of changes to what is recommended Vue best practice, as well as a number of breaking changes between Vue 2 and 3.
|
|
169
|
+
|
|
170
|
+
It is recommended to read the [Vue 3 migration guide](https://v3-migration.vuejs.org) and in particular the [breaking changes list](https://v3-migration.vuejs.org/breaking-changes).
|
|
171
|
+
|
|
172
|
+
It is not currently possible to use the [Vue 3 migration build](https://v3-migration.vuejs.org/migration-build.html) with Nuxt 3.
|
|
173
|
+
|
|
174
|
+
## Vuex
|
|
175
|
+
|
|
176
|
+
Nuxt no longer provides a Vuex integration. Instead, the official Vue recommendation is to use `pinia`, which has built-in Nuxt support via a [Nuxt module](https://pinia.vuejs.org/ssr/nuxt.html). [Find out more about pinia here](https://pinia.vuejs.org).
|
|
177
|
+
|
|
178
|
+
A simple way to provide global state management with pinia would be:
|
|
179
|
+
|
|
180
|
+
Install the [`@pinia/nuxt`](/modules/pinia) module:
|
|
181
|
+
|
|
182
|
+
```bash [Terminal]
|
|
183
|
+
yarn add pinia @pinia/nuxt
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Enable the module in your nuxt configuration:
|
|
187
|
+
|
|
188
|
+
```ts [nuxt.config.ts]
|
|
189
|
+
import { defineNuxtConfig } from 'nuxt/config';
|
|
190
|
+
|
|
191
|
+
export default defineNuxtConfig({
|
|
192
|
+
modules: ['@pinia/nuxt']
|
|
193
|
+
})
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Create a `store` folder at the root of your application:
|
|
197
|
+
|
|
198
|
+
```ts [store/index.ts]
|
|
199
|
+
import { defineStore } from 'pinia'
|
|
200
|
+
|
|
201
|
+
export const useMainStore = defineStore('main', {
|
|
202
|
+
state: () => ({
|
|
203
|
+
counter: 0,
|
|
204
|
+
}),
|
|
205
|
+
actions: {
|
|
206
|
+
increment() {
|
|
207
|
+
// `this` is the store instance
|
|
208
|
+
this.counter++
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
})
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Create a [plugin](/docs/guide/directory-structure/plugins) file to globalize your store:
|
|
215
|
+
|
|
216
|
+
```ts [plugins/pinia.ts]
|
|
217
|
+
import { useMainStore } from '~/store'
|
|
218
|
+
|
|
219
|
+
export default defineNuxtPlugin(({ $pinia }) => {
|
|
220
|
+
return {
|
|
221
|
+
provide: {
|
|
222
|
+
store: useMainStore($pinia)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
})
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
If you want to keep using Vuex, you can manually migrate to Vuex 4 following [these steps](https://vuex.vuejs.org/guide/migrating-to-4-0-from-3-x.html).
|
|
229
|
+
|
|
230
|
+
Once it's done you will need to add the following plugin to your Nuxt app:
|
|
231
|
+
|
|
232
|
+
```ts [plugins/vuex.ts]
|
|
233
|
+
import store from '~/store'
|
|
234
|
+
|
|
235
|
+
export default defineNuxtPlugin(nuxtApp => {
|
|
236
|
+
nuxtApp.vueApp.use(store);
|
|
237
|
+
})
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
For larger apps, this migration can entail a lot of work. If updating Vuex still creates roadblocks, you may want to use the community module: [nuxt3-vuex-module](https://github.com/vedmant/nuxt3-vuex#nuxt3-vuex-module), which should work out of the box.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Modules
|
|
3
|
+
description: 'Learn how to migrate from Nuxt 2 to Nuxt 3 modules.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Module Compatibility
|
|
7
|
+
|
|
8
|
+
Nuxt 3 has a basic backward compatibility layer for Nuxt 2 modules using `@nuxt/kit` auto wrappers. But there are usually steps to follow to make modules compatible with Nuxt 3 and sometimes, using Nuxt Bridge is required for cross-version compatibility.
|
|
9
|
+
|
|
10
|
+
We have prepared a [Dedicated Guide](/docs/guide/going-further/modules) for authoring Nuxt 3 ready modules using `@nuxt/kit`. Currently best migration path is to follow it and rewrite your modules. Rest of this guide includes preparation steps if you prefer to avoid a full rewrite yet making modules compatible with Nuxt 3.
|
|
11
|
+
|
|
12
|
+
::tip{icon="i-lucide-puzzle" to="/modules"}
|
|
13
|
+
Explore Nuxt 3 compatible modules.
|
|
14
|
+
::
|
|
15
|
+
|
|
16
|
+
### Plugin Compatibility
|
|
17
|
+
|
|
18
|
+
Nuxt 3 plugins are **not** fully backward compatible with Nuxt 2.
|
|
19
|
+
|
|
20
|
+
:read-more{to="/docs/guide/directory-structure/plugins"}
|
|
21
|
+
|
|
22
|
+
### Vue Compatibility
|
|
23
|
+
|
|
24
|
+
Plugins or components using the Composition API need exclusive Vue 2 or Vue 3 support.
|
|
25
|
+
|
|
26
|
+
By using [vue-demi](https://github.com/vueuse/vue-demi) they should be compatible with both Nuxt 2 and 3.
|
|
27
|
+
|
|
28
|
+
## Module Migration
|
|
29
|
+
|
|
30
|
+
When Nuxt 3 users add your module, you will not have access to the module container (`this.*`) so you will need to use utilities from `@nuxt/kit` to access the container functionality.
|
|
31
|
+
|
|
32
|
+
### Test with `@nuxt/bridge`
|
|
33
|
+
|
|
34
|
+
Migrating to `@nuxt/bridge` is the first and most important step for supporting Nuxt 3.
|
|
35
|
+
|
|
36
|
+
If you have a fixture or example in your module, add `@nuxt/bridge` package to its config (see [example](/docs/bridge/overview#update-nuxtconfig))
|
|
37
|
+
|
|
38
|
+
### Migrate from CommonJS to ESM
|
|
39
|
+
|
|
40
|
+
Nuxt 3 natively supports TypeScript and ECMAScript Modules. Please check [Native ES Modules](/docs/guide/concepts/esm) for more info and upgrading.
|
|
41
|
+
|
|
42
|
+
### Ensure Plugins Default Export
|
|
43
|
+
|
|
44
|
+
If you inject a Nuxt plugin that does not have `export default` (such as global Vue plugins), ensure you add `export default () => { }` to the end of it.
|
|
45
|
+
|
|
46
|
+
::code-group
|
|
47
|
+
|
|
48
|
+
```js [Before]
|
|
49
|
+
// ~/plugins/vuelidate.js
|
|
50
|
+
import Vue from 'vue'
|
|
51
|
+
import Vuelidate from 'vuelidate'
|
|
52
|
+
|
|
53
|
+
Vue.use(Vuelidate)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```js [After]
|
|
57
|
+
// ~/plugins/vuelidate.js
|
|
58
|
+
import Vue from 'vue'
|
|
59
|
+
import Vuelidate from 'vuelidate'
|
|
60
|
+
|
|
61
|
+
Vue.use(Vuelidate)
|
|
62
|
+
|
|
63
|
+
export default () => { }
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
::
|
|
67
|
+
|
|
68
|
+
### Avoid Runtime Modules
|
|
69
|
+
|
|
70
|
+
With Nuxt 3, Nuxt is now a build-time-only dependency, which means that modules shouldn't attempt to hook into the Nuxt runtime.
|
|
71
|
+
|
|
72
|
+
Your module should work even if it's only added to [`buildModules`](/docs/api/nuxt-config#runtimeconfig) (instead of `modules`). For example:
|
|
73
|
+
|
|
74
|
+
- Avoid updating `process.env` within a Nuxt module and reading by a Nuxt plugin; use [`runtimeConfig`](/docs/api/nuxt-config#runtimeconfig) instead.
|
|
75
|
+
- (*) Avoid depending on runtime hooks like `vue-renderer:*` for production
|
|
76
|
+
- (*) Avoid adding `serverMiddleware` by importing them inside the module. Instead, add them by referencing a file path so that they are independent of the module's context
|
|
77
|
+
|
|
78
|
+
(*) Unless it is for `nuxt dev` purpose only and guarded with `if (nuxt.options.dev) { }`.
|
|
79
|
+
|
|
80
|
+
::tip
|
|
81
|
+
Continue reading about Nuxt 3 modules in the [Modules Author Guide](/docs/guide/going-further/modules).
|
|
82
|
+
::
|
|
83
|
+
|
|
84
|
+
### Use TypeScript (Optional)
|
|
85
|
+
|
|
86
|
+
While it is not essential, most of the Nuxt ecosystem is shifting to use TypeScript, so it is highly recommended to consider migration.
|
|
87
|
+
|
|
88
|
+
::tip
|
|
89
|
+
You can start migration by renaming `.js` files, to `.ts`. TypeScript is designed to be progressive!
|
|
90
|
+
::
|
|
91
|
+
|
|
92
|
+
::tip
|
|
93
|
+
You can use TypeScript syntax for Nuxt 2 and 3 modules and plugins without any extra dependencies.
|
|
94
|
+
::
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Auto Imports
|
|
3
|
+
description: Nuxt 3 adopts a minimal friction approach, meaning wherever possible components and composables are auto-imported.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
::note
|
|
7
|
+
In the rest of the migration documentation, you will notice that key Nuxt and Vue utilities do not have explicit imports. This is not a typo; Nuxt will automatically import them for you, and you should get full type hinting if you have followed [the instructions](/docs/migration/configuration#typescript) to use Nuxt's TypeScript support.
|
|
8
|
+
::
|
|
9
|
+
|
|
10
|
+
[Read more about auto imports](/docs/guide/concepts/auto-imports)
|
|
11
|
+
|
|
12
|
+
## Migration
|
|
13
|
+
|
|
14
|
+
1. If you have been using `@nuxt/components` in Nuxt 2, you can remove `components: true` in your `nuxt.config`. If you had a more complex setup, then note that the component options have changed somewhat. See the [components documentation](/docs/guide/directory-structure/components) for more information.
|
|
15
|
+
|
|
16
|
+
::tip
|
|
17
|
+
You can look at `.nuxt/types/components.d.ts` and `.nuxt/types/imports.d.ts` to see how Nuxt has resolved your components and composable auto-imports.
|
|
18
|
+
::
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Meta Tags
|
|
3
|
+
description: Manage your meta tags, from Nuxt 2 to Nuxt 3.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Nuxt 3 provides several different ways to manage your meta tags:
|
|
7
|
+
1. Through your `nuxt.config`.
|
|
8
|
+
2. Through the [`useHead`](/docs/api/composables/use-head) [composable](/docs/getting-started/seo-meta)
|
|
9
|
+
3. Through [global meta components](/docs/getting-started/seo-meta)
|
|
10
|
+
|
|
11
|
+
You can customize `title`, `titleTemplate`, `base`, `script`, `noscript`, `style`, `meta`, `link`, `htmlAttrs` and `bodyAttrs`.
|
|
12
|
+
|
|
13
|
+
::tip
|
|
14
|
+
Nuxt currently uses [`Unhead`](https://github.com/unjs/unhead) to manage your meta tags, but implementation details may change.
|
|
15
|
+
::
|
|
16
|
+
|
|
17
|
+
:read-more{to="/docs/getting-started/seo-meta"}
|
|
18
|
+
|
|
19
|
+
## Migration
|
|
20
|
+
|
|
21
|
+
1. In your `nuxt.config`, rename `head` to `meta`. Consider moving this shared meta configuration into your `app.vue` instead. (Note that objects no longer have a `hid` key for deduplication.)
|
|
22
|
+
2. If you need to access the component state with `head`, you should migrate to using [`useHead`](/docs/api/composables/use-head) . You might also consider using the built-in meta-components.
|
|
23
|
+
3. If you need to use the Options API, there is a `head()` method you can use when you use `defineNuxtComponent`.
|
|
24
|
+
|
|
25
|
+
### useHead
|
|
26
|
+
|
|
27
|
+
::code-group
|
|
28
|
+
|
|
29
|
+
```vue [Nuxt 2]
|
|
30
|
+
<script>
|
|
31
|
+
export default {
|
|
32
|
+
data: () => ({
|
|
33
|
+
title: 'My App',
|
|
34
|
+
description: 'My App Description'
|
|
35
|
+
})
|
|
36
|
+
head () {
|
|
37
|
+
return {
|
|
38
|
+
title: this.title,
|
|
39
|
+
meta: [{
|
|
40
|
+
hid: 'description',
|
|
41
|
+
name: 'description',
|
|
42
|
+
content: this.description
|
|
43
|
+
}]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
</script>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```vue [Nuxt 3]
|
|
51
|
+
<script setup lang="ts">
|
|
52
|
+
const title = ref('My App')
|
|
53
|
+
const description = ref('My App Description')
|
|
54
|
+
|
|
55
|
+
// This will be reactive when you change title/description above
|
|
56
|
+
useHead({
|
|
57
|
+
title,
|
|
58
|
+
meta: [{
|
|
59
|
+
name: 'description',
|
|
60
|
+
content: description
|
|
61
|
+
}]
|
|
62
|
+
})
|
|
63
|
+
</script>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
::
|
|
67
|
+
|
|
68
|
+
### Meta-components
|
|
69
|
+
|
|
70
|
+
Nuxt 3 also provides meta components that you can use to accomplish the same task. While these components look similar to HTML tags, they are provided by Nuxt and have similar functionality.
|
|
71
|
+
|
|
72
|
+
::code-group
|
|
73
|
+
|
|
74
|
+
```vue [Nuxt 2]
|
|
75
|
+
<script>
|
|
76
|
+
export default {
|
|
77
|
+
head () {
|
|
78
|
+
return {
|
|
79
|
+
title: 'My App',
|
|
80
|
+
meta: [{
|
|
81
|
+
hid: 'description',
|
|
82
|
+
name: 'description',
|
|
83
|
+
content: 'My App Description'
|
|
84
|
+
}]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
</script>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```vue [Nuxt 3]
|
|
92
|
+
<template>
|
|
93
|
+
<div>
|
|
94
|
+
<Head>
|
|
95
|
+
<Title>My App</Title>
|
|
96
|
+
<Meta name="description" content="My app description"/>
|
|
97
|
+
</Head>
|
|
98
|
+
<!-- -->
|
|
99
|
+
</div>
|
|
100
|
+
</template>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
::
|
|
104
|
+
|
|
105
|
+
::important
|
|
106
|
+
1. Make sure you use capital letters for these component names to distinguish them from native HTML elements (`<Title>` rather than `<title>`).
|
|
107
|
+
2. You can place these components anywhere in your template for your page.
|
|
108
|
+
::
|
|
109
|
+
|
|
110
|
+
### Options API
|
|
111
|
+
|
|
112
|
+
```vue [Nuxt 3 (Options API)]
|
|
113
|
+
<script>
|
|
114
|
+
// if using options API `head` method you must use `defineNuxtComponent`
|
|
115
|
+
export default defineNuxtComponent({
|
|
116
|
+
head (nuxtApp) {
|
|
117
|
+
// `head` receives the nuxt app but cannot access the component instance
|
|
118
|
+
return {
|
|
119
|
+
meta: [{
|
|
120
|
+
name: 'description',
|
|
121
|
+
content: 'This is my page description.'
|
|
122
|
+
}]
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
</script>
|
|
127
|
+
```
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Plugins and Middleware
|
|
3
|
+
description: 'Learn how to migrate from Nuxt 2 to Nuxt 3 plugins and middleware.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Plugins
|
|
7
|
+
|
|
8
|
+
Plugins now have a different format, and take only one argument (`nuxtApp`).
|
|
9
|
+
|
|
10
|
+
::code-group
|
|
11
|
+
|
|
12
|
+
```js [Nuxt 2]
|
|
13
|
+
export default (ctx, inject) => {
|
|
14
|
+
inject('injected', () => 'my injected function')
|
|
15
|
+
})
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```ts [Nuxt 3]
|
|
19
|
+
export default defineNuxtPlugin(nuxtApp => {
|
|
20
|
+
// now available on `nuxtApp.$injected`
|
|
21
|
+
nuxtApp.provide('injected', () => 'my injected function')
|
|
22
|
+
|
|
23
|
+
// You can alternatively use this format, which comes with automatic type support
|
|
24
|
+
return {
|
|
25
|
+
provide: {
|
|
26
|
+
injected: () => 'my injected function'
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
::
|
|
33
|
+
|
|
34
|
+
:read-more{to="/docs/guide/directory-structure/plugins"}
|
|
35
|
+
|
|
36
|
+
::read-more{to="/docs/api/composables/use-nuxt-app"}
|
|
37
|
+
Read more about the format of `nuxtApp`.
|
|
38
|
+
::
|
|
39
|
+
|
|
40
|
+
### Migration
|
|
41
|
+
|
|
42
|
+
1. Migrate your plugins to use the `defineNuxtPlugin` helper function.
|
|
43
|
+
2. Remove any entries in your `nuxt.config` plugins array that are located in your `plugins/` folder. All files in this directory at the top level (and any index files in any subdirectories) will be automatically registered. Instead of setting `mode` to `client` or `server`, you can indicate this in the file name. For example, `~/plugins/my-plugin.client.ts` will only be loaded on client-side.
|
|
44
|
+
|
|
45
|
+
## Route Middleware
|
|
46
|
+
|
|
47
|
+
Route middleware has a different format.
|
|
48
|
+
|
|
49
|
+
::code-group
|
|
50
|
+
|
|
51
|
+
```js [Nuxt 2]
|
|
52
|
+
export default function ({ store, redirect }) {
|
|
53
|
+
// If the user is not authenticated
|
|
54
|
+
if (!store.state.authenticated) {
|
|
55
|
+
return redirect('/login')
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```ts [Nuxt 3]
|
|
61
|
+
export default defineNuxtRouteMiddleware((to, from) => {
|
|
62
|
+
const auth = useState('auth')
|
|
63
|
+
if (!auth.value.authenticated) {
|
|
64
|
+
return navigateTo('/login')
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
::
|
|
70
|
+
|
|
71
|
+
Much like Nuxt 2, route middleware placed in your `~/middleware` folder is automatically registered. You can then specify it by name in a component. However, this is done with `definePageMeta` rather than as a component option.
|
|
72
|
+
|
|
73
|
+
`navigateTo` is one of a number of route helper functions.
|
|
74
|
+
|
|
75
|
+
:read-more{to="/docs/guide/directory-structure/middleware"}
|
|
76
|
+
|
|
77
|
+
### Migration
|
|
78
|
+
|
|
79
|
+
1. Migrate your route middleware to use the `defineNuxtRouteMiddleware` helper function.
|
|
80
|
+
1. Any global middleware (such as in your `nuxt.config`) can be placed in your `~/middleware` folder with a `.global` extension, for example `~/middleware/auth.global.ts`.
|