@nuxt/docs-nightly 4.0.0-29162105.8c587084 → 4.0.0-29165109.5b7cbcb6
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 +3 -3
- package/1.getting-started/03.configuration.md +1 -1
- package/1.getting-started/07.routing.md +1 -1
- package/1.getting-started/10.data-fetching.md +1 -1
- package/1.getting-started/11.state-management.md +1 -1
- package/1.getting-started/12.error-handling.md +1 -1
- package/1.getting-started/15.prerendering.md +7 -7
- package/1.getting-started/16.deployment.md +2 -2
- package/1.getting-started/18.upgrade.md +51 -9
- package/2.guide/1.concepts/3.rendering.md +3 -3
- package/2.guide/1.concepts/5.modules.md +1 -1
- package/2.guide/1.concepts/8.typescript.md +6 -6
- package/2.guide/1.concepts/9.code-style.md +1 -1
- package/2.guide/2.directory-structure/1.app/.navigation.yml +5 -0
- package/2.guide/2.directory-structure/{1.composables.md → 1.app/1.composables.md} +1 -1
- package/2.guide/2.directory-structure/{1.pages.md → 1.app/1.pages.md} +2 -2
- package/2.guide/2.directory-structure/1.content.md +1 -1
- package/2.guide/2.directory-structure/1.server.md +1 -1
- package/2.guide/2.directory-structure/2.env.md +4 -4
- package/2.guide/3.going-further/1.events.md +1 -1
- package/2.guide/3.going-further/1.experimental-features.md +1 -1
- package/2.guide/3.going-further/1.internals.md +2 -2
- package/2.guide/3.going-further/10.runtime-config.md +1 -1
- package/2.guide/3.going-further/11.nightly-release-channel.md +2 -6
- package/2.guide/3.going-further/3.modules.md +3 -3
- package/2.guide/3.going-further/9.debugging.md +1 -5
- package/2.guide/4.recipes/1.custom-routing.md +5 -5
- package/2.guide/4.recipes/4.sessions-and-authentication.md +2 -2
- package/3.api/1.components/10.nuxt-picture.md +1 -1
- package/3.api/1.components/9.nuxt-img.md +1 -1
- package/3.api/2.composables/use-async-data.md +1 -1
- package/3.api/2.composables/use-cookie.md +5 -4
- package/3.api/2.composables/use-fetch.md +1 -1
- package/3.api/2.composables/use-preview-mode.md +3 -3
- package/3.api/3.utils/define-page-meta.md +1 -1
- package/3.api/4.commands/add.md +20 -20
- package/3.api/4.commands/analyze.md +2 -2
- package/3.api/4.commands/build-module.md +2 -2
- package/3.api/4.commands/build.md +2 -2
- package/3.api/4.commands/cleanup.md +2 -2
- package/3.api/4.commands/dev.md +3 -3
- package/3.api/4.commands/devtools.md +3 -3
- package/3.api/4.commands/generate.md +3 -3
- package/3.api/4.commands/info.md +2 -2
- package/3.api/4.commands/init.md +3 -3
- package/3.api/4.commands/module.md +8 -8
- package/3.api/4.commands/prepare.md +2 -2
- package/3.api/4.commands/preview.md +3 -3
- package/3.api/4.commands/typecheck.md +2 -2
- package/3.api/4.commands/upgrade.md +2 -2
- package/3.api/5.kit/11.nitro.md +48 -1
- package/3.api/5.kit/4.autoimports.md +8 -8
- package/3.api/6.advanced/1.hooks.md +1 -1
- package/3.api/6.nuxt-config.md +2932 -3
- package/5.community/4.contribution.md +1 -1
- package/5.community/6.roadmap.md +17 -12
- package/5.community/7.changelog.md +1 -1
- package/7.migration/2.configuration.md +2 -2
- package/7.migration/7.component-options.md +1 -1
- package/package.json +1 -1
- /package/2.guide/2.directory-structure/{1.assets.md → 1.app/1.assets.md} +0 -0
- /package/2.guide/2.directory-structure/{1.components.md → 1.app/1.components.md} +0 -0
- /package/2.guide/2.directory-structure/{1.layouts.md → 1.app/1.layouts.md} +0 -0
- /package/2.guide/2.directory-structure/{1.middleware.md → 1.app/1.middleware.md} +0 -0
- /package/2.guide/2.directory-structure/{1.plugins.md → 1.app/1.plugins.md} +0 -0
- /package/2.guide/2.directory-structure/{1.utils.md → 1.app/1.utils.md} +0 -0
- /package/2.guide/2.directory-structure/{3.app-config.md → 1.app/3.app-config.md} +0 -0
- /package/2.guide/2.directory-structure/{3.app.md → 1.app/3.app.md} +0 -0
- /package/2.guide/2.directory-structure/{3.error.md → 1.app/3.error.md} +0 -0
|
@@ -72,9 +72,9 @@ A module system allows to extend Nuxt with custom features and integrations with
|
|
|
72
72
|
|
|
73
73
|
Nuxt is composed of different [core packages](https://github.com/nuxt/nuxt/tree/main/packages):
|
|
74
74
|
|
|
75
|
-
- Core
|
|
76
|
-
- Bundlers: [@nuxt/vite-builder](https://github.com/nuxt/nuxt/tree/main/packages/vite) and [@nuxt/webpack-builder](https://github.com/nuxt/nuxt/tree/main/packages/webpack)
|
|
77
|
-
- Command line interface: [
|
|
75
|
+
- Core engine: [nuxt](https://github.com/nuxt/nuxt/tree/main/packages/nuxt)
|
|
76
|
+
- Bundlers: [@nuxt/vite-builder](https://github.com/nuxt/nuxt/tree/main/packages/vite), [@nuxt/rspack-builder](https://github.com/nuxt/nuxt/tree/main/packages/rspack) and [@nuxt/webpack-builder](https://github.com/nuxt/nuxt/tree/main/packages/webpack)
|
|
77
|
+
- Command line interface: [@nuxt/cli](https://github.com/nuxt/cli)
|
|
78
78
|
- Server engine: [nitro](https://github.com/nitrojs/nitro)
|
|
79
79
|
- Development kit: [@nuxt/kit](https://github.com/nuxt/nuxt/tree/main/packages/kit)
|
|
80
80
|
|
|
@@ -50,7 +50,7 @@ export default defineNuxtConfig({
|
|
|
50
50
|
})
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
To select an environment when running a Nuxt CLI command, simply pass the name to the `--envName` flag, like so: `
|
|
53
|
+
To select an environment when running a Nuxt CLI command, simply pass the name to the `--envName` flag, like so: `nuxt build --envName staging`.
|
|
54
54
|
|
|
55
55
|
To learn more about the mechanism behind these overrides, please refer to the `c12` documentation on [environment-specific configuration](https://github.com/unjs/c12?tab=readme-ov-file#environment-specific-configuration).
|
|
56
56
|
|
|
@@ -94,7 +94,7 @@ There are three kinds of route middleware:
|
|
|
94
94
|
|
|
95
95
|
1. Anonymous (or inline) route middleware, which are defined directly in the pages where they are used.
|
|
96
96
|
2. Named route middleware, which are placed in the [`middleware/`](/docs/guide/directory-structure/middleware) directory and will be automatically loaded via asynchronous import when used on a page. (**Note**: The route middleware name is normalized to kebab-case, so `someMiddleware` becomes `some-middleware`.)
|
|
97
|
-
3. Global route middleware, which are placed in the [`middleware/`
|
|
97
|
+
3. Global route middleware, which are placed in the [`middleware/`](/docs/guide/directory-structure/middleware) directory (with a `.global` suffix) and will be automatically run on every route change.
|
|
98
98
|
|
|
99
99
|
Example of an `auth` middleware protecting the `/dashboard` page:
|
|
100
100
|
|
|
@@ -84,7 +84,7 @@ This is similar to the [`nuxtServerInit` action](https://v2.nuxt.com/docs/direct
|
|
|
84
84
|
In this example, we leverage the [Pinia module](/modules/pinia) to create a global store and use it across the app.
|
|
85
85
|
|
|
86
86
|
::important
|
|
87
|
-
Make sure to install the Pinia module with `npx
|
|
87
|
+
Make sure to install the Pinia module with `npx nuxt module add pinia` or follow the [module's installation steps](https://pinia.vuejs.org/ssr/nuxt.html#Installation).
|
|
88
88
|
::
|
|
89
89
|
|
|
90
90
|
::code-group
|
|
@@ -10,26 +10,26 @@ Nuxt allows for select pages from your application to be rendered at build time.
|
|
|
10
10
|
|
|
11
11
|
## Crawl-based Pre-rendering
|
|
12
12
|
|
|
13
|
-
Use the [`
|
|
13
|
+
Use the [`nuxt generate` command](/docs/api/commands/generate) to build and pre-render your application using the [Nitro](/docs/guide/concepts/server-engine) crawler. This command is similar to `nuxt build` with the `nitro.static` option set to `true`, or running `nuxt build --prerender`.
|
|
14
14
|
|
|
15
15
|
This will build your site, stand up a nuxt instance, and, by default, prerender the root page `/` along with any of your site's pages it links to, any of your site's pages they link to, and so on.
|
|
16
16
|
|
|
17
17
|
::code-group{sync="pm"}
|
|
18
18
|
|
|
19
19
|
```bash [npm]
|
|
20
|
-
npx
|
|
20
|
+
npx nuxt generate
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
```bash [yarn]
|
|
24
|
-
yarn
|
|
24
|
+
yarn nuxt generate
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
```bash [pnpm]
|
|
28
|
-
pnpm
|
|
28
|
+
pnpm nuxt generate
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
```bash [bun]
|
|
32
|
-
bun x
|
|
32
|
+
bun x nuxt generate
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
::
|
|
@@ -45,8 +45,8 @@ Working of the Nitro crawler:
|
|
|
45
45
|
|
|
46
46
|
This is important to understand since pages that are not linked to a discoverable page can't be pre-rendered automatically.
|
|
47
47
|
|
|
48
|
-
::read-more{to="/docs/api/commands/generate#
|
|
49
|
-
Read more about the `
|
|
48
|
+
::read-more{to="/docs/api/commands/generate#nuxt-generate"}
|
|
49
|
+
Read more about the `nuxt generate` command.
|
|
50
50
|
::
|
|
51
51
|
|
|
52
52
|
### Selective Pre-rendering
|
|
@@ -70,14 +70,14 @@ By default, the workload gets distributed to the workers with the round robin st
|
|
|
70
70
|
|
|
71
71
|
There are two ways to deploy a Nuxt application to any static hosting services:
|
|
72
72
|
|
|
73
|
-
- Static site generation (SSG) with `ssr: true` pre-renders routes of your application at build time. (This is the default behavior when running `
|
|
73
|
+
- Static site generation (SSG) with `ssr: true` pre-renders routes of your application at build time. (This is the default behavior when running `nuxt generate`.) It will also generate `/200.html` and `/404.html` single-page app fallback pages, which can render dynamic routes or 404 errors on the client (though you may need to configure this on your static host).
|
|
74
74
|
- Alternatively, you can prerender your site with `ssr: false` (static single-page app). This will produce HTML pages with an empty `<div id="__nuxt"></div>` where your Vue app would normally be rendered. You will lose many SEO benefits of prerendering your site, so it is suggested instead to use [`<ClientOnly>`](/docs/api/components/client-only) to wrap the portions of your site that cannot be server rendered (if any).
|
|
75
75
|
|
|
76
76
|
:read-more{title="Nuxt prerendering" to="/docs/getting-started/prerendering"}
|
|
77
77
|
|
|
78
78
|
### Client-side Only Rendering
|
|
79
79
|
|
|
80
|
-
If you don't want to pre-render your routes, another way of using static hosting is to set the `ssr` property to `false` in the `nuxt.config` file. The `
|
|
80
|
+
If you don't want to pre-render your routes, another way of using static hosting is to set the `ssr` property to `false` in the `nuxt.config` file. The `nuxt generate` command will then output an `.output/public/index.html` entrypoint and JavaScript bundles like a classic client-side Vue.js application.
|
|
81
81
|
|
|
82
82
|
```ts twoslash [nuxt.config.ts]
|
|
83
83
|
export default defineNuxtConfig({
|
|
@@ -8,24 +8,24 @@ navigation.icon: i-lucide-circle-arrow-up
|
|
|
8
8
|
|
|
9
9
|
### Latest release
|
|
10
10
|
|
|
11
|
-
To upgrade Nuxt to the [latest release](https://github.com/nuxt/nuxt/releases), use the `
|
|
11
|
+
To upgrade Nuxt to the [latest release](https://github.com/nuxt/nuxt/releases), use the `nuxt upgrade` command.
|
|
12
12
|
|
|
13
13
|
::code-group{sync="pm"}
|
|
14
14
|
|
|
15
15
|
```bash [npm]
|
|
16
|
-
npx
|
|
16
|
+
npx nuxt upgrade
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
```bash [yarn]
|
|
20
|
-
yarn
|
|
20
|
+
yarn nuxt upgrade
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
```bash [pnpm]
|
|
24
|
-
pnpm
|
|
24
|
+
pnpm nuxt upgrade
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
```bash [bun]
|
|
28
|
-
bun x
|
|
28
|
+
bun x nuxt upgrade
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
::
|
|
@@ -40,7 +40,7 @@ The nightly release channel `latest` tag is currently tracking the Nuxt v4 branc
|
|
|
40
40
|
|
|
41
41
|
## Testing Nuxt 4
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
Nuxt 4 is **scheduled for release in Q2 2025**. It will include all the features currently available through `compatibilityVersion: 4`.
|
|
44
44
|
|
|
45
45
|
Until the release, it is possible to test many of Nuxt 4's breaking changes from Nuxt version 3.12+.
|
|
46
46
|
|
|
@@ -188,6 +188,10 @@ server/
|
|
|
188
188
|
nuxt.config.ts
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
+
::note
|
|
192
|
+
With this new structure, the `~` alias now points to the `app/` directory by default (your `srcDir`). This means `~/components` resolves to `app/components/`, `~/pages` to `app/pages/`, etc.
|
|
193
|
+
::
|
|
194
|
+
|
|
191
195
|
</details>
|
|
192
196
|
|
|
193
197
|
👉 For more details, see the [PR implementing this change](https://github.com/nuxt/nuxt/pull/27029).
|
|
@@ -218,7 +222,7 @@ You can also force a v3 folder structure with the following configuration:
|
|
|
218
222
|
export default defineNuxtConfig({
|
|
219
223
|
// This reverts the new srcDir default from `app` back to your root directory
|
|
220
224
|
srcDir: '.',
|
|
221
|
-
// This specifies the directory prefix for `
|
|
225
|
+
// This specifies the directory prefix for `router.options.ts` and `spa-loading-template.html`
|
|
222
226
|
dir: {
|
|
223
227
|
app: 'app'
|
|
224
228
|
}
|
|
@@ -430,7 +434,7 @@ export default defineNuxtConfig({
|
|
|
430
434
|
|
|
431
435
|
#### What Changed
|
|
432
436
|
|
|
433
|
-
When rendering a client-only page (with `ssr: false`), we optionally render a loading screen (from
|
|
437
|
+
When rendering a client-only page (with `ssr: false`), we optionally render a loading screen (from `~/app/spa-loading-template.html` - note that this has also changed to `~/spa-loading-template.html` in Nuxt 4), within the Nuxt app root:
|
|
434
438
|
|
|
435
439
|
```html
|
|
436
440
|
<div id="__nuxt">
|
|
@@ -1000,6 +1004,44 @@ These options have been set to their current values for some time and we do not
|
|
|
1000
1004
|
|
|
1001
1005
|
* `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)
|
|
1002
1006
|
|
|
1007
|
+
### Removal of Top-Level `generate` Configuration
|
|
1008
|
+
|
|
1009
|
+
🚦 **Impact Level**: Minimal
|
|
1010
|
+
|
|
1011
|
+
#### What Changed
|
|
1012
|
+
|
|
1013
|
+
The top-level `generate` configuration option is no longer available in Nuxt 4. This includes all of its properties:
|
|
1014
|
+
|
|
1015
|
+
* `generate.exclude` - for excluding routes from prerendering
|
|
1016
|
+
* `generate.routes` - for specifying routes to prerender
|
|
1017
|
+
|
|
1018
|
+
#### Reasons for Change
|
|
1019
|
+
|
|
1020
|
+
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+.
|
|
1021
|
+
|
|
1022
|
+
#### Migration Steps
|
|
1023
|
+
|
|
1024
|
+
Replace `generate` configuration with the corresponding `nitro.prerender` options:
|
|
1025
|
+
|
|
1026
|
+
```diff
|
|
1027
|
+
export default defineNuxtConfig({
|
|
1028
|
+
- generate: {
|
|
1029
|
+
- exclude: ['/admin', '/private'],
|
|
1030
|
+
- routes: ['/sitemap.xml', '/robots.txt']
|
|
1031
|
+
- }
|
|
1032
|
+
+ nitro: {
|
|
1033
|
+
+ prerender: {
|
|
1034
|
+
+ ignore: ['/admin', '/private'],
|
|
1035
|
+
+ routes: ['/sitemap.xml', '/robots.txt']
|
|
1036
|
+
+ }
|
|
1037
|
+
+ }
|
|
1038
|
+
})
|
|
1039
|
+
```
|
|
1040
|
+
|
|
1041
|
+
::read-more{to="https://nitro.build/config/#prerender"}
|
|
1042
|
+
Read more about Nitro's prerender configuration options.
|
|
1043
|
+
::
|
|
1044
|
+
|
|
1003
1045
|
## Nuxt 2 vs. Nuxt 3+
|
|
1004
1046
|
|
|
1005
1047
|
In the table below, there is a quick comparison between 3 versions of Nuxt:
|
|
@@ -1019,7 +1061,7 @@ Components Auto Import | ✅ | ✅ | ✅
|
|
|
1019
1061
|
Auto Imports | ❌ | ✅ | ✅
|
|
1020
1062
|
webpack | 4 | 4 | 5
|
|
1021
1063
|
Vite | ⚠️ Partial | 🚧 Partial | ✅
|
|
1022
|
-
|
|
1064
|
+
Nuxt CLI | ❌ Old | ✅ nuxt | ✅ nuxt
|
|
1023
1065
|
Static sites | ✅ | ✅ | ✅
|
|
1024
1066
|
|
|
1025
1067
|
## Nuxt 2 to Nuxt 3+
|
|
@@ -88,7 +88,7 @@ export default defineNuxtConfig({
|
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
::note
|
|
91
|
-
If you do use `ssr: false`, you should also place an HTML file in `~/
|
|
91
|
+
If you do use `ssr: false`, you should also place an HTML file in `~/spa-loading-template.html` with some HTML you would like to use to render a loading screen that will be rendered until your app is hydrated.
|
|
92
92
|
:read-more{title="SPA Loading Template" to="/docs/api/configuration/nuxt-config#spaloadingtemplate"}
|
|
93
93
|
::
|
|
94
94
|
|
|
@@ -96,10 +96,10 @@ If you do use `ssr: false`, you should also place an HTML file in `~/app/spa-loa
|
|
|
96
96
|
|
|
97
97
|
### Deploying a Static Client-Rendered App
|
|
98
98
|
|
|
99
|
-
If you deploy your app to [static hosting](/docs/getting-started/deployment#static-hosting) with the `
|
|
99
|
+
If you deploy your app to [static hosting](/docs/getting-started/deployment#static-hosting) with the `nuxt generate` or `nuxt build --prerender` commands, then by default, Nuxt will render every page as a separate static HTML file.
|
|
100
100
|
|
|
101
101
|
::warning
|
|
102
|
-
If you prerender your app with the `
|
|
102
|
+
If you prerender your app with the `nuxt generate` or `nuxt build --prerender` commands, then you will not be able to use any server endpoints as no server will be included in your output folder. If you need server functionality, use `nuxt build` instead.
|
|
103
103
|
::
|
|
104
104
|
|
|
105
105
|
If you are using purely client-side rendering, then this might be unnecessary. You might only need a single `index.html` file, plus `200.html` and `404.html` fallbacks, which you can tell your static web host to serve up for all requests.
|
|
@@ -7,7 +7,7 @@ description: "Nuxt provides a module system to extend the framework core and sim
|
|
|
7
7
|
|
|
8
8
|
When developing production-grade applications with Nuxt you might find that the framework's core functionality is not enough. Nuxt can be extended with configuration options and plugins, but maintaining these customizations across multiple projects can be tedious, repetitive and time-consuming. On the other hand, supporting every project's needs out of the box would make Nuxt very complex and hard to use.
|
|
9
9
|
|
|
10
|
-
This is one of the reasons why Nuxt provides a module system that makes it possible to extend the core. Nuxt modules are async functions that sequentially run when starting Nuxt in development mode using [`
|
|
10
|
+
This is one of the reasons why Nuxt provides a module system that makes it possible to extend the core. Nuxt modules are async functions that sequentially run when starting Nuxt in development mode using [`nuxt dev`](/docs/api/commands/dev) or building a project for production with [`nuxt build`](/docs/api/commands/build). They can override templates, configure webpack loaders, add CSS libraries, and perform many other useful tasks.
|
|
11
11
|
|
|
12
12
|
Best of all, Nuxt modules can be distributed in npm packages. This makes it possible for them to be reused across projects and shared with the community, helping create an ecosystem of high-quality add-ons.
|
|
13
13
|
|
|
@@ -5,7 +5,7 @@ description: "Nuxt is fully typed and provides helpful shortcuts to ensure you h
|
|
|
5
5
|
|
|
6
6
|
## Type-checking
|
|
7
7
|
|
|
8
|
-
By default, Nuxt doesn't check types when you run [`
|
|
8
|
+
By default, Nuxt doesn't check types when you run [`nuxt dev`](/docs/api/commands/dev) or [`nuxt build`](/docs/api/commands/build), for performance reasons.
|
|
9
9
|
|
|
10
10
|
To enable type-checking at build or development time, install `vue-tsc` and `typescript` as development dependency:
|
|
11
11
|
|
|
@@ -29,10 +29,10 @@ To enable type-checking at build or development time, install `vue-tsc` and `typ
|
|
|
29
29
|
|
|
30
30
|
::
|
|
31
31
|
|
|
32
|
-
Then, run [`
|
|
32
|
+
Then, run [`nuxt typecheck`](/docs/api/commands/typecheck) command to check your types:
|
|
33
33
|
|
|
34
34
|
```bash [Terminal]
|
|
35
|
-
npx
|
|
35
|
+
npx nuxt typecheck
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
To enable type-checking at build or development time, you can also use the [`typescript.typeCheck`](/docs/api/nuxt-config#typecheck) option in your `nuxt.config` file:
|
|
@@ -47,13 +47,13 @@ export default defineNuxtConfig({
|
|
|
47
47
|
|
|
48
48
|
## Auto-generated Types
|
|
49
49
|
|
|
50
|
-
When you run `
|
|
50
|
+
When you run `nuxt dev` or `nuxt build`, Nuxt generates the following files for IDE type support (and type checking):
|
|
51
51
|
|
|
52
52
|
### `.nuxt/nuxt.d.ts`
|
|
53
53
|
|
|
54
54
|
This file contains the types of any modules you are using, as well as the key types that Nuxt requires. Your IDE should recognize these types automatically.
|
|
55
55
|
|
|
56
|
-
Some of the references in the file are to files that are only generated within your `buildDir` (`.nuxt`) and therefore for full typings, you will need to run `
|
|
56
|
+
Some of the references in the file are to files that are only generated within your `buildDir` (`.nuxt`) and therefore for full typings, you will need to run `nuxt dev` or `nuxt build`.
|
|
57
57
|
|
|
58
58
|
### `.nuxt/tsconfig.json`
|
|
59
59
|
|
|
@@ -77,7 +77,7 @@ Nitro also [auto-generates types](/docs/guide/concepts/server-engine#typed-api-r
|
|
|
77
77
|
Keep in mind that all options extended from `./.nuxt/tsconfig.json` will be overwritten by the options defined in your `tsconfig.json`.
|
|
78
78
|
Overwriting options such as `"compilerOptions.paths"` with your own configuration will lead TypeScript to not factor in the module resolutions from `./.nuxt/tsconfig.json`. This can lead to module resolutions such as `#imports` not being recognized.
|
|
79
79
|
:br :br
|
|
80
|
-
In case you need to extend options provided by `./.nuxt/tsconfig.json` further, you can use the [`alias` property](/docs/api/nuxt-config#alias) within your `nuxt.config`.
|
|
80
|
+
In case you need to extend options provided by `./.nuxt/tsconfig.json` further, you can use the [`alias` property](/docs/api/nuxt-config#alias) within your `nuxt.config`. Nuxt will pick them up and extend `./.nuxt/tsconfig.json` accordingly.
|
|
81
81
|
::
|
|
82
82
|
|
|
83
83
|
## Strict Checks
|
|
@@ -14,7 +14,7 @@ The module is designed for the [new ESLint flat config format](https://eslint.or
|
|
|
14
14
|
## Quick Setup
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
npx
|
|
17
|
+
npx nuxt module add eslint
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
Start your Nuxt app, a `eslint.config.mjs` file will be generated under your project root. You can customize it as needed.
|
|
@@ -50,7 +50,7 @@ The `composables/` directory in Nuxt does not provide any additional reactivity
|
|
|
50
50
|
|
|
51
51
|
Under the hood, Nuxt auto generates the file `.nuxt/imports.d.ts` to declare the types.
|
|
52
52
|
|
|
53
|
-
Be aware that you have to run [`
|
|
53
|
+
Be aware that you have to run [`nuxt prepare`](/docs/api/commands/prepare), [`nuxt dev`](/docs/api/commands/dev) or [`nuxt build`](/docs/api/commands/build) in order to let Nuxt generate the types.
|
|
54
54
|
|
|
55
55
|
::note
|
|
56
56
|
If you create a composable without having the dev server running, TypeScript will throw an error, such as `Cannot find name 'useBar'.`
|
|
@@ -6,7 +6,7 @@ navigation.icon: i-lucide-folder
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
::note
|
|
9
|
-
To reduce your application's bundle size, this directory is **optional**, meaning that [`vue-router`](https://router.vuejs.org) won't be included if you only use [`app.vue`](/docs/guide/directory-structure/app). To force the pages system, set `pages: true` in `nuxt.config` or have a [`
|
|
9
|
+
To reduce your application's bundle size, this directory is **optional**, meaning that [`vue-router`](https://router.vuejs.org) won't be included if you only use [`app.vue`](/docs/guide/directory-structure/app). To force the pages system, set `pages: true` in `nuxt.config` or have a [`router.options.ts`](/docs/guide/recipes/custom-routing#using-approuteroptions).
|
|
10
10
|
::
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
@@ -405,7 +405,7 @@ You can define a page as [client only](/docs/guide/directory-structure/component
|
|
|
405
405
|
|
|
406
406
|
You can define a page as [server only](/docs/guide/directory-structure/components#server-components) by giving it a `.server.vue` suffix. While you will be able to navigate to the page using client-side navigation, controlled by `vue-router`, it will be rendered with a server component automatically, meaning the code required to render the page will not be in your client-side bundle.
|
|
407
407
|
|
|
408
|
-
::
|
|
408
|
+
::warning
|
|
409
409
|
Server-only pages must have a single root element. (HTML comments are considered elements as well.)
|
|
410
410
|
::
|
|
411
411
|
|
|
@@ -21,7 +21,7 @@ Learn more in **Nuxt Content** documentation.
|
|
|
21
21
|
Install the `@nuxt/content` module in your project as well as adding it to your `nuxt.config.ts` with one command:
|
|
22
22
|
|
|
23
23
|
```bash [Terminal]
|
|
24
|
-
npx
|
|
24
|
+
npx nuxt module add content
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
## Create Content
|
|
@@ -144,7 +144,7 @@ To improve clarity within your IDE between the auto-imports from 'nitro' and 'vu
|
|
|
144
144
|
}
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
-
Currently, these values won't be respected when type checking ([`
|
|
147
|
+
Currently, these values won't be respected when type checking ([`nuxt typecheck`](/docs/api/commands/typecheck)), but you should get better type hints in your IDE.
|
|
148
148
|
|
|
149
149
|
## Recipes
|
|
150
150
|
|
|
@@ -11,7 +11,7 @@ This file should be added to your [`.gitignore`](/docs/guide/directory-structure
|
|
|
11
11
|
|
|
12
12
|
## Dev, Build and Generate Time
|
|
13
13
|
|
|
14
|
-
Nuxt CLI has built-in [dotenv](https://github.com/motdotla/dotenv) support in development mode and when running [`
|
|
14
|
+
Nuxt CLI has built-in [dotenv](https://github.com/motdotla/dotenv) support in development mode and when running [`nuxt build`](/docs/api/commands/build) and [`nuxt generate`](/docs/api/commands/generate).
|
|
15
15
|
|
|
16
16
|
In addition to any process environment variables, if you have a `.env` file in your project root directory, it will be automatically loaded **at dev, build and generate time**. Any environment variables set there will be accessible within your `nuxt.config` file and modules.
|
|
17
17
|
|
|
@@ -25,10 +25,10 @@ Note that removing a variable from `.env` or removing the `.env` file entirely w
|
|
|
25
25
|
|
|
26
26
|
## Custom File
|
|
27
27
|
|
|
28
|
-
If you want to use a different file - for example, to use `.env.local` or `.env.production` - you can do so by passing the `--dotenv` flag when using
|
|
28
|
+
If you want to use a different file - for example, to use `.env.local` or `.env.production` - you can do so by passing the `--dotenv` flag when using the Nuxt CLI.
|
|
29
29
|
|
|
30
30
|
```bash [Terminal]
|
|
31
|
-
npx
|
|
31
|
+
npx nuxt dev --dotenv .env.local
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
When updating `.env` in development mode, the Nuxt instance is automatically restarted to apply new values to the `process.env`.
|
|
@@ -57,7 +57,7 @@ Since `.env` files are not used in production, you must explicitly set environme
|
|
|
57
57
|
|
|
58
58
|
## Production Preview
|
|
59
59
|
|
|
60
|
-
For local production preview purpose, we recommend using [`
|
|
60
|
+
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.
|
|
61
61
|
|
|
62
62
|
Or you could pass the environment variables as arguments using the terminal. For example, on Linux or macOS:
|
|
63
63
|
|
|
@@ -454,7 +454,7 @@ By setting `experimental.normalizeComponentNames`, these two values match, and V
|
|
|
454
454
|
|
|
455
455
|
## spaLoadingTemplateLocation
|
|
456
456
|
|
|
457
|
-
When rendering a client-only page (with `ssr: false`), we optionally render a loading screen (from
|
|
457
|
+
When rendering a client-only page (with `ssr: false`), we optionally render a loading screen (from `~/spa-loading-template.html`).
|
|
458
458
|
|
|
459
459
|
It can be set to `within`, which will render it like this:
|
|
460
460
|
|
|
@@ -7,7 +7,7 @@ This guide helps you better understand Nuxt internals to develop new solutions a
|
|
|
7
7
|
|
|
8
8
|
## The Nuxt Interface
|
|
9
9
|
|
|
10
|
-
When you start Nuxt in development mode with [`
|
|
10
|
+
When you start Nuxt in development mode with [`nuxt dev`](/docs/api/commands/dev) or building a production application with [`nuxt build`](/docs/api/commands/build),
|
|
11
11
|
a common context will be created, referred to as `nuxt` internally. It holds normalized options merged with `nuxt.config` file,
|
|
12
12
|
some internal state, and a powerful [hooking system](/docs/api/advanced/hooks) powered by [unjs/hookable](https://github.com/unjs/hookable)
|
|
13
13
|
allowing different components to communicate with each other. You can think of it as **Builder Core**.
|
|
@@ -78,4 +78,4 @@ While both areas can be extended, that runtime context is isolated from build-ti
|
|
|
78
78
|
|
|
79
79
|
`nuxt.config` and [Nuxt Modules](/docs/guide/going-further/modules) can be used to extend the build context, and [Nuxt Plugins](/docs/guide/directory-structure/plugins) can be used to extend runtime.
|
|
80
80
|
|
|
81
|
-
When building an application for production, `
|
|
81
|
+
When building an application for production, `nuxt build` will generate a standalone build in the `.output` directory, independent of `nuxt.config` and [Nuxt modules](/docs/guide/going-further/modules).
|
|
@@ -44,7 +44,7 @@ Instead of passing non-serializable objects or functions into your application f
|
|
|
44
44
|
The most common way to provide configuration is by using [Environment Variables](https://medium.com/chingu/an-introduction-to-environment-variables-and-how-to-use-them-f602f66d15fa).
|
|
45
45
|
|
|
46
46
|
::note
|
|
47
|
-
|
|
47
|
+
The Nuxt CLI has built-in support for reading your `.env` file in development, build and generate. But when you run your built server, **your `.env` file will not be read**.
|
|
48
48
|
:read-more{to="/docs/guide/directory-structure/env"}
|
|
49
49
|
::
|
|
50
50
|
|
|
@@ -49,16 +49,12 @@ Update `nuxt` dependency inside `package.json`:
|
|
|
49
49
|
|
|
50
50
|
Remove lockfile (`package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, or `bun.lockb`) and reinstall dependencies.
|
|
51
51
|
|
|
52
|
-
## Using Nightly `
|
|
53
|
-
|
|
54
|
-
::note
|
|
55
|
-
All cli dependencies are bundled because of the building method for reducing `nuxi` package size. :br You can get dependency updates and CLI improvements using the nightly release channel.
|
|
56
|
-
::
|
|
52
|
+
## Using Nightly `@nuxt/cli`
|
|
57
53
|
|
|
58
54
|
To try the latest version of [nuxt/cli](https://github.com/nuxt/cli):
|
|
59
55
|
|
|
60
56
|
```bash [Terminal]
|
|
61
|
-
npx
|
|
57
|
+
npx @nuxt/cli-nightly@latest [command]
|
|
62
58
|
```
|
|
63
59
|
|
|
64
60
|
::read-more{to="/docs/api/commands"}
|
|
@@ -6,7 +6,7 @@ image: '/socials/module-author-guide.jpg'
|
|
|
6
6
|
|
|
7
7
|
Nuxt's [configuration](/docs/api/nuxt-config) and [hooks](/docs/guide/going-further/hooks) systems make it possible to customize every aspect of Nuxt and add any integration you might need (Vue plugins, CMS, server routes, components, logging, etc.).
|
|
8
8
|
|
|
9
|
-
**Nuxt Modules** are functions that sequentially run when starting Nuxt in development mode using `
|
|
9
|
+
**Nuxt Modules** are functions that sequentially run when starting Nuxt in development mode using `nuxt dev` or building a project for production with `nuxt build`.
|
|
10
10
|
With modules, you can encapsulate, properly test, and share custom solutions as npm packages without adding unnecessary boilerplate to your project, or requiring changes to Nuxt itself.
|
|
11
11
|
|
|
12
12
|
## Quick Start
|
|
@@ -59,7 +59,7 @@ You can interact with the playground like with any Nuxt application.
|
|
|
59
59
|
- Build it with `npm run dev:build`
|
|
60
60
|
|
|
61
61
|
::note
|
|
62
|
-
All other `
|
|
62
|
+
All other `nuxt` commands can be used against the `playground` directory (e.g. `nuxt <COMMAND> playground`). Feel free to declare additional `dev:*` scripts within your `package.json` referencing them for convenience.
|
|
63
63
|
::
|
|
64
64
|
|
|
65
65
|
#### How to Test
|
|
@@ -614,7 +614,7 @@ export default defineNuxtModule({
|
|
|
614
614
|
interface MyModuleNitroRules {
|
|
615
615
|
myModule?: { foo: 'bar' }
|
|
616
616
|
}
|
|
617
|
-
declare module '
|
|
617
|
+
declare module 'nitropack/types' {
|
|
618
618
|
interface NitroRouteRules extends MyModuleNitroRules {}
|
|
619
619
|
interface NitroRouteConfig extends MyModuleNitroRules {}
|
|
620
620
|
}
|
|
@@ -22,7 +22,7 @@ export default defineNuxtConfig({
|
|
|
22
22
|
You can use [Node inspector](https://nodejs.org/en/learn/getting-started/debugging) to debug Nuxt server-side.
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
|
|
25
|
+
nuxt dev --inspect
|
|
26
26
|
```
|
|
27
27
|
This will start Nuxt in `dev` mode with debugger active. If everything is working correctly a Node.js icon will appear on your Chrome DevTools and you can attach to the debugger.
|
|
28
28
|
|
|
@@ -38,10 +38,6 @@ It is possible to debug your Nuxt app in your IDE while you are developing it.
|
|
|
38
38
|
|
|
39
39
|
You may need to update the config below with a path to your web browser. For more information, visit the [VS Code documentation about debug configuration](https://go.microsoft.com/fwlink/?linkid=830387).
|
|
40
40
|
|
|
41
|
-
::important
|
|
42
|
-
If you use `pnpm`, you will need to have `nuxi` installed as a devDependency for the configuration below to work.
|
|
43
|
-
::
|
|
44
|
-
|
|
45
41
|
```json5
|
|
46
42
|
{
|
|
47
43
|
// Use IntelliSense to learn about possible attributes.
|
|
@@ -13,7 +13,7 @@ Using [router options](/docs/guide/recipes/custom-routing#router-options), you c
|
|
|
13
13
|
|
|
14
14
|
If it returns `null` or `undefined`, Nuxt will fall back to the default routes (useful to modify input array).
|
|
15
15
|
|
|
16
|
-
```ts [
|
|
16
|
+
```ts [router.options.ts]
|
|
17
17
|
import type { RouterConfig } from '@nuxt/schema'
|
|
18
18
|
|
|
19
19
|
export default {
|
|
@@ -83,11 +83,11 @@ The [Nuxt kit](/docs/guide/going-further/kit) provides a few ways [to add routes
|
|
|
83
83
|
|
|
84
84
|
On top of customizing options for [`vue-router`](https://router.vuejs.org/api/interfaces/routeroptions.html), Nuxt offers [additional options](/docs/api/nuxt-config#router) to customize the router.
|
|
85
85
|
|
|
86
|
-
### Using `
|
|
86
|
+
### Using `router.options`
|
|
87
87
|
|
|
88
88
|
This is the recommended way to specify [router options](/docs/api/nuxt-config#router).
|
|
89
89
|
|
|
90
|
-
```ts [
|
|
90
|
+
```ts [router.options.ts]
|
|
91
91
|
import type { RouterConfig } from '@nuxt/schema'
|
|
92
92
|
|
|
93
93
|
export default {
|
|
@@ -109,7 +109,7 @@ export default defineNuxtConfig({
|
|
|
109
109
|
const resolver = createResolver(import.meta.url)
|
|
110
110
|
// add a route
|
|
111
111
|
files.push({
|
|
112
|
-
path: resolver.resolve('./runtime/
|
|
112
|
+
path: resolver.resolve('./runtime/router-options'),
|
|
113
113
|
optional: true
|
|
114
114
|
})
|
|
115
115
|
}
|
|
@@ -170,7 +170,7 @@ export default defineNuxtConfig({
|
|
|
170
170
|
|
|
171
171
|
You can optionally override history mode using a function that accepts the base URL and returns the history mode. If it returns `null` or `undefined`, Nuxt will fallback to the default history.
|
|
172
172
|
|
|
173
|
-
```ts [
|
|
173
|
+
```ts [router.options.ts]
|
|
174
174
|
import type { RouterConfig } from '@nuxt/schema'
|
|
175
175
|
import { createMemoryHistory } from 'vue-router'
|
|
176
176
|
|
|
@@ -11,10 +11,10 @@ The module uses secured & sealed cookies to store session data, so you don't nee
|
|
|
11
11
|
|
|
12
12
|
## Install nuxt-auth-utils
|
|
13
13
|
|
|
14
|
-
Install the `nuxt-auth-utils` module using the `
|
|
14
|
+
Install the `nuxt-auth-utils` module using the `nuxt` CLI.
|
|
15
15
|
|
|
16
16
|
```bash [Terminal]
|
|
17
|
-
npx
|
|
17
|
+
npx nuxt module add auth-utils
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
::callout
|
|
@@ -19,7 +19,7 @@ Learn more about the [`<picture>` tag on MDN](https://developer.mozilla.org/en-U
|
|
|
19
19
|
In order to use `<NuxtPicture>` you should install and enable the Nuxt Image module:
|
|
20
20
|
|
|
21
21
|
```bash [Terminal]
|
|
22
|
-
npx
|
|
22
|
+
npx nuxt module add image
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
::read-more{to="https://image.nuxt.com/usage/nuxt-picture" target="_blank"}
|