@nuxt/docs 3.17.6 → 3.18.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 (47) hide show
  1. package/1.getting-started/01.introduction.md +2 -2
  2. package/1.getting-started/02.installation.md +7 -7
  3. package/1.getting-started/03.configuration.md +1 -1
  4. package/1.getting-started/04.views.md +1 -1
  5. package/1.getting-started/06.styling.md +3 -3
  6. package/1.getting-started/08.seo-meta.md +2 -2
  7. package/1.getting-started/09.transitions.md +3 -3
  8. package/1.getting-started/10.data-fetching.md +3 -3
  9. package/1.getting-started/12.error-handling.md +1 -1
  10. package/1.getting-started/15.prerendering.md +2 -2
  11. package/1.getting-started/16.deployment.md +1 -1
  12. package/1.getting-started/17.testing.md +2 -2
  13. package/1.getting-started/18.upgrade.md +222 -2
  14. package/2.guide/0.index.md +3 -0
  15. package/2.guide/1.concepts/3.rendering.md +1 -1
  16. package/2.guide/2.directory-structure/1.components.md +2 -2
  17. package/2.guide/2.directory-structure/1.pages.md +1 -1
  18. package/2.guide/2.directory-structure/2.env.md +4 -0
  19. package/2.guide/3.going-further/1.events.md +3 -22
  20. package/2.guide/3.going-further/2.hooks.md +21 -2
  21. package/2.guide/3.going-further/3.modules.md +27 -2
  22. package/2.guide/5.best-practices/.navigation.yml +3 -0
  23. package/2.guide/5.best-practices/hydration.md +188 -0
  24. package/2.guide/5.best-practices/performance.md +305 -0
  25. package/2.guide/5.best-practices/plugins.md +20 -0
  26. package/3.api/1.components/4.nuxt-link.md +1 -1
  27. package/3.api/2.composables/use-async-data.md +7 -3
  28. package/3.api/2.composables/use-fetch.md +13 -8
  29. package/3.api/2.composables/use-nuxt-data.md +1 -1
  30. package/3.api/2.composables/use-response-header.md +1 -1
  31. package/3.api/2.composables/use-route.md +1 -1
  32. package/3.api/2.composables/use-runtime-config.md +1 -1
  33. package/3.api/3.utils/$fetch.md +1 -1
  34. package/3.api/3.utils/define-lazy-hydration-component.md +261 -0
  35. package/3.api/3.utils/define-nuxt-route-middleware.md +1 -1
  36. package/3.api/3.utils/on-before-route-leave.md +1 -1
  37. package/3.api/3.utils/on-before-route-update.md +1 -1
  38. package/3.api/4.commands/init.md +2 -0
  39. package/3.api/5.kit/1.modules.md +49 -0
  40. package/3.api/5.kit/10.templates.md +1 -1
  41. package/3.api/5.kit/11.nitro.md +47 -0
  42. package/3.api/5.kit/4.autoimports.md +8 -8
  43. package/3.api/6.advanced/1.hooks.md +4 -4
  44. package/5.community/4.contribution.md +18 -0
  45. package/7.migration/6.pages-and-layouts.md +1 -1
  46. package/7.migration/8.runtime-config.md +1 -1
  47. 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/v3" target="_blank"}
13
- :card{title="Open on CodeSandbox" icon="i-simple-icons-codesandbox" to="https://nuxt.new/c/v3" target="_blank"}
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 can not be overridden using environment variables.
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
  ![Layouts are wrapper around pages](/assets/docs/getting-started/views/layouts.svg)
90
90
 
