@nuxt/docs 4.0.0-0 → 4.0.0-alpha.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 +3 -3
- package/1.getting-started/02.installation.md +1 -1
- package/1.getting-started/03.configuration.md +3 -3
- package/1.getting-started/06.styling.md +1 -1
- package/1.getting-started/07.routing.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/17.testing.md +1 -1
- package/1.getting-started/18.upgrade.md +6 -6
- package/2.guide/1.concepts/3.rendering.md +2 -2
- 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.composables.md +7 -7
- package/2.guide/2.directory-structure/1.content.md +1 -1
- package/2.guide/2.directory-structure/1.pages.md +4 -4
- 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.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/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-fetch.md +1 -1
- package/3.api/2.composables/use-preview-mode.md +3 -3
- 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 +1 -1
- package/3.api/5.kit/7.pages.md +1 -1
- package/3.api/6.advanced/1.hooks.md +1 -1
- package/3.api/6.nuxt-config.md +2956 -3
- package/5.community/4.contribution.md +1 -1
- package/5.community/7.changelog.md +1 -1
- package/7.migration/2.configuration.md +2 -2
- package/package.json +1 -1
|
@@ -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
|
|
|
@@ -21,7 +21,7 @@ Or follow the steps below to set up a new Nuxt project on your computer.
|
|
|
21
21
|
<!-- markdownlint-disable-next-line MD001 -->
|
|
22
22
|
#### Prerequisites
|
|
23
23
|
|
|
24
|
-
- **Node.js** - [`
|
|
24
|
+
- **Node.js** - [`20.x`](https://nodejs.org/en) or newer (but we recommend the [active LTS release](https://github.com/nodejs/release#release-schedule))
|
|
25
25
|
- **Text editor** - There is no IDE requirement, but we recommend [Visual Studio Code](https://code.visualstudio.com/) with the [official Vue extension](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (previously known as Volar) or [WebStorm](https://www.jetbrains.com/webstorm/), which, along with [other JetBrains IDEs](https://www.jetbrains.com/ides/), offers great Nuxt support right out-of-the-box.
|
|
26
26
|
- **Terminal** - In order to run Nuxt commands
|
|
27
27
|
|
|
@@ -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
|
|
|
@@ -171,8 +171,8 @@ Name | Config File | How To
|
|
|
171
171
|
|
|
172
172
|
If you need to pass options to `@vitejs/plugin-vue` or `@vitejs/plugin-vue-jsx`, you can do this in your `nuxt.config` file.
|
|
173
173
|
|
|
174
|
-
- `vite.vue` for `@vitejs/plugin-vue`. Check available options
|
|
175
|
-
- `vite.vueJsx` for `@vitejs/plugin-vue-jsx`. Check available options
|
|
174
|
+
- `vite.vue` for `@vitejs/plugin-vue`. Check [available options](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue).
|
|
175
|
+
- `vite.vueJsx` for `@vitejs/plugin-vue-jsx`. Check [available options](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue-jsx).
|
|
176
176
|
|
|
177
177
|
```ts twoslash [nuxt.config.ts]
|
|
178
178
|
export default defineNuxtConfig({
|
|
@@ -145,7 +145,7 @@ useHead({
|
|
|
145
145
|
})
|
|
146
146
|
```
|
|
147
147
|
|
|
148
|
-
Nuxt uses `unhead` under the hood, and you can refer to its full documentation
|
|
148
|
+
Nuxt uses `unhead` under the hood, and you can refer to [its full documentation](https://unhead.unjs.io).
|
|
149
149
|
|
|
150
150
|
### Modifying The Rendered Head With A Nitro Plugin
|
|
151
151
|
|
|
@@ -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({
|
|
@@ -280,7 +280,7 @@ mockNuxtImport('useStorage', () => {
|
|
|
280
280
|
```
|
|
281
281
|
|
|
282
282
|
::note
|
|
283
|
-
`mockNuxtImport` can only be used once per mocked import per test file. It is actually a macro that gets transformed to `vi.mock` and `vi.mock` is hoisted, as described [
|
|
283
|
+
`mockNuxtImport` can only be used once per mocked import per test file. It is actually a macro that gets transformed to `vi.mock` and `vi.mock` is hoisted, as described [in the Vitest docs](https://vitest.dev/api/vi.html#vi-mock).
|
|
284
284
|
::
|
|
285
285
|
|
|
286
286
|
If you need to mock a Nuxt import and provide different implementations between tests, you can do it by creating and exposing your mocks using [`vi.hoisted`](https://vitest.dev/api/vi.html#vi-hoisted), and then use those mocks in `mockNuxtImport`. You then have access to the mocked imports, and can change the implementation between tests. Be careful to [restore mocks](https://vitest.dev/api/mock.html#mockrestore) before or after each test to undo mock state changes between runs.
|
|
@@ -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
|
::
|
|
@@ -1019,7 +1019,7 @@ Components Auto Import | ✅ | ✅ | ✅
|
|
|
1019
1019
|
Auto Imports | ❌ | ✅ | ✅
|
|
1020
1020
|
webpack | 4 | 4 | 5
|
|
1021
1021
|
Vite | ⚠️ Partial | 🚧 Partial | ✅
|
|
1022
|
-
|
|
1022
|
+
Nuxt CLI | ❌ Old | ✅ nuxt | ✅ nuxt
|
|
1023
1023
|
Static sites | ✅ | ✅ | ✅
|
|
1024
1024
|
|
|
1025
1025
|
## Nuxt 2 to Nuxt 3+
|
|
@@ -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'.`
|
|
@@ -109,12 +109,12 @@ export { utils } from './nested/utils.ts'
|
|
|
109
109
|
export default defineNuxtConfig({
|
|
110
110
|
imports: {
|
|
111
111
|
dirs: [
|
|
112
|
-
// Scan top-level
|
|
113
|
-
'composables',
|
|
114
|
-
// ... or scan
|
|
115
|
-
'composables/*/index.{ts,js,mjs,mts}',
|
|
116
|
-
// ... or scan all
|
|
117
|
-
'composables/**'
|
|
112
|
+
// Scan top-level composables
|
|
113
|
+
'~/composables',
|
|
114
|
+
// ... or scan composables nested one level deep with a specific name and file extension
|
|
115
|
+
'~/composables/*/index.{ts,js,mjs,mts}',
|
|
116
|
+
// ... or scan all composables within given directory
|
|
117
|
+
'~/composables/**'
|
|
118
118
|
]
|
|
119
119
|
}
|
|
120
120
|
})
|
|
@@ -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
|
|
@@ -299,13 +299,13 @@ Of course, you are welcome to define metadata for your own use throughout your a
|
|
|
299
299
|
|
|
300
300
|
#### `alias`
|
|
301
301
|
|
|
302
|
-
You can define page aliases. They allow you to access the same page from different paths. It can be either a string or an array of strings as defined [
|
|
302
|
+
You can define page aliases. They allow you to access the same page from different paths. It can be either a string or an array of strings as defined [in the vue-router documentation](https://router.vuejs.org/guide/essentials/redirect-and-alias.html#Alias).
|
|
303
303
|
|
|
304
304
|
#### `keepalive`
|
|
305
305
|
|
|
306
306
|
Nuxt will automatically wrap your page in [the Vue `<KeepAlive>` component](https://vuejs.org/guide/built-ins/keep-alive.html#keepalive) if you set `keepalive: true` in your `definePageMeta`. This might be useful to do, for example, in a parent route that has dynamic child routes, if you want to preserve page state across route changes.
|
|
307
307
|
|
|
308
|
-
When your goal is to preserve state for parent routes use this syntax: `<NuxtPage keepalive />`. You can also set props to be passed to `<KeepAlive>` (see a full list
|
|
308
|
+
When your goal is to preserve state for parent routes use this syntax: `<NuxtPage keepalive />`. You can also set props to be passed to `<KeepAlive>` (see [a full list](https://vuejs.org/api/built-in-components.html#keepalive)).
|
|
309
309
|
|
|
310
310
|
You can set a default value for this property [in your `nuxt.config`](/docs/api/nuxt-config#keepalive).
|
|
311
311
|
|
|
@@ -319,7 +319,7 @@ You can define the layout used to render the route. This can be either false (to
|
|
|
319
319
|
|
|
320
320
|
#### `layoutTransition` and `pageTransition`
|
|
321
321
|
|
|
322
|
-
You can define transition properties for the `<transition>` component that wraps your pages and layouts, or pass `false` to disable the `<transition>` wrapper for that route. You can see a list of options that can be passed
|
|
322
|
+
You can define transition properties for the `<transition>` component that wraps your pages and layouts, or pass `false` to disable the `<transition>` wrapper for that route. You can see [a list of options that can be passed](https://vuejs.org/api/built-in-components.html#transition) or read [more about how transitions work](https://vuejs.org/guide/built-ins/transition.html#transition).
|
|
323
323
|
|
|
324
324
|
You can set default values for these properties [in your `nuxt.config`](/docs/api/nuxt-config#layouttransition).
|
|
325
325
|
|
|
@@ -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
|
|
|
@@ -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
|
|
|
@@ -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.
|
|
@@ -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"}
|
|
@@ -98,7 +98,7 @@ The `handler` function should be **side-effect free** to ensure predictable beha
|
|
|
98
98
|
Which only caches data when `experimental.payloadExtraction` of `nuxt.config` is enabled.
|
|
99
99
|
- `pick`: only pick specified keys in this array from the `handler` function result
|
|
100
100
|
- `watch`: watch reactive sources to auto-refresh
|
|
101
|
-
- `deep`: return data in a deep ref object. It is `false` by default to return data in a shallow ref object
|
|
101
|
+
- `deep`: return data in a deep ref object. It is `false` by default to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive.
|
|
102
102
|
- `dedupe`: avoid fetching same key more than once at a time (defaults to `cancel`). Possible options:
|
|
103
103
|
- `cancel` - cancels existing requests when a new one is made
|
|
104
104
|
- `defer` - does not make new requests at all if there is a pending request
|
|
@@ -132,7 +132,7 @@ All fetch options can be given a `computed` or `ref` value. These will be watche
|
|
|
132
132
|
Which only caches data when `experimental.payloadExtraction` of `nuxt.config` is enabled.
|
|
133
133
|
- `pick`: only pick specified keys in this array from the `handler` function result
|
|
134
134
|
- `watch`: watch an array of reactive sources and auto-refresh the fetch result when they change. Fetch options and URL are watched by default. You can completely ignore reactive sources by using `watch: false`. Together with `immediate: false`, this allows for a fully-manual `useFetch`. (You can [see an example here](/docs/getting-started/data-fetching#watch) of using `watch`.)
|
|
135
|
-
- `deep`: return data in a deep ref object. It is `false` by default to return data in a shallow ref object
|
|
135
|
+
- `deep`: return data in a deep ref object. It is `false` by default to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive.
|
|
136
136
|
- `dedupe`: avoid fetching same key more than once at a time (defaults to `cancel`). Possible options:
|
|
137
137
|
- `cancel` - cancels existing requests when a new one is made
|
|
138
138
|
- `defer` - does not make new requests at all if there is a pending request
|
|
@@ -103,8 +103,8 @@ const { data } = await useFetch('/api/preview', {
|
|
|
103
103
|
Now you can generate your site and serve it:
|
|
104
104
|
|
|
105
105
|
```bash [Terminal]
|
|
106
|
-
npx
|
|
107
|
-
npx
|
|
106
|
+
npx nuxt generate
|
|
107
|
+
npx nuxt preview
|
|
108
108
|
```
|
|
109
109
|
|
|
110
110
|
Then you can see your preview page by adding the query param `preview` to the end of the page you want to see once:
|
|
@@ -114,5 +114,5 @@ Then you can see your preview page by adding the query param `preview` to the en
|
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
::note
|
|
117
|
-
`usePreviewMode` should be tested locally with `
|
|
117
|
+
`usePreviewMode` should be tested locally with `nuxt generate` and then `nuxt preview` rather than `nuxt dev`. (The [preview command](/docs/api/commands/preview) is not related to preview mode.)
|
|
118
118
|
::
|