@nuxt/docs 3.17.7 → 3.18.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/1.getting-started/01.introduction.md +2 -2
- package/1.getting-started/02.installation.md +7 -7
- package/1.getting-started/03.configuration.md +1 -1
- package/1.getting-started/04.views.md +1 -1
- package/1.getting-started/06.styling.md +3 -3
- package/1.getting-started/08.seo-meta.md +2 -2
- package/1.getting-started/09.transitions.md +3 -3
- package/1.getting-started/10.data-fetching.md +3 -3
- package/1.getting-started/12.error-handling.md +1 -1
- package/1.getting-started/15.prerendering.md +2 -2
- package/1.getting-started/16.deployment.md +1 -1
- package/1.getting-started/17.testing.md +2 -2
- package/1.getting-started/18.upgrade.md +163 -1
- package/2.guide/0.index.md +3 -0
- package/2.guide/1.concepts/10.nuxt-lifecycle.md +1 -1
- package/2.guide/1.concepts/3.rendering.md +1 -1
- package/2.guide/2.directory-structure/1.components.md +2 -2
- package/2.guide/2.directory-structure/1.pages.md +1 -1
- package/2.guide/3.going-further/11.nightly-release-channel.md +4 -4
- package/2.guide/3.going-further/3.modules.md +2 -2
- package/2.guide/5.best-practices/.navigation.yml +3 -0
- package/2.guide/5.best-practices/hydration.md +188 -0
- package/2.guide/5.best-practices/performance.md +305 -0
- package/2.guide/5.best-practices/plugins.md +20 -0
- package/3.api/1.components/4.nuxt-link.md +1 -1
- package/3.api/2.composables/use-async-data.md +4 -0
- package/3.api/2.composables/use-fetch.md +5 -1
- package/3.api/2.composables/use-response-header.md +1 -1
- package/3.api/2.composables/use-route.md +1 -1
- package/3.api/3.utils/$fetch.md +1 -1
- package/3.api/3.utils/define-lazy-hydration-component.md +261 -0
- package/3.api/3.utils/define-nuxt-route-middleware.md +1 -1
- package/3.api/3.utils/on-before-route-leave.md +1 -1
- package/3.api/3.utils/on-before-route-update.md +1 -1
- package/3.api/4.commands/init.md +2 -0
- package/3.api/5.kit/1.modules.md +49 -0
- package/3.api/5.kit/10.templates.md +1 -1
- package/3.api/5.kit/11.nitro.md +47 -0
- package/3.api/5.kit/4.autoimports.md +8 -8
- package/3.api/6.advanced/1.hooks.md +4 -4
- package/5.community/4.contribution.md +18 -0
- package/7.migration/6.pages-and-layouts.md +1 -1
- package/7.migration/8.runtime-config.md +1 -1
- package/package.json +1 -1
|
@@ -24,7 +24,7 @@ Nuxt uses conventions and an opinionated directory structure to automate repetit
|
|
|
24
24
|
- **Server-side rendering out of the box:** Nuxt comes with built-in SSR capabilities, so you don't have to set up a separate server yourself.
|
|
25
25
|
- **Auto-imports:** write Vue composables and components in their respective directories and use them without having to import them with the benefits of tree-shaking and optimized JS bundles.
|
|
26
26
|
- **Data-fetching utilities:** Nuxt provides composables to handle SSR-compatible data fetching as well as different strategies.
|
|
27
|
-
- **Zero-config TypeScript support:** write type-safe code without having to learn TypeScript with our auto-generated types and `tsconfig.json
|
|
27
|
+
- **Zero-config TypeScript support:** write type-safe code without having to learn TypeScript with our auto-generated types and `tsconfig.json`.
|
|
28
28
|
- **Configured build tools:** we use [Vite](https://vite.dev) by default to support hot module replacement (HMR) in development and bundling your code for production with best-practices baked-in.
|
|
29
29
|
|
|
30
30
|
Nuxt takes care of these and provides both frontend and backend functionality so you can focus on what matters: **creating your web application**.
|
|
@@ -64,7 +64,7 @@ A Nuxt application can be deployed on a Node or Deno server, pre-rendered to be
|
|
|
64
64
|
|
|
65
65
|
### Modular
|
|
66
66
|
|
|
67
|
-
A module system allows to extend Nuxt with custom features and integrations with third-party services.
|
|
67
|
+
A module system allows you to extend Nuxt with custom features and integrations with third-party services.
|
|
68
68
|
|
|
69
69
|
:read-more{title="Nuxt Modules Concept" to="/docs/guide/concepts/modules"}
|
|
70
70
|
|
|
@@ -9,8 +9,8 @@ navigation.icon: i-lucide-play
|
|
|
9
9
|
If you just want to play around with Nuxt in your browser without setting up a project, you can use one of our online sandboxes:
|
|
10
10
|
|
|
11
11
|
::card-group
|
|
12
|
-
:card{title="Open on StackBlitz" icon="i-simple-icons-stackblitz" to="https://nuxt.new/s/
|
|
13
|
-
:card{title="Open on CodeSandbox" icon="i-simple-icons-codesandbox" to="https://nuxt.new/c/
|
|
12
|
+
:card{title="Open on StackBlitz" icon="i-simple-icons-stackblitz" to="https://nuxt.new/s/v4" target="_blank"}
|
|
13
|
+
:card{title="Open on CodeSandbox" icon="i-simple-icons-codesandbox" to="https://nuxt.new/c/v4" target="_blank"}
|
|
14
14
|
::
|
|
15
15
|
|
|
16
16
|
Or follow the steps below to set up a new Nuxt project on your computer.
|
|
@@ -39,23 +39,23 @@ Open a terminal (if you're using [Visual Studio Code](https://code.visualstudio.
|
|
|
39
39
|
::code-group{sync="pm"}
|
|
40
40
|
|
|
41
41
|
```bash [npm]
|
|
42
|
-
npm create nuxt <project-name>
|
|
42
|
+
npm create nuxt@latest <project-name> -- -t v3
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
```bash [yarn]
|
|
46
|
-
yarn create nuxt <project-name>
|
|
46
|
+
yarn create nuxt@latest <project-name> -t v3
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
```bash [pnpm]
|
|
50
|
-
pnpm create nuxt <project-name>
|
|
50
|
+
pnpm create nuxt@latest <project-name> -t v3
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
```bash [bun]
|
|
54
|
-
bun create nuxt <project-name>
|
|
54
|
+
bun create nuxt@latest <project-name> -t v3
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
```bash [deno]
|
|
58
|
-
deno -A npm:create-nuxt@latest <project-name>
|
|
58
|
+
deno -A npm:create-nuxt@latest <project-name> -t v3
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
::
|
|
@@ -100,7 +100,7 @@ const runtimeConfig = useRuntimeConfig()
|
|
|
100
100
|
|
|
101
101
|
## App Configuration
|
|
102
102
|
|
|
103
|
-
The `app.config.ts` file, located in the source directory (by default the root of the project), is used to expose public variables that can be determined at build time. Contrary to the `runtimeConfig` option, these
|
|
103
|
+
The `app.config.ts` file, located in the source directory (by default the root of the project), is used to expose public variables that can be determined at build time. Contrary to the `runtimeConfig` option, these cannot be overridden using environment variables.
|
|
104
104
|
|
|
105
105
|
A minimal configuration file exports the `defineAppConfig` function containing an object with your configuration. The `defineAppConfig` helper is globally available without import.
|
|
106
106
|
|
|
@@ -88,7 +88,7 @@ To use pages, create `pages/index.vue` file and add `<NuxtPage />` component to
|
|
|
88
88
|
|
|
89
89
|

