@nuxt/docs 0.0.0 → 3.17.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.
- package/.navigation.yml +2 -0
- package/1.getting-started/.navigation.yml +3 -0
- package/1.getting-started/01.introduction.md +81 -0
- package/1.getting-started/02.installation.md +109 -0
- package/1.getting-started/03.configuration.md +226 -0
- package/1.getting-started/04.views.md +163 -0
- package/1.getting-started/05.assets.md +48 -0
- package/1.getting-started/06.styling.md +565 -0
- package/1.getting-started/07.routing.md +149 -0
- package/1.getting-started/08.seo-meta.md +360 -0
- package/1.getting-started/09.transitions.md +473 -0
- package/1.getting-started/10.data-fetching.md +795 -0
- package/1.getting-started/11.state-management.md +223 -0
- package/1.getting-started/12.error-handling.md +233 -0
- package/1.getting-started/13.server.md +94 -0
- package/1.getting-started/14.layers.md +92 -0
- package/1.getting-started/15.prerendering.md +194 -0
- package/1.getting-started/16.deployment.md +130 -0
- package/1.getting-started/17.testing.md +728 -0
- package/1.getting-started/18.upgrade.md +997 -0
- package/2.guide/.navigation.yml +2 -0
- package/2.guide/0.index.md +22 -0
- package/2.guide/1.concepts/.navigation.yml +3 -0
- package/2.guide/1.concepts/1.auto-imports.md +205 -0
- package/2.guide/1.concepts/10.nuxt-lifecycle.md +141 -0
- package/2.guide/1.concepts/2.vuejs-development.md +103 -0
- package/2.guide/1.concepts/3.rendering.md +255 -0
- package/2.guide/1.concepts/4.server-engine.md +62 -0
- package/2.guide/1.concepts/5.modules.md +48 -0
- package/2.guide/1.concepts/7.esm.md +299 -0
- package/2.guide/1.concepts/8.typescript.md +97 -0
- package/2.guide/1.concepts/9.code-style.md +22 -0
- package/2.guide/2.directory-structure/.navigation.yml +3 -0
- package/2.guide/2.directory-structure/0.nuxt.md +20 -0
- package/2.guide/2.directory-structure/0.output.md +18 -0
- package/2.guide/2.directory-structure/1.assets.md +16 -0
- package/2.guide/2.directory-structure/1.components.md +608 -0
- package/2.guide/2.directory-structure/1.composables.md +121 -0
- package/2.guide/2.directory-structure/1.content.md +64 -0
- package/2.guide/2.directory-structure/1.layouts.md +180 -0
- package/2.guide/2.directory-structure/1.middleware.md +209 -0
- package/2.guide/2.directory-structure/1.modules.md +66 -0
- package/2.guide/2.directory-structure/1.node_modules.md +12 -0
- package/2.guide/2.directory-structure/1.pages.md +440 -0
- package/2.guide/2.directory-structure/1.plugins.md +299 -0
- package/2.guide/2.directory-structure/1.public.md +27 -0
- package/2.guide/2.directory-structure/1.server.md +546 -0
- package/2.guide/2.directory-structure/1.shared.md +104 -0
- package/2.guide/2.directory-structure/1.utils.md +49 -0
- package/2.guide/2.directory-structure/2.env.md +75 -0
- package/2.guide/2.directory-structure/2.gitignore.md +37 -0
- package/2.guide/2.directory-structure/2.nuxtignore.md +36 -0
- package/2.guide/2.directory-structure/2.nuxtrc.md +50 -0
- package/2.guide/2.directory-structure/3.app-config.md +177 -0
- package/2.guide/2.directory-structure/3.app.md +72 -0
- package/2.guide/2.directory-structure/3.error.md +55 -0
- package/2.guide/2.directory-structure/3.nuxt-config.md +34 -0
- package/2.guide/2.directory-structure/3.package.md +32 -0
- package/2.guide/2.directory-structure/3.tsconfig.md +24 -0
- package/2.guide/3.going-further/.navigation.yml +3 -0
- package/2.guide/3.going-further/1.experimental-features.md +689 -0
- package/2.guide/3.going-further/1.features.md +103 -0
- package/2.guide/3.going-further/1.internals.md +81 -0
- package/2.guide/3.going-further/10.runtime-config.md +174 -0
- package/2.guide/3.going-further/11.nightly-release-channel.md +68 -0
- package/2.guide/3.going-further/2.hooks.md +98 -0
- package/2.guide/3.going-further/3.modules.md +811 -0
- package/2.guide/3.going-further/4.kit.md +51 -0
- package/2.guide/3.going-further/6.nuxt-app.md +64 -0
- package/2.guide/3.going-further/7.layers.md +227 -0
- package/2.guide/3.going-further/9.debugging.md +115 -0
- package/2.guide/3.going-further/index.md +4 -0
- package/2.guide/4.recipes/.navigation.yml +3 -0
- package/2.guide/4.recipes/1.custom-routing.md +181 -0
- package/2.guide/4.recipes/2.vite-plugin.md +65 -0
- package/2.guide/4.recipes/3.custom-usefetch.md +125 -0
- package/2.guide/4.recipes/4.sessions-and-authentication.md +203 -0
- package/3.api/.navigation.yml +3 -0
- package/3.api/1.components/.navigation.yml +3 -0
- package/3.api/1.components/1.client-only.md +76 -0
- package/3.api/1.components/1.dev-only.md +51 -0
- package/3.api/1.components/1.nuxt-client-fallback.md +80 -0
- package/3.api/1.components/10.nuxt-picture.md +27 -0
- package/3.api/1.components/11.teleports.md +40 -0
- package/3.api/1.components/12.nuxt-route-announcer.md +56 -0
- package/3.api/1.components/13.nuxt-time.md +173 -0
- package/3.api/1.components/2.nuxt-page.md +154 -0
- package/3.api/1.components/3.nuxt-layout.md +156 -0
- package/3.api/1.components/4.nuxt-link.md +322 -0
- package/3.api/1.components/5.nuxt-loading-indicator.md +50 -0
- package/3.api/1.components/6.nuxt-error-boundary.md +65 -0
- package/3.api/1.components/7.nuxt-welcome.md +25 -0
- package/3.api/1.components/8.nuxt-island.md +70 -0
- package/3.api/1.components/9.nuxt-img.md +43 -0
- package/3.api/2.composables/.navigation.yml +3 -0
- package/3.api/2.composables/on-prehydrate.md +60 -0
- package/3.api/2.composables/use-app-config.md +19 -0
- package/3.api/2.composables/use-async-data.md +212 -0
- package/3.api/2.composables/use-cookie.md +233 -0
- package/3.api/2.composables/use-error.md +32 -0
- package/3.api/2.composables/use-fetch.md +217 -0
- package/3.api/2.composables/use-head-safe.md +55 -0
- package/3.api/2.composables/use-head.md +69 -0
- package/3.api/2.composables/use-hydration.md +68 -0
- package/3.api/2.composables/use-lazy-async-data.md +47 -0
- package/3.api/2.composables/use-lazy-fetch.md +55 -0
- package/3.api/2.composables/use-loading-indicator.md +77 -0
- package/3.api/2.composables/use-nuxt-app.md +294 -0
- package/3.api/2.composables/use-nuxt-data.md +112 -0
- package/3.api/2.composables/use-preview-mode.md +118 -0
- package/3.api/2.composables/use-request-event.md +23 -0
- package/3.api/2.composables/use-request-fetch.md +52 -0
- package/3.api/2.composables/use-request-header.md +34 -0
- package/3.api/2.composables/use-request-headers.md +37 -0
- package/3.api/2.composables/use-request-url.md +41 -0
- package/3.api/2.composables/use-response-header.md +48 -0
- package/3.api/2.composables/use-route-announcer.md +60 -0
- package/3.api/2.composables/use-route.md +52 -0
- package/3.api/2.composables/use-router.md +92 -0
- package/3.api/2.composables/use-runtime-config.md +142 -0
- package/3.api/2.composables/use-runtime-hook.md +43 -0
- package/3.api/2.composables/use-seo-meta.md +80 -0
- package/3.api/2.composables/use-server-seo-meta.md +27 -0
- package/3.api/2.composables/use-state.md +48 -0
- package/3.api/3.utils/$fetch.md +98 -0
- package/3.api/3.utils/.navigation.yml +3 -0
- package/3.api/3.utils/abort-navigation.md +73 -0
- package/3.api/3.utils/add-route-middleware.md +88 -0
- package/3.api/3.utils/call-once.md +92 -0
- package/3.api/3.utils/clear-error.md +29 -0
- package/3.api/3.utils/clear-nuxt-data.md +23 -0
- package/3.api/3.utils/clear-nuxt-state.md +23 -0
- package/3.api/3.utils/create-error.md +55 -0
- package/3.api/3.utils/define-nuxt-component.md +53 -0
- package/3.api/3.utils/define-nuxt-route-middleware.md +67 -0
- package/3.api/3.utils/define-page-meta.md +234 -0
- package/3.api/3.utils/define-route-rules.md +52 -0
- package/3.api/3.utils/navigate-to.md +230 -0
- package/3.api/3.utils/on-before-route-leave.md +11 -0
- package/3.api/3.utils/on-before-route-update.md +11 -0
- package/3.api/3.utils/on-nuxt-ready.md +25 -0
- package/3.api/3.utils/prefetch-components.md +28 -0
- package/3.api/3.utils/preload-components.md +23 -0
- package/3.api/3.utils/preload-route-components.md +41 -0
- package/3.api/3.utils/prerender-routes.md +46 -0
- package/3.api/3.utils/refresh-cookie.md +46 -0
- package/3.api/3.utils/refresh-nuxt-data.md +91 -0
- package/3.api/3.utils/reload-nuxt-app.md +74 -0
- package/3.api/3.utils/set-page-layout.md +24 -0
- package/3.api/3.utils/set-response-status.md +36 -0
- package/3.api/3.utils/show-error.md +31 -0
- package/3.api/3.utils/update-app-config.md +27 -0
- package/3.api/4.commands/.navigation.yml +3 -0
- package/3.api/4.commands/add.md +112 -0
- package/3.api/4.commands/analyze.md +41 -0
- package/3.api/4.commands/build-module.md +42 -0
- package/3.api/4.commands/build.md +46 -0
- package/3.api/4.commands/cleanup.md +38 -0
- package/3.api/4.commands/dev.md +59 -0
- package/3.api/4.commands/devtools.md +38 -0
- package/3.api/4.commands/generate.md +41 -0
- package/3.api/4.commands/info.md +33 -0
- package/3.api/4.commands/init.md +46 -0
- package/3.api/4.commands/module.md +84 -0
- package/3.api/4.commands/prepare.md +36 -0
- package/3.api/4.commands/preview.md +43 -0
- package/3.api/4.commands/typecheck.md +42 -0
- package/3.api/4.commands/upgrade.md +37 -0
- package/3.api/5.kit/.navigation.yml +3 -0
- package/3.api/5.kit/1.modules.md +172 -0
- package/3.api/5.kit/10.runtime-config.md +27 -0
- package/3.api/5.kit/10.templates.md +283 -0
- package/3.api/5.kit/11.nitro.md +409 -0
- package/3.api/5.kit/12.resolving.md +268 -0
- package/3.api/5.kit/13.logging.md +65 -0
- package/3.api/5.kit/14.builder.md +491 -0
- package/3.api/5.kit/15.examples.md +41 -0
- package/3.api/5.kit/2.programmatic.md +125 -0
- package/3.api/5.kit/3.compatibility.md +230 -0
- package/3.api/5.kit/4.autoimports.md +144 -0
- package/3.api/5.kit/5.components.md +127 -0
- package/3.api/5.kit/6.context.md +130 -0
- package/3.api/5.kit/7.pages.md +295 -0
- package/3.api/5.kit/8.layout.md +80 -0
- package/3.api/5.kit/9.plugins.md +263 -0
- package/3.api/6.advanced/.navigation.yml +1 -0
- package/3.api/6.advanced/1.hooks.md +105 -0
- package/3.api/6.advanced/2.import-meta.md +60 -0
- package/3.api/6.nuxt-config.md +12 -0
- package/3.api/index.md +31 -0
- package/5.community/.navigation.yml +3 -0
- package/5.community/2.getting-help.md +48 -0
- package/5.community/3.reporting-bugs.md +50 -0
- package/5.community/4.contribution.md +205 -0
- package/5.community/5.framework-contribution.md +142 -0
- package/5.community/6.roadmap.md +79 -0
- package/5.community/7.changelog.md +92 -0
- package/6.bridge/.navigation.yml +3 -0
- package/6.bridge/1.overview.md +137 -0
- package/6.bridge/10.configuration.md +96 -0
- package/6.bridge/2.typescript.md +46 -0
- package/6.bridge/3.bridge-composition-api.md +132 -0
- package/6.bridge/4.plugins-and-middleware.md +65 -0
- package/6.bridge/5.nuxt3-compatible-api.md +204 -0
- package/6.bridge/6.meta.md +117 -0
- package/6.bridge/7.runtime-config.md +38 -0
- package/6.bridge/8.nitro.md +102 -0
- package/6.bridge/9.vite.md +37 -0
- package/7.migration/.navigation.yml +3 -0
- package/7.migration/1.overview.md +24 -0
- package/7.migration/10.bundling.md +28 -0
- package/7.migration/11.server.md +17 -0
- package/7.migration/2.configuration.md +240 -0
- package/7.migration/20.module-authors.md +94 -0
- package/7.migration/3.auto-imports.md +18 -0
- package/7.migration/4.meta.md +127 -0
- package/7.migration/5.plugins-and-middleware.md +80 -0
- package/7.migration/6.pages-and-layouts.md +233 -0
- package/7.migration/7.component-options.md +156 -0
- package/7.migration/8.runtime-config.md +58 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/package.json +16 -4
- package/dist/.gitkeep +0 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: ".env"
|
|
3
|
+
description: "A .env file specifies your build/dev-time environment variables."
|
|
4
|
+
head.title: ".env"
|
|
5
|
+
navigation.icon: i-lucide-file
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
::important
|
|
9
|
+
This file should be added to your [`.gitignore`](/docs/guide/directory-structure/gitignore) file to avoid pushing secrets to your repository.
|
|
10
|
+
::
|
|
11
|
+
|
|
12
|
+
## Dev, Build and Generate Time
|
|
13
|
+
|
|
14
|
+
Nuxt CLI has built-in [dotenv](https://github.com/motdotla/dotenv) support in development mode and when running [`nuxi build`](/docs/api/commands/build) and [`nuxi generate`](/docs/api/commands/generate).
|
|
15
|
+
|
|
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
|
+
|
|
18
|
+
```ini [.env]
|
|
19
|
+
MY_ENV_VARIABLE=hello
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
::note
|
|
23
|
+
Note that removing a variable from `.env` or removing the `.env` file entirely will not unset values that have already been set.
|
|
24
|
+
::
|
|
25
|
+
|
|
26
|
+
## Custom File
|
|
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 `nuxi`.
|
|
29
|
+
|
|
30
|
+
```bash [Terminal]
|
|
31
|
+
npx nuxi dev --dotenv .env.local
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
When updating `.env` in development mode, the Nuxt instance is automatically restarted to apply new values to the `process.env`.
|
|
35
|
+
|
|
36
|
+
::important
|
|
37
|
+
In your application code, you should use [Runtime Config](/docs/guide/going-further/runtime-config) instead of plain env variables.
|
|
38
|
+
::
|
|
39
|
+
|
|
40
|
+
## Production
|
|
41
|
+
|
|
42
|
+
**After your server is built**, you are responsible for setting environment variables when you run the server.
|
|
43
|
+
|
|
44
|
+
Your `.env` files will not be read at this point. How you do this is different for every environment.
|
|
45
|
+
|
|
46
|
+
This design decision was made to ensure compatibility across various deployment environments, some of which may not have a traditional file system available, such as serverless platforms or edge networks like Cloudflare Workers.
|
|
47
|
+
|
|
48
|
+
Since `.env` files are not used in production, you must explicitly set environment variables using the tools and methods provided by your hosting environment. Here are some common approaches:
|
|
49
|
+
|
|
50
|
+
* You can pass the environment variables as arguments using the terminal:
|
|
51
|
+
|
|
52
|
+
`$ DATABASE_HOST=mydatabaseconnectionstring node .output/server/index.mjs`
|
|
53
|
+
|
|
54
|
+
* You can set environment variables in shell configuration files like `.bashrc` or `.profile`.
|
|
55
|
+
|
|
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
|
+
|
|
58
|
+
## Production Preview
|
|
59
|
+
|
|
60
|
+
For local production preview purpose, we recommend using [`nuxi 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
|
+
|
|
62
|
+
Or you could pass the environment variables as arguments using the terminal. For example, on Linux or macOS:
|
|
63
|
+
|
|
64
|
+
```bash [Terminal]
|
|
65
|
+
DATABASE_HOST=mydatabaseconnectionstring node .output/server/index.mjs
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Note that for a purely static site, it is not possible to set runtime configuration config after your project is prerendered.
|
|
69
|
+
|
|
70
|
+
:read-more{to="/docs/guide/going-further/runtime-config"}
|
|
71
|
+
|
|
72
|
+
::note
|
|
73
|
+
If you want to use environment variables set at build time but do not care about updating these down the line (or only need to update them reactively _within_ your app) then `appConfig` may be a better choice. You can define `appConfig` both within your `nuxt.config` (using environment variables) and also within an `~/app.config.ts` file in your project.
|
|
74
|
+
:read-more{to="/docs/guide/directory-structure/app-config"}
|
|
75
|
+
::
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: ".gitignore"
|
|
3
|
+
description: "A .gitignore file specifies intentionally untracked files that git should ignore."
|
|
4
|
+
head.title: ".gitignore"
|
|
5
|
+
navigation.icon: i-lucide-file
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
A `.gitignore` file specifies intentionally untracked files that git should ignore.
|
|
9
|
+
|
|
10
|
+
:read-more{icon="i-simple-icons-git" title="the git documentation" to="https://git-scm.com/docs/gitignore" target="_blank"}
|
|
11
|
+
|
|
12
|
+
We recommend having a `.gitignore` file that has **at least** the following entries present:
|
|
13
|
+
|
|
14
|
+
```bash [.gitignore]
|
|
15
|
+
# Nuxt dev/build outputs
|
|
16
|
+
.output
|
|
17
|
+
.data
|
|
18
|
+
.nuxt
|
|
19
|
+
.nitro
|
|
20
|
+
.cache
|
|
21
|
+
dist
|
|
22
|
+
|
|
23
|
+
# Node dependencies
|
|
24
|
+
node_modules
|
|
25
|
+
|
|
26
|
+
# Logs
|
|
27
|
+
logs
|
|
28
|
+
*.log
|
|
29
|
+
|
|
30
|
+
# Misc
|
|
31
|
+
.DS_Store
|
|
32
|
+
|
|
33
|
+
# Local env files
|
|
34
|
+
.env
|
|
35
|
+
.env.*
|
|
36
|
+
!.env.example
|
|
37
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: .nuxtignore
|
|
3
|
+
head.title: '.nuxtignore'
|
|
4
|
+
description: The .nuxtignore file lets Nuxt ignore files in your project’s root directory during the build phase.
|
|
5
|
+
navigation.icon: i-lucide-file
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
The `.nuxtignore` file tells Nuxt to ignore files in your project’s root directory ([`rootDir`](/docs/api/nuxt-config#rootdir)) during the build phase.
|
|
9
|
+
|
|
10
|
+
It is subject to the same specification as [`.gitignore`](/docs/guide/directory-structure/gitignore) and `.eslintignore` files, in which each line is a glob pattern indicating which files should be ignored.
|
|
11
|
+
|
|
12
|
+
::tip
|
|
13
|
+
You can also configure [`ignoreOptions`](/docs/api/nuxt-config#ignoreoptions), [`ignorePrefix`](/docs/api/nuxt-config#ignoreprefix) and [`ignore`](/docs/api/nuxt-config#ignore) in your `nuxt.config` file.
|
|
14
|
+
::
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```bash [.nuxtignore]
|
|
19
|
+
# ignore layout foo.vue
|
|
20
|
+
layouts/foo.vue
|
|
21
|
+
# ignore layout files whose name ends with -ignore.vue
|
|
22
|
+
layouts/*-ignore.vue
|
|
23
|
+
|
|
24
|
+
# ignore page bar.vue
|
|
25
|
+
pages/bar.vue
|
|
26
|
+
# ignore page inside ignore folder
|
|
27
|
+
pages/ignore/*.vue
|
|
28
|
+
|
|
29
|
+
# ignore route middleware files under foo folder except foo/bar.js
|
|
30
|
+
middleware/foo/*.js
|
|
31
|
+
!middleware/foo/bar.js
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
::read-more{icon="i-simple-icons-git" title="the git documentation" to="https://git-scm.com/docs/gitignore" target="_blank"}
|
|
35
|
+
More details about the spec are in the **gitignore documentation**.
|
|
36
|
+
::
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: ".nuxtrc"
|
|
3
|
+
description: "The .nuxtrc file allows you to define nuxt configurations in a flat syntax."
|
|
4
|
+
head.title: ".nuxtrc"
|
|
5
|
+
navigation.icon: i-lucide-file
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
The `.nuxtrc` file can be used to configure Nuxt with a flat syntax. It is based on [`unjs/rc9`](https://github.com/unjs/rc9).
|
|
9
|
+
|
|
10
|
+
::tip
|
|
11
|
+
For more advanced configurations, use [`nuxt.config`](/docs/guide/directory-structure/nuxt-config).
|
|
12
|
+
::
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```bash [.nuxtrc]
|
|
17
|
+
# Disable SSR
|
|
18
|
+
ssr=false
|
|
19
|
+
|
|
20
|
+
# Configuration for `@nuxt/devtools`
|
|
21
|
+
devtools.enabled=true
|
|
22
|
+
|
|
23
|
+
# Add Nuxt modules
|
|
24
|
+
modules[]=@nuxt/image
|
|
25
|
+
modules[]=nuxt-security
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
If present, the properties in the `nuxt.config` file will overwrite the properties in `.nuxtrc` file.
|
|
29
|
+
|
|
30
|
+
::read-more{to="/docs/api/configuration/nuxt-config"}
|
|
31
|
+
Discover all the available options in the **Nuxt configuration** documentation.
|
|
32
|
+
::
|
|
33
|
+
|
|
34
|
+
## Global `.nuxtrc` File
|
|
35
|
+
|
|
36
|
+
You can also create a global `.nuxtrc` file in your home directory to apply configurations globally.
|
|
37
|
+
|
|
38
|
+
- On macOS/Linux, this file is located at:
|
|
39
|
+
|
|
40
|
+
```md
|
|
41
|
+
~/.nuxtrc
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- On Windows, it is located at:
|
|
45
|
+
|
|
46
|
+
```md
|
|
47
|
+
C:\Users\{username}\.nuxtrc
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
This global `.nuxtrc` file allows you to define default settings that apply to all Nuxt projects on your system. However, project-level `.nuxtrc` files will override these global settings, and `nuxt.config` will take precedence over both.
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: app.config.ts
|
|
3
|
+
head.title: 'app.config.ts'
|
|
4
|
+
description: Expose reactive configuration within your application with the App Config file.
|
|
5
|
+
navigation.icon: i-lucide-file
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
Nuxt provides an `app.config` config file to expose reactive configuration within your application with the ability to update it at runtime within lifecycle or using a nuxt plugin and editing it with HMR (hot-module-replacement).
|
|
9
|
+
|
|
10
|
+
You can easily provide runtime app configuration using `app.config.ts` file. It can have either of `.ts`, `.js`, or `.mjs` extensions.
|
|
11
|
+
|
|
12
|
+
```ts twoslash [app.config.ts]
|
|
13
|
+
export default defineAppConfig({
|
|
14
|
+
foo: 'bar'
|
|
15
|
+
})
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
::caution
|
|
19
|
+
Do not put any secret values inside `app.config` file. It is exposed to the user client bundle.
|
|
20
|
+
::
|
|
21
|
+
|
|
22
|
+
::note
|
|
23
|
+
When configuring a custom [`srcDir`](/docs/api/nuxt-config#srcdir), make sure to place the `app.config` file at the root of the new `srcDir` path.
|
|
24
|
+
::
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
To expose config and environment variables to the rest of your app, you will need to define configuration in `app.config` file.
|
|
29
|
+
|
|
30
|
+
```ts twoslash [app.config.ts]
|
|
31
|
+
export default defineAppConfig({
|
|
32
|
+
theme: {
|
|
33
|
+
primaryColor: '#ababab'
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
We can now universally access `theme` both when server-rendering the page and in the browser using [`useAppConfig`](/docs/api/composables/use-app-config) composable.
|
|
39
|
+
|
|
40
|
+
```vue [pages/index.vue]
|
|
41
|
+
<script setup lang="ts">
|
|
42
|
+
const appConfig = useAppConfig()
|
|
43
|
+
|
|
44
|
+
console.log(appConfig.theme)
|
|
45
|
+
</script>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The [`updateAppConfig`](/docs/api/utils/update-app-config) utility can be used to update the `app.config` at runtime.
|
|
49
|
+
|
|
50
|
+
```vue [pages/index.vue]
|
|
51
|
+
<script setup>
|
|
52
|
+
const appConfig = useAppConfig() // { foo: 'bar' }
|
|
53
|
+
|
|
54
|
+
const newAppConfig = { foo: 'baz' }
|
|
55
|
+
|
|
56
|
+
updateAppConfig(newAppConfig)
|
|
57
|
+
|
|
58
|
+
console.log(appConfig) // { foo: 'baz' }
|
|
59
|
+
</script>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
::read-more{to="/docs/api/utils/update-app-config"}
|
|
63
|
+
Read more about the `updateAppConfig` utility.
|
|
64
|
+
::
|
|
65
|
+
|
|
66
|
+
## Typing App Config
|
|
67
|
+
|
|
68
|
+
Nuxt tries to automatically generate a TypeScript interface from provided app config so you won't have to type it yourself.
|
|
69
|
+
|
|
70
|
+
However, there are some cases where you might want to type it yourself. There are two possible things you might want to type.
|
|
71
|
+
|
|
72
|
+
### App Config Input
|
|
73
|
+
|
|
74
|
+
`AppConfigInput` might be used by module authors who are declaring what valid _input_ options are when setting app config. This will not affect the type of `useAppConfig()`.
|
|
75
|
+
|
|
76
|
+
```ts [index.d.ts]
|
|
77
|
+
declare module 'nuxt/schema' {
|
|
78
|
+
interface AppConfigInput {
|
|
79
|
+
/** Theme configuration */
|
|
80
|
+
theme?: {
|
|
81
|
+
/** Primary app color */
|
|
82
|
+
primaryColor?: string
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// It is always important to ensure you import/export something when augmenting a type
|
|
88
|
+
export {}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### App Config Output
|
|
92
|
+
|
|
93
|
+
If you want to type the result of calling [`useAppConfig()`](/docs/api/composables/use-app-config), then you will want to extend `AppConfig`.
|
|
94
|
+
|
|
95
|
+
::warning
|
|
96
|
+
Be careful when typing `AppConfig` as you will overwrite the types Nuxt infers from your actually defined app config.
|
|
97
|
+
::
|
|
98
|
+
|
|
99
|
+
```ts [index.d.ts]
|
|
100
|
+
declare module 'nuxt/schema' {
|
|
101
|
+
interface AppConfig {
|
|
102
|
+
// This will entirely replace the existing inferred `theme` property
|
|
103
|
+
theme: {
|
|
104
|
+
// You might want to type this value to add more specific types than Nuxt can infer,
|
|
105
|
+
// such as string literal types
|
|
106
|
+
primaryColor?: 'red' | 'blue'
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// It is always important to ensure you import/export something when augmenting a type
|
|
112
|
+
export {}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Merging Strategy
|
|
116
|
+
|
|
117
|
+
Nuxt uses a custom merging strategy for the `AppConfig` within [the layers](/docs/getting-started/layers) of your application.
|
|
118
|
+
|
|
119
|
+
This strategy is implemented using a [Function Merger](https://github.com/unjs/defu#function-merger), which allows defining a custom merging strategy for every key in `app.config` that has an array as value.
|
|
120
|
+
|
|
121
|
+
::note
|
|
122
|
+
The function merger can only be used in the extended layers and not the main `app.config` in project.
|
|
123
|
+
::
|
|
124
|
+
|
|
125
|
+
Here's an example of how you can use:
|
|
126
|
+
|
|
127
|
+
::code-group
|
|
128
|
+
|
|
129
|
+
```ts twoslash [layer/app.config.ts]
|
|
130
|
+
export default defineAppConfig({
|
|
131
|
+
// Default array value
|
|
132
|
+
array: ['hello'],
|
|
133
|
+
})
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```ts twoslash [app.config.ts]
|
|
137
|
+
export default defineAppConfig({
|
|
138
|
+
// Overwrite default array value by using a merger function
|
|
139
|
+
array: () => ['bonjour'],
|
|
140
|
+
})
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
::
|
|
144
|
+
|
|
145
|
+
## Known Limitations
|
|
146
|
+
|
|
147
|
+
As of Nuxt v3.3, the `app.config.ts` file is shared with Nitro, which results in the following limitations:
|
|
148
|
+
|
|
149
|
+
1. You cannot import Vue components directly in `app.config.ts`.
|
|
150
|
+
2. Some auto-imports are not available in the Nitro context.
|
|
151
|
+
|
|
152
|
+
These limitations occur because Nitro processes the app config without full Vue component support.
|
|
153
|
+
|
|
154
|
+
While it's possible to use Vite plugins in the Nitro config as a workaround, this approach is not recommended:
|
|
155
|
+
|
|
156
|
+
```ts [nuxt.config.ts]
|
|
157
|
+
export default defineNuxtConfig({
|
|
158
|
+
nitro: {
|
|
159
|
+
vite: {
|
|
160
|
+
plugins: [vue()]
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
::warning
|
|
167
|
+
Using this workaround may lead to unexpected behavior and bugs. The Vue plugin is one of many that are not available in the Nitro context.
|
|
168
|
+
::
|
|
169
|
+
|
|
170
|
+
Related issues:
|
|
171
|
+
- [Issue #19858](https://github.com/nuxt/nuxt/issues/19858)
|
|
172
|
+
- [Issue #19854](https://github.com/nuxt/nuxt/issues/19854)
|
|
173
|
+
|
|
174
|
+
::note
|
|
175
|
+
Nitro v3 will resolve these limitations by removing support for the app config.
|
|
176
|
+
You can track the progress in [this pull request](https://github.com/nitrojs/nitro/pull/2521).
|
|
177
|
+
::
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "app.vue"
|
|
3
|
+
description: "The app.vue file is the main component of your Nuxt application."
|
|
4
|
+
head.title: "app.vue"
|
|
5
|
+
navigation.icon: i-lucide-file
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
::tip
|
|
9
|
+
If you have a `pages/` directory, the `app.vue` file is optional. Nuxt will automatically include a default `app.vue`, but you can still add your own to customize the structure and content as needed.
|
|
10
|
+
::
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
### Minimal Usage
|
|
15
|
+
|
|
16
|
+
With Nuxt, the [`pages/`](/docs/guide/directory-structure/pages) directory is optional. If it is not present, Nuxt will not include the [vue-router](https://router.vuejs.org) dependency. This is useful when building a landing page or an application that does not require routing.
|
|
17
|
+
|
|
18
|
+
```vue [app.vue]
|
|
19
|
+
<template>
|
|
20
|
+
<h1>Hello World!</h1>
|
|
21
|
+
</template>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
:link-example{to="/docs/examples/hello-world"}
|
|
25
|
+
|
|
26
|
+
### Usage with Pages
|
|
27
|
+
|
|
28
|
+
When you have a [`pages/`](/docs/guide/directory-structure/pages) directory, you need to use the [`<NuxtPage>`](/docs/api/components/nuxt-page) component to display the current page:
|
|
29
|
+
|
|
30
|
+
```vue [app.vue]
|
|
31
|
+
<template>
|
|
32
|
+
<NuxtPage />
|
|
33
|
+
</template>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
You can also define the common structure of your application directly in `app.vue`. This is useful when you want to include global elements such as a header or footer:
|
|
37
|
+
|
|
38
|
+
```vue [app.vue]
|
|
39
|
+
<template>
|
|
40
|
+
<header>
|
|
41
|
+
Header content
|
|
42
|
+
</header>
|
|
43
|
+
<NuxtPage />
|
|
44
|
+
<footer>
|
|
45
|
+
Footer content
|
|
46
|
+
</footer>
|
|
47
|
+
</template>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
::note
|
|
51
|
+
Remember that `app.vue` acts as the main component of your Nuxt application. Anything you add to it (JS and CSS) will be global and included in every page.
|
|
52
|
+
::
|
|
53
|
+
|
|
54
|
+
::read-more{to="/docs/guide/directory-structure/pages"}
|
|
55
|
+
Learn more about how to structure your pages using the `pages/` directory.
|
|
56
|
+
::
|
|
57
|
+
|
|
58
|
+
### Usage with Layouts
|
|
59
|
+
|
|
60
|
+
When your application requires different layouts for different pages, you can use the `layouts/` directory with the [`<NuxtLayout>`](/docs/api/components/nuxt-layout) component. This allows you to define multiple layouts and apply them per page.
|
|
61
|
+
|
|
62
|
+
```vue [app.vue]
|
|
63
|
+
<template>
|
|
64
|
+
<NuxtLayout>
|
|
65
|
+
<NuxtPage />
|
|
66
|
+
</NuxtLayout>
|
|
67
|
+
</template>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
::read-more{to="/docs/guide/directory-structure/layouts"}
|
|
71
|
+
Learn more about how to structure your layouts using the `layouts/` directory.
|
|
72
|
+
::
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "error.vue"
|
|
3
|
+
description: "The error.vue file is the error page in your Nuxt application."
|
|
4
|
+
head.title: "error.vue"
|
|
5
|
+
navigation.icon: i-lucide-file
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
During the lifespan of your application, some errors may appear unexpectedly at runtime. In such case, we can use the `error.vue` file to override the default error files and display the error nicely.
|
|
9
|
+
|
|
10
|
+
```vue [error.vue]
|
|
11
|
+
<script setup lang="ts">
|
|
12
|
+
import type { NuxtError } from '#app'
|
|
13
|
+
|
|
14
|
+
const props = defineProps({
|
|
15
|
+
error: Object as () => NuxtError
|
|
16
|
+
})
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<template>
|
|
20
|
+
<div>
|
|
21
|
+
<h1>{{ error.statusCode }}</h1>
|
|
22
|
+
<NuxtLink to="/">Go back home</NuxtLink>
|
|
23
|
+
</div>
|
|
24
|
+
</template>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
::note
|
|
28
|
+
Although it is called an 'error page' it's not a route and shouldn't be placed in your `~/pages` directory. For the same reason, you shouldn't use `definePageMeta` within this page. That being said, you can still use layouts in the error file, by utilizing the [`NuxtLayout`](/docs/api/components/nuxt-layout) component and specifying the name of the layout.
|
|
29
|
+
::
|
|
30
|
+
|
|
31
|
+
The error page has a single prop - `error` which contains an error for you to handle.
|
|
32
|
+
|
|
33
|
+
The `error` object provides the following fields:
|
|
34
|
+
```ts
|
|
35
|
+
{
|
|
36
|
+
statusCode: number
|
|
37
|
+
fatal: boolean
|
|
38
|
+
unhandled: boolean
|
|
39
|
+
statusMessage?: string
|
|
40
|
+
data?: unknown
|
|
41
|
+
cause?: unknown
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
If you have an error with custom fields they will be lost; you should assign them to `data` instead:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
throw createError({
|
|
49
|
+
statusCode: 404,
|
|
50
|
+
statusMessage: 'Page Not Found',
|
|
51
|
+
data: {
|
|
52
|
+
myCustomField: true
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "nuxt.config.ts"
|
|
3
|
+
description: "Nuxt can be easily configured with a single nuxt.config file."
|
|
4
|
+
head.title: "nuxt.config.ts"
|
|
5
|
+
navigation.icon: i-lucide-file
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
The `nuxt.config` file extension can either be `.js`, `.ts` or `.mjs`.
|
|
9
|
+
|
|
10
|
+
```ts twoslash [nuxt.config.ts]
|
|
11
|
+
export default defineNuxtConfig({
|
|
12
|
+
// My Nuxt config
|
|
13
|
+
})
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
::tip
|
|
17
|
+
`defineNuxtConfig` helper is globally available without import.
|
|
18
|
+
::
|
|
19
|
+
|
|
20
|
+
You can explicitly import `defineNuxtConfig` from `nuxt/config` if you prefer:
|
|
21
|
+
|
|
22
|
+
```ts twoslash [nuxt.config.ts]
|
|
23
|
+
import { defineNuxtConfig } from 'nuxt/config'
|
|
24
|
+
|
|
25
|
+
export default defineNuxtConfig({
|
|
26
|
+
// My Nuxt config
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
::read-more{to="/docs/api/configuration/nuxt-config"}
|
|
31
|
+
Discover all the available options in the **Nuxt configuration** documentation.
|
|
32
|
+
::
|
|
33
|
+
|
|
34
|
+
To ensure your configuration is up to date, Nuxt will make a full restart when detecting changes in the main configuration file, the [`.env`](/docs/guide/directory-structure/env), [`.nuxtignore`](/docs/guide/directory-structure/nuxtignore) and [`.nuxtrc`](/docs/guide/directory-structure/nuxtrc) dotfiles.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: package.json
|
|
3
|
+
head.title: package.json
|
|
4
|
+
description: The package.json file contains all the dependencies and scripts for your application.
|
|
5
|
+
navigation.icon: i-lucide-file
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
The minimal `package.json` of your Nuxt application should looks like:
|
|
9
|
+
|
|
10
|
+
```json [package.json]
|
|
11
|
+
{
|
|
12
|
+
"name": "nuxt-app",
|
|
13
|
+
"private": true,
|
|
14
|
+
"type": "module",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "nuxt build",
|
|
17
|
+
"dev": "nuxt dev",
|
|
18
|
+
"generate": "nuxt generate",
|
|
19
|
+
"preview": "nuxt preview",
|
|
20
|
+
"postinstall": "nuxt prepare"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"nuxt": "latest",
|
|
24
|
+
"vue": "latest",
|
|
25
|
+
"vue-router": "latest"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
::read-more{icon="i-simple-icons-npm" to="https://docs.npmjs.com/cli/configuring-npm/package-json" target="_blank"}
|
|
31
|
+
Read more about the `package.json` file.
|
|
32
|
+
::
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "tsconfig.json"
|
|
3
|
+
description: "Nuxt generates a .nuxt/tsconfig.json file with sensible defaults and your aliases."
|
|
4
|
+
head.title: "tsconfig.json"
|
|
5
|
+
navigation.icon: i-lucide-file
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
Nuxt [automatically generates](/docs/guide/concepts/typescript) a `.nuxt/tsconfig.json` file with the resolved aliases you are using in your Nuxt project, as well as with other sensible defaults.
|
|
9
|
+
|
|
10
|
+
You can benefit from this by creating a `tsconfig.json` in the root of your project with the following content:
|
|
11
|
+
|
|
12
|
+
```json [tsconfig.json]
|
|
13
|
+
{
|
|
14
|
+
"extends": "./.nuxt/tsconfig.json"
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
::note
|
|
19
|
+
As you need to, you can customize the contents of this file. However, it is recommended that you don't overwrite `target`, `module` and `moduleResolution`.
|
|
20
|
+
::
|
|
21
|
+
|
|
22
|
+
::note
|
|
23
|
+
If you need to customize your `paths`, this will override the auto-generated path aliases. Instead, we recommend that you add any path aliases you need to the [`alias`](/docs/api/nuxt-config#alias) property within your `nuxt.config`, where they will get picked up and added to the auto-generated `tsconfig`.
|
|
24
|
+
::
|