91
- Layouts are wrappers around pages that contain a common User Interface for several pages, such as a header and footer display. 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.
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 `~/public/` directory, for example in `~/public/fonts`. You can then reference them in your stylesheets using `url()`.
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 like this.
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 preprocessors syntax. Vite come 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.
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 to use `useHead()` in `app.vue`.
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 to take a look at the [`useHead`](/docs/api/composables/use-head) and [`useHeadSafe`](/docs/api/composables/use-head-safe) composables.
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, that 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 restrict 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.
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 based) or combined with [`useAsyncData`](#useasyncdata) when fetching the initial component data.
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 an 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.
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 to use `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.
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/#routerules"}
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 grained handling of each route that gets prerendered.
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
- > ie. `vitest.config.m{ts,js}`.
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 twoslash
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/
@@ -299,6 +300,64 @@ export default defineNuxtConfig({
299
300
  })
300
301
  ```
301
302
 
303
+ ### Corrected Module Loading Order in Layers
304
+
305
+ 🚦 **Impact Level**: Minimal
306
+
307
+ #### What Changed
308
+
309
+ The order in which modules are loaded when using [Nuxt layers](/docs/guide/going-further/layers) has been corrected. Previously, modules from the project root were loaded before modules from extended layers, which was the reverse of the expected behavior.
310
+
311
+ Now modules are loaded in the correct order:
312
+
313
+ 1. **Layer modules first** (in extend order - deeper layers first)
314
+ 2. **Project modules last** (highest priority)
315
+
316
+ This affects both:
317
+ * Modules defined in the `modules` array in `nuxt.config.ts`
318
+ * Auto-discovered modules from the `modules/` directory
319
+
320
+ #### Reasons for Change
321
+
322
+ This change ensures that:
323
+ * Extended layers have lower priority than the consuming project
324
+ * Module execution order matches the intuitive layer inheritance pattern
325
+ * Module configuration and hooks work as expected in multi-layer setups
326
+
327
+ #### Migration Steps
328
+
329
+ **Most projects will not need changes**, as this corrects the loading order to match expected behavior.
330
+
331
+ However, if your project was relying on the previous incorrect order, you may need to:
332
+
333
+ 1. **Review module dependencies**: Check if any modules depend on specific loading order
334
+ 2. **Adjust module configuration**: If modules were configured to work around the incorrect order
335
+ 3. **Test thoroughly**: Ensure all functionality works as expected with the corrected order
336
+
337
+ Example of the new correct order:
338
+ ```ts
339
+ // Layer: my-layer/nuxt.config.ts
340
+ export default defineNuxtConfig({
341
+ modules: ['layer-module-1', 'layer-module-2']
342
+ })
343
+
344
+ // Project: nuxt.config.ts
345
+ export default defineNuxtConfig({
346
+ extends: ['./my-layer'],
347
+ modules: ['project-module-1', 'project-module-2']
348
+ })
349
+
350
+ // Loading order (corrected):
351
+ // 1. layer-module-1
352
+ // 2. layer-module-2
353
+ // 3. project-module-1 (can override layer modules)
354
+ // 4. project-module-2 (can override layer modules)
355
+ ```
356
+
357
+ If you encounter issues with module order dependencies due to needing to register a hook, consider using the [`modules:done` hook](/docs/guide/going-further/modules#custom-hooks) for modules that need to call a hook. This is run after all other modules have been loaded, which means it is safe to use.
358
+
359
+ 👉 See [PR #31507](https://github.com/nuxt/nuxt/pull/31507) and [issue #25719](https://github.com/nuxt/nuxt/issues/25719) for more details.
360
+
302
361
  ### Deduplication of Route Metadata
303
362
 
304
363
  🚦 **Impact Level**: Minimal
@@ -407,7 +466,7 @@ export default defineNuxtPlugin({
407
466
  })
408
467
  ```
409
468
 
410
- While not required it's recommend to update any imports from `@unhead/vue` to `#imports` or `nuxt/app`.
469
+ While not required it's recommended to update any imports from `@unhead/vue` to `#imports` or `nuxt/app`.
411
470
 
412
471
  ```diff
413
472
  -import { useHead } from '@unhead/vue'
@@ -777,7 +836,7 @@ This change should generally improve the expected behavior, but if you were expe
777
836
  query: { id },
778
837
  immediate: false
779
838
  )
780
- + watch(id, execute, { once: true })
839
+ + watch(id, () => execute(), { once: true })
781
840
  ```
782
841
 
783
842
  To opt out of this behavior:
@@ -973,6 +1032,129 @@ const importName = genSafeVariableName
973
1032
  You can automate this step by running `npx codemod@latest nuxt/4/template-compilation-changes`
974
1033
  ::
975
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
+
976
1158
  ### Removal of Experimental Features
977
1159
 
978
1160
  🚦 **Impact Level**: Minimal
@@ -997,6 +1179,44 @@ These options have been set to their current values for some time and we do not
997
1179
 
998
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)
999
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
+
1000
1220
  ## Nuxt 2 vs. Nuxt 3+
1001
1221
 
1002
1222
  In the table below, there is a quick comparison between 3 versions of Nuxt:
@@ -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
  ::
@@ -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 Client-only applications on any static server with HTML, CSS, and JavaScript files.
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
- Ensure to always `await` on `navigateTo` or chain its result by returning from functions.
380
+ Make sure to always `await` on `navigateTo` or chain its result by returning from functions.
381
381
  ::
382
382
 
383
383
  ```vue twoslash
@@ -55,6 +55,10 @@ Since `.env` files are not used in production, you must explicitly set environme
55
55
 
56
56
  * Many cloud service providers, such as Vercel, Netlify, and AWS, provide interfaces for setting environment variables via their dashboards, CLI tools or configuration files.
57
57
 
58
+ ::important
59
+ `runtimeConfig` [won't pick up environment variables that don't start with `NUXT_` in production] (https://nuxt.com/docs/guide/going-further/runtime-config#environment-variables).
60
+ ::
61
+
58
62
  ## Production Preview
59
63
 
60
64
  For local production preview purpose, we recommend using [`nuxt preview`](/docs/api/commands/preview) since using this command, the `.env` file will be loaded into `process.env` for convenience. Note that this command requires dependencies to be installed in the package directory.
@@ -58,25 +58,6 @@ await nuxtApp.callHook('app:user:registered', {
58
58
  You can inspect all events using the **Nuxt DevTools** Hooks panel.
59
59
  ::
60
60
 
61
- ## Augmenting Types
62
-
63
- You can augment the types of hooks provided by Nuxt.
64
-
65
- ```ts
66
- import { HookResult } from "@nuxt/schema";
67
-
68
- declare module '#app' {
69
- interface RuntimeNuxtHooks {
70
- 'your-nuxt-runtime-hook': () => HookResult
71
- }
72
- interface NuxtHooks {
73
- 'your-nuxt-hook': () => HookResult
74
- }
75
- }
76
-
77
- declare module 'nitropack' {
78
- interface NitroRuntimeHooks {
79
- 'your-nitro-hook': () => void;
80
- }
81
- }
82
- ```
61
+ ::read-more{to="/docs/guide/going-further/hooks"}
62
+ Learn more about Nuxt's built-in hooks and how to extend them
63
+ ::
@@ -74,6 +74,25 @@ export default defineNitroPlugin((nitroApp) => {
74
74
  Learn more about available Nitro lifecycle hooks.
75
75
  ::
76
76
 
77
- ## Additional Hooks
77
+ ## Adding Custom Hooks
78
78
 
79
- Learn more about creating custom hooks in the [Events section](/docs/guide/going-further/events).
79
+ You can define your own custom hooks support by extending Nuxt's hook interfaces.
80
+
81
+ ```ts
82
+ import { HookResult } from "@nuxt/schema";
83
+
84
+ declare module '#app' {
85
+ interface RuntimeNuxtHooks {
86
+ 'your-nuxt-runtime-hook': () => HookResult
87
+ }
88
+ interface NuxtHooks {
89
+ 'your-nuxt-hook': () => HookResult
90
+ }
91
+ }
92
+
93
+ declare module 'nitropack' {
94
+ interface NitroRuntimeHooks {
95
+ 'your-nitro-hook': () => void;
96
+ }
97
+ }
98
+ ```