|
|
90
90
|
|
|
91
|
-
Layouts are wrappers around pages that contain a common User Interface for several pages, such as
|
|
91
|
+
Layouts are wrappers around pages that contain a common User Interface for several pages, such as header and footer displays. Layouts are Vue files using `<slot />` components to display the **page** content. The `layouts/default.vue` file will be used by default. Custom layouts can be set as part of your page metadata.
|
|
92
92
|
|
|
93
93
|
::note
|
|
94
94
|
If you only have a single layout in your application, we recommend using [`app.vue`](/docs/guide/directory-structure/app) with [`<NuxtPage />`](/docs/api/components/nuxt-page) instead.
|
|
@@ -51,7 +51,7 @@ The stylesheets will be inlined in the HTML rendered by Nuxt, injected globally
|
|
|
51
51
|
|
|
52
52
|
### Working With Fonts
|
|
53
53
|
|
|
54
|
-
Place your local fonts files in your
|
|
54
|
+
Place your local fonts files in your `public/` directory, for example in `public/fonts`. You can then reference them in your stylesheets using `url()`.
|
|
55
55
|
|
|
56
56
|
```css [assets/css/main.css]
|
|
57
57
|
@font-face {
|
|
@@ -119,7 +119,7 @@ export default defineNuxtConfig({
|
|
|
119
119
|
|
|
120
120
|
## External Stylesheets
|
|
121
121
|
|
|
122
|
-
You can include external stylesheets in your application by adding a link element in the head section of your nuxt.config file. You can achieve this result using different methods. Note that local stylesheets can also be included
|
|
122
|
+
You can include external stylesheets in your application by adding a link element in the head section of your nuxt.config file. You can achieve this result using different methods. Note that local stylesheets can also be included this way.
|
|
123
123
|
|
|
124
124
|
You can manipulate the head with the [`app.head`](/docs/api/nuxt-config#head) property of your Nuxt configuration:
|
|
125
125
|
|
|
@@ -407,7 +407,7 @@ You can use [CSS Modules](https://github.com/css-modules/css-modules) with the m
|
|
|
407
407
|
|
|
408
408
|
### Preprocessors Support
|
|
409
409
|
|
|
410
|
-
SFC style blocks support
|
|
410
|
+
SFC style blocks support preprocessor syntax. Vite comes with built-in support for .scss, .sass, .less, .styl and .stylus files without configuration. You just need to install them first, and they will be available directly in SFC with the lang attribute.
|
|
411
411
|
|
|
412
412
|
::code-group
|
|
413
413
|
|
|
@@ -12,7 +12,7 @@ and numerous configuration options to manage your app's head and SEO meta tags.
|
|
|
12
12
|
Providing an [`app.head`](/docs/api/nuxt-config#head) property in your [`nuxt.config.ts`](/docs/guide/directory-structure/nuxt-config) allows you to statically customize the head for your entire app.
|
|
13
13
|
|
|
14
14
|
::important
|
|
15
|
-
This method does not allow you to provide reactive data. We recommend
|
|
15
|
+
This method does not allow you to provide reactive data. We recommend using `useHead()` in `app.vue`.
|
|
16
16
|
::
|
|
17
17
|
|
|
18
18
|
It's good practice to set tags here that won't change such as your site title default, language and favicon.
|
|
@@ -75,7 +75,7 @@ useHead({
|
|
|
75
75
|
</script>
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
We recommend
|
|
78
|
+
We recommend taking a look at the [`useHead`](/docs/api/composables/use-head) and [`useHeadSafe`](/docs/api/composables/use-head-safe) composables.
|
|
79
79
|
|
|
80
80
|
## `useSeoMeta`
|
|
81
81
|
|
|
@@ -16,7 +16,7 @@ You can enable page transitions to apply an automatic transition for all your [p
|
|
|
16
16
|
export default defineNuxtConfig({
|
|
17
17
|
app: {
|
|
18
18
|
pageTransition: { name: 'page', mode: 'out-in' }
|
|
19
|
-
}
|
|
19
|
+
}
|
|
20
20
|
})
|
|
21
21
|
```
|
|
22
22
|
|
|
@@ -121,7 +121,7 @@ You can enable layout transitions to apply an automatic transition for all your
|
|
|
121
121
|
export default defineNuxtConfig({
|
|
122
122
|
app: {
|
|
123
123
|
layoutTransition: { name: 'layout', mode: 'out-in' }
|
|
124
|
-
}
|
|
124
|
+
}
|
|
125
125
|
})
|
|
126
126
|
```
|
|
127
127
|
|
|
@@ -470,4 +470,4 @@ export default defineNuxtRouteMiddleware(to => {
|
|
|
470
470
|
|
|
471
471
|
### Known Issues
|
|
472
472
|
|
|
473
|
-
- If you perform data fetching within your page setup functions,
|
|
473
|
+
- If you perform data fetching within your page setup functions, you may wish to reconsider using this feature for the moment. (By design, View Transitions completely freeze DOM updates whilst they are taking place.) We're looking at restricting the View Transition to the final moments before `<Suspense>` resolves, but in the interim you may want to consider carefully whether to adopt this feature if this describes you.
|
|
@@ -9,7 +9,7 @@ Nuxt comes with two composables and a built-in library to perform data-fetching
|
|
|
9
9
|
In a nutshell:
|
|
10
10
|
|
|
11
11
|
- [`$fetch`](/docs/api/utils/dollarfetch) is the simplest way to make a network request.
|
|
12
|
-
- [`useFetch`](/docs/api/composables/use-fetch) is wrapper around `$fetch` that fetches data only once in [universal rendering](/docs/guide/concepts/rendering#universal-rendering).
|
|
12
|
+
- [`useFetch`](/docs/api/composables/use-fetch) is a wrapper around `$fetch` that fetches data only once in [universal rendering](/docs/guide/concepts/rendering#universal-rendering).
|
|
13
13
|
- [`useAsyncData`](/docs/api/composables/use-async-data) is similar to `useFetch` but offers more fine-grained control.
|
|
14
14
|
|
|
15
15
|
Both `useFetch` and `useAsyncData` share a common set of options and patterns that we will detail in the last sections.
|
|
@@ -81,7 +81,7 @@ async function addTodo() {
|
|
|
81
81
|
|
|
82
82
|
::warning
|
|
83
83
|
Beware that using only `$fetch` will not provide [network calls de-duplication and navigation prevention](#the-need-for-usefetch-and-useasyncdata). :br
|
|
84
|
-
It is recommended to use `$fetch` for client-side interactions (event
|
|
84
|
+
It is recommended to use `$fetch` for client-side interactions (event-based) or combined with [`useAsyncData`](#useasyncdata) when fetching the initial component data.
|
|
85
85
|
::
|
|
86
86
|
|
|
87
87
|
::read-more{to="/docs/api/utils/dollarfetch"}
|
|
@@ -483,7 +483,7 @@ If you need to change the URL based on a reactive value, you may want to use a [
|
|
|
483
483
|
|
|
484
484
|
#### Computed URL
|
|
485
485
|
|
|
486
|
-
Sometimes you may need to compute
|
|
486
|
+
Sometimes you may need to compute a URL from reactive values, and refresh the data each time these change. Instead of juggling your way around, you can attach each param as a reactive value. Nuxt will automatically use the reactive value and re-fetch each time it changes.
|
|
487
487
|
|
|
488
488
|
```vue
|
|
489
489
|
<script setup lang="ts">
|
|
@@ -109,7 +109,7 @@ const handleError = () => clearError({ redirect: '/' })
|
|
|
109
109
|
Read more about `error.vue` and its uses.
|
|
110
110
|
::
|
|
111
111
|
|
|
112
|
-
For custom errors we highly recommend
|
|
112
|
+
For custom errors we highly recommend using `onErrorCaptured` composable that can be called in a page/component setup function or `vue:error` runtime nuxt hook that can be configured in a nuxt plugin.
|
|
113
113
|
|
|
114
114
|
```ts twoslash [plugins/error-handler.ts]
|
|
115
115
|
export default defineNuxtPlugin(nuxtApp => {
|
|
@@ -99,7 +99,7 @@ export default defineNuxtConfig({
|
|
|
99
99
|
});
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
::read-more{to="https://nitro.build/config
|
|
102
|
+
::read-more{to="https://nitro.build/config#routerules"}
|
|
103
103
|
Read more about Nitro's `routeRules` configuration.
|
|
104
104
|
::
|
|
105
105
|
|
|
@@ -177,7 +177,7 @@ export default defineNuxtConfig({
|
|
|
177
177
|
|
|
178
178
|
### `prerender:generate` Nitro hook
|
|
179
179
|
|
|
180
|
-
This is called for each route during prerendering. You can use this for fine
|
|
180
|
+
This is called for each route during prerendering. You can use this for fine-grained handling of each route that gets prerendered.
|
|
181
181
|
|
|
182
182
|
```ts [nuxt.config.ts]
|
|
183
183
|
export default defineNuxtConfig({
|
|
@@ -62,7 +62,7 @@ By default, the workload gets distributed to the workers with the round robin st
|
|
|
62
62
|
|
|
63
63
|
### Learn More
|
|
64
64
|
|
|
65
|
-
:read-more{to="https://nitro.build/deploy/node" title="the Nitro documentation for node-server preset"}
|
|
65
|
+
:read-more{to="https://nitro.build/deploy/runtimes/node" title="the Nitro documentation for node-server preset"}
|
|
66
66
|
|
|
67
67
|
:video-accordion{title="Watch Daniel Roe's short video on the topic" videoId="0x1H6K5yOfs"}
|
|
68
68
|
|
|
@@ -63,7 +63,7 @@ We currently ship an environment for unit testing code that needs a [Nuxt](https
|
|
|
63
63
|
|
|
64
64
|
::tip
|
|
65
65
|
When importing `@nuxt/test-utils` in your vitest config, It is necessary to have `"type": "module"` specified in your `package.json` or rename your vitest config file appropriately.
|
|
66
|
-
>
|
|
66
|
+
> i.e., `vitest.config.m{ts,js}`.
|
|
67
67
|
::
|
|
68
68
|
|
|
69
69
|
::tip
|
|
@@ -444,7 +444,7 @@ If you prefer to use `@vue/test-utils` on its own for unit testing in Nuxt, and
|
|
|
444
444
|
|
|
445
445
|
2. Create a `vitest.config.ts` with the following content:
|
|
446
446
|
|
|
447
|
-
```ts
|
|
447
|
+
```ts
|
|
448
448
|
import { defineConfig } from 'vitest/config'
|
|
449
449
|
import vue from '@vitejs/plugin-vue'
|
|
450
450
|
|
|
@@ -179,6 +179,7 @@ layers/
|
|
|
179
179
|
modules/
|
|
180
180
|
node_modules/
|
|
181
181
|
public/
|
|
182
|
+
shared/
|
|
182
183
|
server/
|
|
183
184
|
api/
|
|
184
185
|
middleware/
|
|
@@ -465,7 +466,7 @@ export default defineNuxtPlugin({
|
|
|
465
466
|
})
|
|
466
467
|
```
|
|
467
468
|
|
|
468
|
-
While not required it's
|
|
469
|
+
While not required it's recommended to update any imports from `@unhead/vue` to `#imports` or `nuxt/app`.
|
|
469
470
|
|
|
470
471
|
```diff
|
|
471
472
|
-import { useHead } from '@unhead/vue'
|
|
@@ -1031,6 +1032,129 @@ const importName = genSafeVariableName
|
|
|
1031
1032
|
You can automate this step by running `npx codemod@latest nuxt/4/template-compilation-changes`
|
|
1032
1033
|
::
|
|
1033
1034
|
|
|
1035
|
+
### Default TypeScript Configuration Changes
|
|
1036
|
+
|
|
1037
|
+
🚦 **Impact Level**: Minimal
|
|
1038
|
+
|
|
1039
|
+
#### What Changed
|
|
1040
|
+
|
|
1041
|
+
`compilerOptions.noUncheckedIndexedAccess` is now `true` instead of `false`.
|
|
1042
|
+
|
|
1043
|
+
#### Reasons for Change
|
|
1044
|
+
|
|
1045
|
+
This change is a follow up to a prior [3.12 config update](https://github.com/nuxt/nuxt/pull/27485) where we improved our defaults, mostly adhering to [TotalTypeScript's recommendations](https://www.totaltypescript.com/tsconfig-cheat-sheet).
|
|
1046
|
+
|
|
1047
|
+
#### Migration Steps
|
|
1048
|
+
|
|
1049
|
+
There are two approaches:
|
|
1050
|
+
|
|
1051
|
+
1. Run a typecheck on your app and fix any new errors (recommended).
|
|
1052
|
+
|
|
1053
|
+
2. Override the new default in your `nuxt.config.ts`:
|
|
1054
|
+
|
|
1055
|
+
<!-- @case-police-ignore tsConfig -->
|
|
1056
|
+
|
|
1057
|
+
```ts
|
|
1058
|
+
export default defineNuxtConfig({
|
|
1059
|
+
typescript: {
|
|
1060
|
+
tsConfig: {
|
|
1061
|
+
compilerOptions: {
|
|
1062
|
+
noUncheckedIndexedAccess: false
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
})
|
|
1067
|
+
```
|
|
1068
|
+
|
|
1069
|
+
### TypeScript Configuration Splitting
|
|
1070
|
+
|
|
1071
|
+
🚦 **Impact Level**: Minimal
|
|
1072
|
+
|
|
1073
|
+
#### What Changed
|
|
1074
|
+
|
|
1075
|
+
Nuxt now generates separate TypeScript configurations for different contexts to provide better type-checking experiences:
|
|
1076
|
+
|
|
1077
|
+
1. **New TypeScript configuration files**: Nuxt now generates additional TypeScript configurations:
|
|
1078
|
+
* `.nuxt/tsconfig.app.json` - For your app code (Vue components, composables, etc.)
|
|
1079
|
+
* `.nuxt/tsconfig.server.json` - For your server-side code (Nitro/server directory)
|
|
1080
|
+
* `.nuxt/tsconfig.node.json` - For your build-time code (modules, `nuxt.config.ts`, etc.)
|
|
1081
|
+
* `.nuxt/tsconfig.shared.json` - For code shared between app and server contexts (like types and non-environment specific utilities)
|
|
1082
|
+
* `.nuxt/tsconfig.json` - Legacy configuration for backward compatibility
|
|
1083
|
+
|
|
1084
|
+
2. **Backward compatibility**: Existing projects that extend `.nuxt/tsconfig.json` will continue to work as before.
|
|
1085
|
+
|
|
1086
|
+
3. **Opt-in project references**: New projects or those wanting better type checking can adopt TypeScript's project references feature.
|
|
1087
|
+
|
|
1088
|
+
4. **Context-specific type checking**: Each context now has appropriate compiler options and includes/excludes for its specific environment.
|
|
1089
|
+
|
|
1090
|
+
5. **New `typescript.nodeTsConfig` option**: You can now customize the TypeScript configuration for Node.js build-time code.
|
|
1091
|
+
|
|
1092
|
+
#### Reasons for Change
|
|
1093
|
+
|
|
1094
|
+
This change provides several benefits:
|
|
1095
|
+
|
|
1096
|
+
1. **Better type safety**: Each context (app, server, build-time) gets appropriate type checking with context-specific globals and APIs.
|
|
1097
|
+
2. **Improved IDE experience**: Better IntelliSense and error reporting for different parts of your codebase.
|
|
1098
|
+
3. **Cleaner separation**: Server code won't incorrectly suggest client-side APIs and vice versa.
|
|
1099
|
+
4. **Performance**: TypeScript can more efficiently check code with properly scoped configurations.
|
|
1100
|
+
|
|
1101
|
+
For example, auto-imports are not available in your `nuxt.config.ts` (but previously this was not flagged by TypeScript). And while IDEs recognized the separate context hinted by `tsconfig.json` in your `server/` directory, this was not reflected in type-checking (requiring a separate step).
|
|
1102
|
+
|
|
1103
|
+
#### Migration Steps
|
|
1104
|
+
|
|
1105
|
+
**No migration is required** - existing projects will continue to work as before.
|
|
1106
|
+
|
|
1107
|
+
However, to take advantage of improved type checking, you can opt in to the new project references approach:
|
|
1108
|
+
|
|
1109
|
+
1. **Update your root `tsconfig.json`** to use project references:
|
|
1110
|
+
|
|
1111
|
+
```json
|
|
1112
|
+
{
|
|
1113
|
+
"files": [],
|
|
1114
|
+
"references": [
|
|
1115
|
+
{ "path": "./.nuxt/tsconfig.app.json" },
|
|
1116
|
+
{ "path": "./.nuxt/tsconfig.server.json" },
|
|
1117
|
+
{ "path": "./.nuxt/tsconfig.shared.json" },
|
|
1118
|
+
{ "path": "./.nuxt/tsconfig.node.json" }
|
|
1119
|
+
]
|
|
1120
|
+
}
|
|
1121
|
+
```
|
|
1122
|
+
|
|
1123
|
+
2. **Remove any manual server `tsconfig.json`** files (like `server/tsconfig.json`) that extended `.nuxt/tsconfig.server.json`.
|
|
1124
|
+
|
|
1125
|
+
3. **Update your type checking scripts** to use the build flag for project references:
|
|
1126
|
+
|
|
1127
|
+
```diff
|
|
1128
|
+
- "typecheck": "nuxt prepare && vue-tsc --noEmit"
|
|
1129
|
+
+ "typecheck": "nuxt prepare && vue-tsc -b --noEmit"
|
|
1130
|
+
```
|
|
1131
|
+
|
|
1132
|
+
4. **Configure Node.js TypeScript options** if needed:
|
|
1133
|
+
<!-- @case-police-ignore tsConfig -->
|
|
1134
|
+
|
|
1135
|
+
```ts
|
|
1136
|
+
export default defineNuxtConfig({
|
|
1137
|
+
typescript: {
|
|
1138
|
+
// Customize app/server TypeScript config
|
|
1139
|
+
tsConfig: {
|
|
1140
|
+
compilerOptions: {
|
|
1141
|
+
strict: true
|
|
1142
|
+
}
|
|
1143
|
+
},
|
|
1144
|
+
// Customize build-time TypeScript config
|
|
1145
|
+
nodeTsConfig: {
|
|
1146
|
+
compilerOptions: {
|
|
1147
|
+
strict: true
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
})
|
|
1152
|
+
```
|
|
1153
|
+
|
|
1154
|
+
5. **Update any CI/build scripts** that run TypeScript checking to ensure they use the new project references approach.
|
|
1155
|
+
|
|
1156
|
+
The new configuration provides better type safety and IntelliSense for projects that opt in, while maintaining full backward compatibility for existing setups.
|
|
1157
|
+
|
|
1034
1158
|
### Removal of Experimental Features
|
|
1035
1159
|
|
|
1036
1160
|
🚦 **Impact Level**: Minimal
|
|
@@ -1055,6 +1179,44 @@ These options have been set to their current values for some time and we do not
|
|
|
1055
1179
|
|
|
1056
1180
|
* `respectNoSSRHeader`is implementable in user-land with [server middleware](https://github.com/nuxt/nuxt/blob/c660b39447f0d5b8790c0826092638d321cd6821/packages/nuxt/src/core/runtime/nitro/no-ssr.ts#L8-L9)
|
|
1057
1181
|
|
|
1182
|
+
### Removal of Top-Level `generate` Configuration
|
|
1183
|
+
|
|
1184
|
+
🚦 **Impact Level**: Minimal
|
|
1185
|
+
|
|
1186
|
+
#### What Changed
|
|
1187
|
+
|
|
1188
|
+
The top-level `generate` configuration option is no longer available in Nuxt 4. This includes all of its properties:
|
|
1189
|
+
|
|
1190
|
+
* `generate.exclude` - for excluding routes from prerendering
|
|
1191
|
+
* `generate.routes` - for specifying routes to prerender
|
|
1192
|
+
|
|
1193
|
+
#### Reasons for Change
|
|
1194
|
+
|
|
1195
|
+
The top level `generate` configuration was a holdover from Nuxt 2. We've supported `nitro.prerender` for a while now, and it is the preferred way to configure prerendering in Nuxt 3+.
|
|
1196
|
+
|
|
1197
|
+
#### Migration Steps
|
|
1198
|
+
|
|
1199
|
+
Replace `generate` configuration with the corresponding `nitro.prerender` options:
|
|
1200
|
+
|
|
1201
|
+
```diff
|
|
1202
|
+
export default defineNuxtConfig({
|
|
1203
|
+
- generate: {
|
|
1204
|
+
- exclude: ['/admin', '/private'],
|
|
1205
|
+
- routes: ['/sitemap.xml', '/robots.txt']
|
|
1206
|
+
- }
|
|
1207
|
+
+ nitro: {
|
|
1208
|
+
+ prerender: {
|
|
1209
|
+
+ ignore: ['/admin', '/private'],
|
|
1210
|
+
+ routes: ['/sitemap.xml', '/robots.txt']
|
|
1211
|
+
+ }
|
|
1212
|
+
+ }
|
|
1213
|
+
})
|
|
1214
|
+
```
|
|
1215
|
+
|
|
1216
|
+
::read-more{to="https://nitro.build/config#prerender"}
|
|
1217
|
+
Read more about Nitro's prerender configuration options.
|
|
1218
|
+
::
|
|
1219
|
+
|
|
1058
1220
|
## Nuxt 2 vs. Nuxt 3+
|
|
1059
1221
|
|
|
1060
1222
|
In the table below, there is a quick comparison between 3 versions of Nuxt:
|
package/2.guide/0.index.md
CHANGED
|
@@ -19,4 +19,7 @@ surround: false
|
|
|
19
19
|
::card{icon="i-lucide-book-open" title="Recipes" to="/docs/guide/recipes"}
|
|
20
20
|
Find solutions to common problems and learn how to implement them in your Nuxt project.
|
|
21
21
|
::
|
|
22
|
+
::card{icon="i-lucide-square-check" title="Best Practices" to="/docs/guide/best-practices"}
|
|
23
|
+
Learn about best practices when developing with Nuxt
|
|
24
|
+
::
|
|
22
25
|
::
|
|
@@ -68,7 +68,7 @@ In Nuxt, there are three types of middleware:
|
|
|
68
68
|
- **Named route middleware**
|
|
69
69
|
- **Anonymous (or inline) route middleware**
|
|
70
70
|
|
|
71
|
-
Nuxt
|
|
71
|
+
Nuxt executes all global middleware on the initial page load (both on server and client) and then again before any client-side navigation. Named and anonymous middleware are executed only on the routes specified in the middleware property of the page(route) meta defined in the corresponding page components.
|
|
72
72
|
|
|
73
73
|
For details about each type and examples, see the [Middleware documentation](/docs/guide/directory-structure/middleware).
|
|
74
74
|
|
|
@@ -70,7 +70,7 @@ Out of the box, a traditional Vue.js application is rendered in the browser (or
|
|
|
70
70
|
|
|
71
71
|
**Benefits of client-side rendering:**
|
|
72
72
|
- **Development speed**: When working entirely on the client-side, we don't have to worry about the server compatibility of the code, for example, by using browser-only APIs like the `window` object.
|
|
73
|
-
- **Cheaper:** Running a server adds a cost of infrastructure as you would need to run on a platform that supports JavaScript. We can host
|
|
73
|
+
- **Cheaper:** Running a server adds a cost of infrastructure as you would need to run on a platform that supports JavaScript. We can host client-only applications on any static server with HTML, CSS, and JavaScript files.
|
|
74
74
|
- **Offline:** Because code entirely runs in the browser, it can nicely keep working while the internet is unavailable.
|
|
75
75
|
|
|
76
76
|
**Downsides of client-side rendering:**
|
|
@@ -79,7 +79,7 @@ const MyButton = resolveComponent('MyButton')
|
|
|
79
79
|
```
|
|
80
80
|
|
|
81
81
|
::important
|
|
82
|
-
If you are using `resolveComponent` to handle dynamic components, make sure not to insert anything but the name of the component, which must be a literal string and not be or contain a variable. The string is statically analyzed at compilation step.
|
|
82
|
+
If you are using `resolveComponent` to handle dynamic components, make sure not to insert anything but the name of the component, which must be a literal string and not be or contain a variable. The string is statically analyzed at the compilation step.
|
|
83
83
|
::
|
|
84
84
|
|
|
85
85
|
:video-accordion{title="Watch Daniel Roe's short video about resolveComponent()" videoId="4kq8E5IUM2U"}
|
|
@@ -187,7 +187,7 @@ Hydrates the component after a specified interaction (e.g., click, mouseover).
|
|
|
187
187
|
</template>
|
|
188
188
|
```
|
|
189
189
|
|
|
190
|
-
If you do not pass an event or list of events, it defaults to hydrating on `pointerenter` and `focus`.
|
|
190
|
+
If you do not pass an event or list of events, it defaults to hydrating on `pointerenter`, `click` and `focus`.
|
|
191
191
|
|
|
192
192
|
::note
|
|
193
193
|
Under the hood, this uses Vue's built-in [`hydrateOnInteraction` strategy](https://vuejs.org/guide/components/async.html#hydrate-on-interaction).
|
|
@@ -377,7 +377,7 @@ Learn more about `<NuxtLink>` usage.
|
|
|
377
377
|
Nuxt allows programmatic navigation through the `navigateTo()` utility method. Using this utility method, you will be able to programmatically navigate the user in your app. This is great for taking input from the user and navigating them dynamically throughout your application. In this example, we have a simple method called `navigate()` that gets called when the user submits a search form.
|
|
378
378
|
|
|
379
379
|
::note
|
|
380
|
-
|
|
380
|
+
Make sure to always `await` on `navigateTo` or chain its result by returning from functions.
|
|
381
381
|
::
|
|
382
382
|
|
|
383
383
|
```vue twoslash
|
|
@@ -26,8 +26,8 @@ Update `nuxt` dependency inside `package.json`:
|
|
|
26
26
|
```diff [package.json]
|
|
27
27
|
{
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
-- "nuxt": "^
|
|
30
|
-
++ "nuxt": "npm:nuxt-nightly@
|
|
29
|
+
-- "nuxt": "^4.0.0"
|
|
30
|
+
++ "nuxt": "npm:nuxt-nightly@latest"
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
```
|
|
@@ -41,8 +41,8 @@ Update `nuxt` dependency inside `package.json`:
|
|
|
41
41
|
```diff [package.json]
|
|
42
42
|
{
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
-- "nuxt": "npm:nuxt-nightly@
|
|
45
|
-
++ "nuxt": "^
|
|
44
|
+
-- "nuxt": "npm:nuxt-nightly@latest"
|
|
45
|
+
++ "nuxt": "^4.0.0"
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
```
|
|
@@ -785,7 +785,7 @@ Linking to the integration website and documentation is always a good idea.
|
|
|
785
785
|
|
|
786
786
|
#### Provide a StackBlitz Demo or Boilerplate
|
|
787
787
|
|
|
788
|
-
It's a good practice to make a minimal reproduction with your module and [StackBlitz](https://nuxt.new/s/
|
|
788
|
+
It's a good practice to make a minimal reproduction with your module and [StackBlitz](https://nuxt.new/s/v4) that you add to your module readme.
|
|
789
789
|
|
|
790
790
|
This not only provides potential users of your module a quick and easy way to experiment with the module but also an easy way for them to build minimal reproductions they can send you when they encounter issues.
|
|
791
791
|
|
|
@@ -813,7 +813,7 @@ Watch Vue School video about Nuxt module types.
|
|
|
813
813
|
|
|
814
814
|
**Community modules** are modules prefixed (scoped) with `@nuxtjs/` (e.g. [`@nuxtjs/tailwindcss`](https://tailwindcss.nuxtjs.org)). They are proven modules made and maintained by community members. Again, contributions are welcome from anyone.
|
|
815
815
|
|
|
816
|
-
**Third
|
|
816
|
+
**Third-party and other community modules** are modules (often) prefixed with `nuxt-`. Anyone can make them, using this prefix allows these modules to be discoverable on npm. This is the best starting point to draft and try an idea!
|
|
817
817
|
|
|
818
818
|
**Private or personal modules** are modules made for your own use case or company. They don't need to follow any naming rules to work with Nuxt and are often seen scoped under an npm organization (e.g. `@my-company/nuxt-auth`)
|
|
819
819
|
|