@nuxt/docs 0.0.0 → 3.17.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/.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,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Features"
|
|
3
|
+
description: "Enable or disable optional Nuxt features to unlock new possibilities."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Some features of Nuxt are available on an opt-in basis, or can be disabled based on your needs.
|
|
7
|
+
|
|
8
|
+
## `features`
|
|
9
|
+
|
|
10
|
+
### inlineStyles
|
|
11
|
+
|
|
12
|
+
Inlines styles when rendering HTML. This is currently available only when using Vite.
|
|
13
|
+
|
|
14
|
+
You can also pass a function that receives the path of a Vue component and returns a boolean indicating whether to inline the styles for that component.
|
|
15
|
+
|
|
16
|
+
```ts [nuxt.config.ts]
|
|
17
|
+
export default defineNuxtConfig({
|
|
18
|
+
features: {
|
|
19
|
+
inlineStyles: false // or a function to determine inlining
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### noScripts
|
|
25
|
+
|
|
26
|
+
Disables rendering of Nuxt scripts and JS resource hints. Can also be configured granularly within `routeRules`.
|
|
27
|
+
|
|
28
|
+
```ts [nuxt.config.ts]
|
|
29
|
+
export default defineNuxtConfig({
|
|
30
|
+
features: {
|
|
31
|
+
noScripts: true
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## `future`
|
|
37
|
+
|
|
38
|
+
There is also a `future` namespace for early opting-in to new features that will become default in a future (possibly major) version of the framework.
|
|
39
|
+
|
|
40
|
+
### compatibilityVersion
|
|
41
|
+
|
|
42
|
+
::important
|
|
43
|
+
This configuration option is available in Nuxt v3.12+. Please note, that for now, you need to define the compatibility version in each layer that opts into Nuxt 4 behavior. This will not be required after Nuxt 4 is released.
|
|
44
|
+
::
|
|
45
|
+
|
|
46
|
+
This enables early access to Nuxt features or flags.
|
|
47
|
+
|
|
48
|
+
Setting `compatibilityVersion` to `4` changes defaults throughout your
|
|
49
|
+
Nuxt configuration to opt-in to Nuxt v4 behaviour, but you can granularly re-enable Nuxt v3 behaviour
|
|
50
|
+
when testing (see example). Please file issues if so, so that we can
|
|
51
|
+
address in Nuxt or in the ecosystem.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
export default defineNuxtConfig({
|
|
55
|
+
future: {
|
|
56
|
+
compatibilityVersion: 4,
|
|
57
|
+
},
|
|
58
|
+
// To re-enable _all_ Nuxt v3 behaviour, set the following options:
|
|
59
|
+
srcDir: '.',
|
|
60
|
+
dir: {
|
|
61
|
+
app: 'app'
|
|
62
|
+
},
|
|
63
|
+
experimental: {
|
|
64
|
+
scanPageMeta: 'after-resolve',
|
|
65
|
+
sharedPrerenderData: false,
|
|
66
|
+
compileTemplate: true,
|
|
67
|
+
resetAsyncDataToUndefined: true,
|
|
68
|
+
templateUtils: true,
|
|
69
|
+
relativeWatchPaths: true,
|
|
70
|
+
normalizeComponentNames: false
|
|
71
|
+
defaults: {
|
|
72
|
+
useAsyncData: {
|
|
73
|
+
deep: true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
features: {
|
|
78
|
+
inlineStyles: true
|
|
79
|
+
},
|
|
80
|
+
unhead: {
|
|
81
|
+
renderSSRHeadOptions: {
|
|
82
|
+
omitLineBreaks: false
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### typescriptBundlerResolution
|
|
89
|
+
|
|
90
|
+
This enables 'Bundler' module resolution mode for TypeScript, which is the recommended setting
|
|
91
|
+
for frameworks like Nuxt and [Vite](https://vite.dev/guide/performance.html#reduce-resolve-operations).
|
|
92
|
+
|
|
93
|
+
It improves type support when using modern libraries with `exports`.
|
|
94
|
+
|
|
95
|
+
See [the original TypeScript pull request](https://github.com/microsoft/TypeScript/pull/51669).
|
|
96
|
+
|
|
97
|
+
```ts [nuxt.config.ts]
|
|
98
|
+
export default defineNuxtConfig({
|
|
99
|
+
future: {
|
|
100
|
+
typescriptBundlerResolution: true
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
```
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "How Nuxt Works?"
|
|
3
|
+
description: "Nuxt is a minimal but highly customizable framework to build web applications."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
This guide helps you better understand Nuxt internals to develop new solutions and module integrations on top of Nuxt.
|
|
7
|
+
|
|
8
|
+
## The Nuxt Interface
|
|
9
|
+
|
|
10
|
+
When you start Nuxt in development mode with [`nuxi dev`](/docs/api/commands/dev) or building a production application with [`nuxi build`](/docs/api/commands/build),
|
|
11
|
+
a common context will be created, referred to as `nuxt` internally. It holds normalized options merged with `nuxt.config` file,
|
|
12
|
+
some internal state, and a powerful [hooking system](/docs/api/advanced/hooks) powered by [unjs/hookable](https://github.com/unjs/hookable)
|
|
13
|
+
allowing different components to communicate with each other. You can think of it as **Builder Core**.
|
|
14
|
+
|
|
15
|
+
This context is globally available to be used with [Nuxt Kit](/docs/guide/going-further/kit) composables.
|
|
16
|
+
Therefore only one instance of Nuxt is allowed to run per process.
|
|
17
|
+
|
|
18
|
+
To extend the Nuxt interface and hook into different stages of the build process, we can use [Nuxt Modules](/docs/guide/going-further/modules).
|
|
19
|
+
|
|
20
|
+
For more details, check out [the source code](https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nuxt.ts).
|
|
21
|
+
|
|
22
|
+
## The NuxtApp Interface
|
|
23
|
+
|
|
24
|
+
When rendering a page in the browser or on the server, a shared context will be created, referred to as `nuxtApp`.
|
|
25
|
+
This context keeps vue instance, runtime hooks, and internal states like ssrContext and payload for hydration.
|
|
26
|
+
You can think of it as **Runtime Core**.
|
|
27
|
+
|
|
28
|
+
This context can be accessed using [`useNuxtApp()`](/docs/api/composables/use-nuxt-app) composable within Nuxt plugins and `<script setup>` and vue composables.
|
|
29
|
+
Global usage is possible for the browser but not on the server, to avoid sharing context between users.
|
|
30
|
+
|
|
31
|
+
Since [`useNuxtApp`](/docs/api/composables/use-nuxt-app) throws an exception if context is currently unavailable, if your composable does not always require `nuxtApp`, you can use [`tryUseNuxtApp`](/docs/api/composables/use-nuxt-app#tryusenuxtapp) instead, which will return `null` instead of throwing an exception.
|
|
32
|
+
|
|
33
|
+
To extend the `nuxtApp` interface and hook into different stages or access contexts, we can use [Nuxt Plugins](/docs/guide/directory-structure/plugins).
|
|
34
|
+
|
|
35
|
+
Check [Nuxt App](/docs/api/composables/use-nuxt-app) for more information about this interface.
|
|
36
|
+
|
|
37
|
+
`nuxtApp` has the following properties:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
const nuxtApp = {
|
|
41
|
+
vueApp, // the global Vue application: https://vuejs.org/api/application.html#application-api
|
|
42
|
+
|
|
43
|
+
versions, // an object containing Nuxt and Vue versions
|
|
44
|
+
|
|
45
|
+
// These let you call and add runtime NuxtApp hooks
|
|
46
|
+
// https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/nuxt.ts#L18
|
|
47
|
+
hooks,
|
|
48
|
+
hook,
|
|
49
|
+
callHook,
|
|
50
|
+
|
|
51
|
+
// Only accessible on server-side
|
|
52
|
+
ssrContext: {
|
|
53
|
+
url,
|
|
54
|
+
req,
|
|
55
|
+
res,
|
|
56
|
+
runtimeConfig,
|
|
57
|
+
noSSR,
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
// This will be stringified and passed from server to client
|
|
61
|
+
payload: {
|
|
62
|
+
serverRendered: true,
|
|
63
|
+
data: {},
|
|
64
|
+
state: {}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
provide: (name: string, value: any) => void
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
For more details, check out [the source code](https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/nuxt.ts).
|
|
72
|
+
|
|
73
|
+
## Runtime Context vs. Build Context
|
|
74
|
+
|
|
75
|
+
Nuxt builds and bundles project using Node.js but also has a runtime side.
|
|
76
|
+
|
|
77
|
+
While both areas can be extended, that runtime context is isolated from build-time. Therefore, they are not supposed to share state, code, or context other than runtime configuration!
|
|
78
|
+
|
|
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
|
+
|
|
81
|
+
When building an application for production, `nuxi build` will generate a standalone build in the `.output` directory, independent of `nuxt.config` and [Nuxt modules](/docs/guide/going-further/modules).
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Runtime Config"
|
|
3
|
+
description: "Nuxt provides a runtime config API to expose configuration and secrets within your application."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Exposing
|
|
7
|
+
|
|
8
|
+
To expose config and environment variables to the rest of your app, you will need to define runtime configuration in your [`nuxt.config`](/docs/guide/directory-structure/nuxt-config) file, using the [`runtimeConfig`](/docs/api/nuxt-config#runtimeconfig) option.
|
|
9
|
+
|
|
10
|
+
```ts [nuxt.config.ts]
|
|
11
|
+
export default defineNuxtConfig({
|
|
12
|
+
runtimeConfig: {
|
|
13
|
+
// The private keys which are only available within server-side
|
|
14
|
+
apiSecret: '123',
|
|
15
|
+
// Keys within public, will be also exposed to the client-side
|
|
16
|
+
public: {
|
|
17
|
+
apiBase: '/api'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
When adding `apiBase` to the `runtimeConfig.public`, Nuxt adds it to each page payload. We can universally access `apiBase` in both server and browser.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
const runtimeConfig = useRuntimeConfig()
|
|
27
|
+
|
|
28
|
+
console.log(runtimeConfig.apiSecret)
|
|
29
|
+
console.log(runtimeConfig.public.apiBase)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
::tip
|
|
33
|
+
Public runtime config is accessible in Vue templates with `$config.public`.
|
|
34
|
+
::
|
|
35
|
+
|
|
36
|
+
### Serialization
|
|
37
|
+
|
|
38
|
+
Your runtime config will be serialized before being passed to Nitro. This means that anything that cannot be serialized and then deserialized (such as functions, Sets, Maps, and so on), should not be set in your `nuxt.config`.
|
|
39
|
+
|
|
40
|
+
Instead of passing non-serializable objects or functions into your application from your `nuxt.config`, you can place this code in a Nuxt or Nitro plugin or middleware.
|
|
41
|
+
|
|
42
|
+
### Environment Variables
|
|
43
|
+
|
|
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
|
+
|
|
46
|
+
::note
|
|
47
|
+
Nuxi 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
|
+
:read-more{to="/docs/guide/directory-structure/env"}
|
|
49
|
+
::
|
|
50
|
+
|
|
51
|
+
Runtime config values are **automatically replaced by matching environment variables at runtime**.
|
|
52
|
+
|
|
53
|
+
There are two key requirements:
|
|
54
|
+
|
|
55
|
+
1. Your desired variables must be defined in your `nuxt.config`. This ensures that arbitrary environment variables are not exposed to your application code.
|
|
56
|
+
|
|
57
|
+
1. Only a specially-named environment variable can override a runtime config property. That is, an uppercase environment variable starting with `NUXT_` which uses `_` to separate keys and case changes.
|
|
58
|
+
|
|
59
|
+
::warning
|
|
60
|
+
Setting the default of `runtimeConfig` values to *differently named environment variables* (for example setting `myVar` to `process.env.OTHER_VARIABLE`) will only work during build-time and will break on runtime.
|
|
61
|
+
It is advised to use environment variables that match the structure of your `runtimeConfig` object.
|
|
62
|
+
::
|
|
63
|
+
|
|
64
|
+
::tip{icon="i-lucide-video" to="https://youtu.be/_FYV5WfiWvs" target="_blank"}
|
|
65
|
+
Watch a video from Alexander Lichter showcasing the top mistake developers make using runtimeConfig.
|
|
66
|
+
::
|
|
67
|
+
|
|
68
|
+
#### Example
|
|
69
|
+
|
|
70
|
+
```ini [.env]
|
|
71
|
+
NUXT_API_SECRET=api_secret_token
|
|
72
|
+
NUXT_PUBLIC_API_BASE=https://nuxtjs.org
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```ts [nuxt.config.ts]
|
|
76
|
+
export default defineNuxtConfig({
|
|
77
|
+
runtimeConfig: {
|
|
78
|
+
apiSecret: '', // can be overridden by NUXT_API_SECRET environment variable
|
|
79
|
+
public: {
|
|
80
|
+
apiBase: '', // can be overridden by NUXT_PUBLIC_API_BASE environment variable
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Reading
|
|
87
|
+
|
|
88
|
+
### Vue App
|
|
89
|
+
|
|
90
|
+
Within the Vue part of your Nuxt app, you will need to call [`useRuntimeConfig()`](/docs/api/composables/use-runtime-config) to access the runtime config.
|
|
91
|
+
|
|
92
|
+
::important
|
|
93
|
+
The behavior is different between the client-side and server-side:
|
|
94
|
+
|
|
95
|
+
- On client-side, only keys in `runtimeConfig.public` and `runtimeConfig.app` (which is used by Nuxt internally) are available, and the object is both writable and reactive.
|
|
96
|
+
|
|
97
|
+
- On server-side, the entire runtime config is available, but it is read-only to avoid context sharing.
|
|
98
|
+
::
|
|
99
|
+
|
|
100
|
+
```vue [pages/index.vue]
|
|
101
|
+
<script setup lang="ts">
|
|
102
|
+
const config = useRuntimeConfig()
|
|
103
|
+
|
|
104
|
+
console.log('Runtime config:', config)
|
|
105
|
+
if (import.meta.server) {
|
|
106
|
+
console.log('API secret:', config.apiSecret)
|
|
107
|
+
}
|
|
108
|
+
</script>
|
|
109
|
+
|
|
110
|
+
<template>
|
|
111
|
+
<div>
|
|
112
|
+
<div>Check developer console!</div>
|
|
113
|
+
</div>
|
|
114
|
+
</template>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
::caution
|
|
118
|
+
**Security note:** Be careful not to expose runtime config keys to the client-side by either rendering them or passing them to `useState`.
|
|
119
|
+
::
|
|
120
|
+
|
|
121
|
+
### Plugins
|
|
122
|
+
|
|
123
|
+
If you want to use the runtime config within any (custom) plugin, you can use [`useRuntimeConfig()`](/docs/api/composables/use-runtime-config) inside of your `defineNuxtPlugin` function.
|
|
124
|
+
|
|
125
|
+
```ts [plugins/config.ts]
|
|
126
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
127
|
+
const config = useRuntimeConfig()
|
|
128
|
+
|
|
129
|
+
console.log('API base URL:', config.public.apiBase)
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Server Routes
|
|
134
|
+
|
|
135
|
+
You can access runtime config within the server routes as well using `useRuntimeConfig`.
|
|
136
|
+
|
|
137
|
+
```ts [server/api/test.ts]
|
|
138
|
+
export default defineEventHandler(async (event) => {
|
|
139
|
+
const { apiSecret } = useRuntimeConfig(event)
|
|
140
|
+
const result = await $fetch('https://my.api.com/test', {
|
|
141
|
+
headers: {
|
|
142
|
+
Authorization: `Bearer ${apiSecret}`
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
return result
|
|
146
|
+
})
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
::note
|
|
150
|
+
Giving the `event` as argument to `useRuntimeConfig` is optional, but it is recommended to pass it to get the runtime config overwritten by [environment variables](/docs/guide/going-further/runtime-config#environment-variables) at runtime for server routes.
|
|
151
|
+
::
|
|
152
|
+
|
|
153
|
+
## Typing Runtime Config
|
|
154
|
+
|
|
155
|
+
Nuxt tries to automatically generate a typescript interface from provided runtime config using [unjs/untyped](https://github.com/unjs/untyped).
|
|
156
|
+
|
|
157
|
+
But it is also possible to type your runtime config manually:
|
|
158
|
+
|
|
159
|
+
```ts [index.d.ts]
|
|
160
|
+
declare module 'nuxt/schema' {
|
|
161
|
+
interface RuntimeConfig {
|
|
162
|
+
apiSecret: string
|
|
163
|
+
}
|
|
164
|
+
interface PublicRuntimeConfig {
|
|
165
|
+
apiBase: string
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// It is always important to ensure you import/export something when augmenting a type
|
|
169
|
+
export {}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
::note
|
|
173
|
+
`nuxt/schema` is provided as a convenience for end-users to access the version of the schema used by Nuxt in their project. Module authors should instead augment `@nuxt/schema`.
|
|
174
|
+
::
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Nightly Release Channel"
|
|
3
|
+
description: "The nightly release channel allows using Nuxt built directly from the latest commits to the repository."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Nuxt lands commits, improvements, and bug fixes every day. You can opt in to test them earlier before the next release.
|
|
7
|
+
|
|
8
|
+
After a commit is merged into the `main` branch of [nuxt/nuxt](https://github.com/nuxt/nuxt) and **passes all tests**, we trigger an automated npm release, using GitHub Actions.
|
|
9
|
+
|
|
10
|
+
You can use these 'nightly' releases to beta test new features and changes.
|
|
11
|
+
|
|
12
|
+
The build and publishing method and quality of these 'nightly' releases are the same as stable ones. The only difference is that you should often check the GitHub repository for updates. There is a slight chance of regressions not being caught during the review process and by the automated tests. Therefore, we internally use this channel to double-check everything before each release.
|
|
13
|
+
|
|
14
|
+
::note
|
|
15
|
+
Features that are only available on the nightly release channel are marked with an alert in the documentation.
|
|
16
|
+
::
|
|
17
|
+
|
|
18
|
+
::warning
|
|
19
|
+
The `latest` nightly release channel is currently tracking the Nuxt v4 branch, meaning that it is particularly likely to have breaking changes right now - be careful!
|
|
20
|
+
|
|
21
|
+
You can opt in to the 3.x branch nightly releases with `"nuxt": "npm:nuxt-nightly@3x"`.
|
|
22
|
+
::
|
|
23
|
+
|
|
24
|
+
## Opting In
|
|
25
|
+
|
|
26
|
+
Update `nuxt` dependency inside `package.json`:
|
|
27
|
+
|
|
28
|
+
```diff [package.json]
|
|
29
|
+
{
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
-- "nuxt": "^3.0.0"
|
|
32
|
+
++ "nuxt": "npm:nuxt-nightly@3x"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Remove lockfile (`package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, or `bun.lockb`) and reinstall dependencies.
|
|
38
|
+
|
|
39
|
+
## Opting Out
|
|
40
|
+
|
|
41
|
+
Update `nuxt` dependency inside `package.json`:
|
|
42
|
+
|
|
43
|
+
```diff [package.json]
|
|
44
|
+
{
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
-- "nuxt": "npm:nuxt-nightly@3x"
|
|
47
|
+
++ "nuxt": "^3.0.0"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Remove lockfile (`package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, or `bun.lockb`) and reinstall dependencies.
|
|
53
|
+
|
|
54
|
+
## Using Nightly `nuxi`
|
|
55
|
+
|
|
56
|
+
::note
|
|
57
|
+
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.
|
|
58
|
+
::
|
|
59
|
+
|
|
60
|
+
To try the latest version of [nuxt/cli](https://github.com/nuxt/cli):
|
|
61
|
+
|
|
62
|
+
```bash [Terminal]
|
|
63
|
+
npx nuxi-nightly@latest [command]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
::read-more{to="/docs/api/commands"}
|
|
67
|
+
Read more about the available commands.
|
|
68
|
+
::
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Lifecycle Hooks"
|
|
3
|
+
description: "Nuxt provides a powerful hooking system to expand almost every aspect using hooks."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
::tip
|
|
7
|
+
The hooking system is powered by [unjs/hookable](https://github.com/unjs/hookable).
|
|
8
|
+
::
|
|
9
|
+
|
|
10
|
+
## Nuxt Hooks (Build Time)
|
|
11
|
+
|
|
12
|
+
These hooks are available for [Nuxt Modules](/docs/guide/going-further/modules) and build context.
|
|
13
|
+
|
|
14
|
+
### Within `nuxt.config.ts`
|
|
15
|
+
|
|
16
|
+
```js [nuxt.config.ts]
|
|
17
|
+
export default defineNuxtConfig({
|
|
18
|
+
hooks: {
|
|
19
|
+
close: () => { }
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Within Nuxt Modules
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
import { defineNuxtModule } from '@nuxt/kit'
|
|
28
|
+
|
|
29
|
+
export default defineNuxtModule({
|
|
30
|
+
setup (options, nuxt) {
|
|
31
|
+
nuxt.hook('close', async () => { })
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
::read-more{to="/docs/api/advanced/hooks#nuxt-hooks-build-time"}
|
|
37
|
+
Explore all available Nuxt hooks.
|
|
38
|
+
::
|
|
39
|
+
|
|
40
|
+
## App Hooks (Runtime)
|
|
41
|
+
|
|
42
|
+
App hooks can be mainly used by [Nuxt Plugins](/docs/guide/directory-structure/plugins) to hook into rendering lifecycle but could also be used in Vue composables.
|
|
43
|
+
|
|
44
|
+
```js [plugins/test.ts]
|
|
45
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
46
|
+
nuxtApp.hook('page:start', () => {
|
|
47
|
+
/* your code goes here */
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
::read-more{to="/docs/api/advanced/hooks#app-hooks-runtime"}
|
|
53
|
+
Explore all available App hooks.
|
|
54
|
+
::
|
|
55
|
+
|
|
56
|
+
## Server Hooks (Runtime)
|
|
57
|
+
|
|
58
|
+
These hooks are available for [server plugins](/docs/guide/directory-structure/server#server-plugins) to hook into Nitro's runtime behavior.
|
|
59
|
+
|
|
60
|
+
```js [~/server/plugins/test.ts]
|
|
61
|
+
export default defineNitroPlugin((nitroApp) => {
|
|
62
|
+
nitroApp.hooks.hook('render:html', (html, { event }) => {
|
|
63
|
+
console.log('render:html', html)
|
|
64
|
+
html.bodyAppend.push('<hr>Appended by custom plugin')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
nitroApp.hooks.hook('render:response', (response, { event }) => {
|
|
68
|
+
console.log('render:response', response)
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
::read-more{to="/docs/api/advanced/hooks#nitro-app-hooks-runtime-server-side"}
|
|
74
|
+
Learn more about available Nitro lifecycle hooks.
|
|
75
|
+
::
|
|
76
|
+
|
|
77
|
+
## Additional Hooks
|
|
78
|
+
|
|
79
|
+
You can add additional hooks by augmenting the types provided by Nuxt. This can be useful for modules.
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { HookResult } from "@nuxt/schema";
|
|
83
|
+
|
|
84
|
+
declare module '#app' {
|
|
85
|
+
interface RuntimeNuxtHooks {
|
|
86
|
+
'your-nuxt-runtime-hook': () => HookResult
|
|
87
|
+
}
|
|
88
|
+
interface NuxtHooks {
|
|
89
|
+
'your-nuxt-hook': () => HookResult
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare module 'nitropack' {
|
|
94
|
+
interface NitroRuntimeHooks {
|
|
95
|
+
'your-nitro-hook': () => void;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|