@nuxt/docs 4.1.2 → 4.2.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/1.getting-started/01.introduction.md +6 -6
- package/1.getting-started/02.installation.md +3 -2
- package/1.getting-started/03.configuration.md +36 -36
- package/1.getting-started/04.views.md +9 -9
- package/1.getting-started/05.assets.md +15 -9
- package/1.getting-started/06.styling.md +58 -48
- package/1.getting-started/07.routing.md +17 -17
- package/1.getting-started/08.seo-meta.md +59 -46
- package/1.getting-started/09.transitions.md +49 -44
- package/1.getting-started/10.data-fetching.md +104 -81
- package/1.getting-started/11.state-management.md +26 -19
- package/1.getting-started/12.error-handling.md +22 -20
- package/1.getting-started/13.server.md +8 -8
- package/1.getting-started/14.layers.md +22 -16
- package/1.getting-started/15.prerendering.md +32 -32
- package/1.getting-started/16.deployment.md +10 -10
- package/1.getting-started/17.testing.md +44 -44
- package/1.getting-started/18.upgrade.md +241 -110
- package/2.guide/0.index.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/.navigation.yml +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/0.nuxt.md +3 -3
- package/2.guide/1.directory-structure/0.output.md +18 -0
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/.navigation.yml +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.assets.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.components.md +45 -28
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.composables.md +13 -13
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.layouts.md +19 -15
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.middleware.md +31 -25
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.pages.md +39 -37
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.plugins.md +25 -25
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.utils.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app-config.md +18 -18
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.error.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.content.md +7 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.modules.md +8 -8
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.node_modules.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.public.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.server.md +35 -35
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.shared.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.env.md +8 -8
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.gitignore.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtignore.md +5 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtrc.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.nuxt-config.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.package.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.tsconfig.md +3 -3
- package/2.guide/{1.concepts → 2.concepts}/1.auto-imports.md +22 -22
- package/2.guide/{1.concepts → 2.concepts}/10.nuxt-lifecycle.md +17 -17
- package/2.guide/{1.concepts → 2.concepts}/2.vuejs-development.md +13 -13
- package/2.guide/{1.concepts → 2.concepts}/3.rendering.md +24 -22
- package/2.guide/{1.concepts → 2.concepts}/4.server-engine.md +6 -6
- package/2.guide/{1.concepts → 2.concepts}/5.modules.md +5 -5
- package/2.guide/{1.concepts → 2.concepts}/7.esm.md +22 -16
- package/2.guide/{1.concepts → 2.concepts}/8.typescript.md +12 -12
- package/2.guide/3.going-further/1.events.md +3 -3
- package/2.guide/3.going-further/1.experimental-features.md +334 -85
- package/2.guide/3.going-further/1.features.md +58 -11
- package/2.guide/3.going-further/1.internals.md +25 -25
- package/2.guide/3.going-further/10.runtime-config.md +12 -12
- package/2.guide/3.going-further/11.nightly-release-channel.md +1 -1
- package/2.guide/3.going-further/2.hooks.md +14 -14
- package/2.guide/3.going-further/3.modules.md +126 -108
- package/2.guide/3.going-further/4.kit.md +7 -7
- package/2.guide/3.going-further/6.nuxt-app.md +8 -8
- package/2.guide/3.going-further/7.layers.md +76 -59
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +30 -30
- package/2.guide/4.recipes/2.vite-plugin.md +45 -4
- package/2.guide/4.recipes/3.custom-usefetch.md +13 -13
- package/2.guide/4.recipes/4.sessions-and-authentication.md +35 -21
- package/2.guide/5.best-practices/hydration.md +4 -4
- package/2.guide/5.best-practices/performance.md +17 -17
- package/3.api/1.components/1.client-only.md +6 -3
- package/3.api/1.components/1.nuxt-client-fallback.md +10 -7
- package/3.api/1.components/10.nuxt-picture.md +1 -1
- package/3.api/1.components/11.teleports.md +5 -2
- package/3.api/1.components/12.nuxt-route-announcer.md +9 -9
- package/3.api/1.components/13.nuxt-time.md +49 -18
- package/3.api/1.components/2.nuxt-page.md +6 -6
- package/3.api/1.components/3.nuxt-layout.md +15 -10
- package/3.api/1.components/4.nuxt-link.md +42 -22
- package/3.api/1.components/5.nuxt-loading-indicator.md +3 -3
- package/3.api/1.components/6.nuxt-error-boundary.md +12 -10
- package/3.api/2.composables/on-prehydrate.md +2 -2
- package/3.api/2.composables/use-app-config.md +1 -1
- package/3.api/2.composables/use-async-data.md +26 -22
- package/3.api/2.composables/use-cookie.md +29 -21
- package/3.api/2.composables/use-error.md +2 -2
- package/3.api/2.composables/use-fetch.md +62 -32
- package/3.api/2.composables/use-head-safe.md +7 -7
- package/3.api/2.composables/use-head.md +5 -5
- package/3.api/2.composables/use-hydration.md +6 -6
- package/3.api/2.composables/use-lazy-async-data.md +4 -4
- package/3.api/2.composables/use-lazy-fetch.md +4 -4
- package/3.api/2.composables/use-loading-indicator.md +12 -12
- package/3.api/2.composables/use-nuxt-app.md +22 -22
- package/3.api/2.composables/use-nuxt-data.md +8 -8
- package/3.api/2.composables/use-preview-mode.md +15 -18
- package/3.api/2.composables/use-request-event.md +1 -1
- package/3.api/2.composables/use-request-fetch.md +3 -3
- package/3.api/2.composables/use-request-header.md +1 -1
- package/3.api/2.composables/use-request-headers.md +4 -4
- package/3.api/2.composables/use-request-url.md +1 -1
- package/3.api/2.composables/use-response-header.md +9 -10
- package/3.api/2.composables/use-route-announcer.md +4 -4
- package/3.api/2.composables/use-route.md +1 -1
- package/3.api/2.composables/use-router.md +10 -8
- package/3.api/2.composables/use-runtime-config.md +11 -11
- package/3.api/2.composables/use-runtime-hook.md +2 -2
- package/3.api/2.composables/use-seo-meta.md +4 -4
- package/3.api/2.composables/use-server-seo-meta.md +6 -6
- package/3.api/2.composables/use-state.md +5 -5
- package/3.api/3.utils/$fetch.md +10 -8
- package/3.api/3.utils/abort-navigation.md +3 -3
- package/3.api/3.utils/add-route-middleware.md +5 -5
- package/3.api/3.utils/call-once.md +6 -6
- package/3.api/3.utils/clear-error.md +3 -3
- package/3.api/3.utils/clear-nuxt-data.md +3 -3
- package/3.api/3.utils/clear-nuxt-state.md +3 -3
- package/3.api/3.utils/create-error.md +2 -2
- package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
- package/3.api/3.utils/define-nuxt-component.md +5 -5
- package/3.api/3.utils/define-nuxt-plugin.md +13 -13
- package/3.api/3.utils/define-nuxt-route-middleware.md +5 -5
- package/3.api/3.utils/define-page-meta.md +23 -23
- package/3.api/3.utils/define-route-rules.md +7 -7
- package/3.api/3.utils/navigate-to.md +11 -11
- package/3.api/3.utils/prefetch-components.md +1 -1
- package/3.api/3.utils/preload-components.md +1 -1
- package/3.api/3.utils/preload-route-components.md +2 -2
- package/3.api/3.utils/prerender-routes.md +3 -3
- package/3.api/3.utils/refresh-cookie.md +4 -4
- package/3.api/3.utils/refresh-nuxt-data.md +12 -7
- package/3.api/3.utils/reload-nuxt-app.md +3 -3
- package/3.api/3.utils/set-page-layout.md +1 -1
- package/3.api/3.utils/set-response-status.md +3 -3
- package/3.api/3.utils/show-error.md +5 -5
- package/3.api/3.utils/update-app-config.md +4 -3
- package/3.api/4.commands/add.md +1 -1
- package/3.api/4.commands/analyze.md +2 -1
- package/3.api/4.commands/build.md +2 -1
- package/3.api/4.commands/dev.md +5 -4
- package/3.api/4.commands/generate.md +3 -2
- package/3.api/4.commands/init.md +3 -2
- package/3.api/4.commands/module.md +4 -4
- package/3.api/4.commands/prepare.md +7 -2
- package/3.api/4.commands/preview.md +5 -4
- package/3.api/4.commands/test.md +40 -0
- package/3.api/4.commands/typecheck.md +5 -3
- package/3.api/4.commands/upgrade.md +3 -3
- package/3.api/5.kit/1.modules.md +123 -37
- package/3.api/5.kit/10.runtime-config.md +1 -1
- package/3.api/5.kit/10.templates.md +8 -6
- package/3.api/5.kit/11.nitro.md +66 -62
- package/3.api/5.kit/12.resolving.md +2 -2
- package/3.api/5.kit/14.builder.md +61 -4
- package/3.api/5.kit/15.examples.md +5 -7
- package/3.api/5.kit/16.layers.md +26 -26
- package/3.api/5.kit/3.compatibility.md +14 -14
- package/3.api/5.kit/4.autoimports.md +13 -13
- package/3.api/5.kit/5.components.md +8 -7
- package/3.api/5.kit/6.context.md +3 -3
- package/3.api/5.kit/7.pages.md +7 -7
- package/3.api/5.kit/8.layout.md +2 -2
- package/3.api/5.kit/9.head.md +132 -0
- package/3.api/5.kit/9.plugins.md +5 -4
- package/3.api/6.advanced/1.hooks.md +5 -5
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/3.api/6.nuxt-config.md +365 -859
- package/3.api/index.md +7 -7
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +3 -3
- package/5.community/4.contribution.md +11 -11
- package/5.community/5.framework-contribution.md +4 -4
- package/5.community/6.roadmap.md +2 -2
- package/6.bridge/1.overview.md +13 -13
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +3 -3
- package/6.bridge/3.bridge-composition-api.md +8 -8
- package/6.bridge/4.plugins-and-middleware.md +9 -9
- package/6.bridge/5.nuxt3-compatible-api.md +20 -17
- package/6.bridge/6.meta.md +20 -19
- package/6.bridge/7.runtime-config.md +1 -1
- package/6.bridge/8.nitro.md +3 -3
- package/6.bridge/9.vite.md +4 -4
- package/7.migration/1.overview.md +2 -2
- package/7.migration/10.bundling.md +1 -1
- package/7.migration/11.server.md +3 -3
- package/7.migration/2.configuration.md +23 -21
- package/7.migration/20.module-authors.md +7 -7
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +21 -18
- package/7.migration/5.plugins-and-middleware.md +8 -8
- package/7.migration/6.pages-and-layouts.md +28 -24
- package/7.migration/7.component-options.md +18 -18
- package/7.migration/8.runtime-config.md +7 -7
- package/package.json +1 -1
- package/2.guide/2.directory-structure/0.output.md +0 -18
- /package/2.guide/{1.concepts → 2.concepts}/.navigation.yml +0 -0
- /package/2.guide/{1.concepts → 2.concepts}/9.code-style.md +0 -0
|
@@ -7,29 +7,51 @@ Some features of Nuxt are available on an opt-in basis, or can be disabled based
|
|
|
7
7
|
|
|
8
8
|
## `features`
|
|
9
9
|
|
|
10
|
+
### devLogs
|
|
11
|
+
|
|
12
|
+
Stream server logs to the client as you are developing. These logs can be handled in the `dev:ssr-logs` hook.
|
|
13
|
+
|
|
14
|
+
By default, this is enabled in development (when test mode is not active).
|
|
15
|
+
|
|
16
|
+
If set to `silent`, the logs will not be printed to the browser console.
|
|
17
|
+
|
|
18
|
+
```ts [nuxt.config.ts]
|
|
19
|
+
export default defineNuxtConfig({
|
|
20
|
+
features: {
|
|
21
|
+
devLogs: true,
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
```
|
|
25
|
+
|
|
10
26
|
### inlineStyles
|
|
11
27
|
|
|
12
28
|
Inlines styles when rendering HTML. This is currently available only when using Vite.
|
|
13
29
|
|
|
14
30
|
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
31
|
|
|
32
|
+
It defaults to `(id) => id.includes('.vue')`.
|
|
33
|
+
|
|
16
34
|
```ts [nuxt.config.ts]
|
|
17
35
|
export default defineNuxtConfig({
|
|
18
36
|
features: {
|
|
19
|
-
inlineStyles: false // or a function to determine inlining
|
|
20
|
-
}
|
|
37
|
+
inlineStyles: false, // or a function to determine inlining
|
|
38
|
+
},
|
|
21
39
|
})
|
|
22
40
|
```
|
|
23
41
|
|
|
24
42
|
### noScripts
|
|
25
43
|
|
|
26
|
-
|
|
44
|
+
Turn off rendering of Nuxt scripts and JavaScript resource hints. Can also be configured granularly within `routeRules`.
|
|
45
|
+
|
|
46
|
+
You can also disable scripts more granularly within `routeRules`.
|
|
47
|
+
|
|
48
|
+
If set to 'production' or `true`, JavaScript will be disabled in production mode only. If set to 'all', JavaScript will be disabled in both development and production modes.
|
|
27
49
|
|
|
28
50
|
```ts [nuxt.config.ts]
|
|
29
51
|
export default defineNuxtConfig({
|
|
30
52
|
features: {
|
|
31
|
-
noScripts: true
|
|
32
|
-
}
|
|
53
|
+
noScripts: true, // or 'production' | 'all' | false
|
|
54
|
+
},
|
|
33
55
|
})
|
|
34
56
|
```
|
|
35
57
|
|
|
@@ -39,23 +61,48 @@ There is also a `future` namespace for early opting-in to new features that will
|
|
|
39
61
|
|
|
40
62
|
### compatibilityVersion
|
|
41
63
|
|
|
42
|
-
This
|
|
64
|
+
This enables early access to Nuxt features or flags.
|
|
65
|
+
|
|
66
|
+
Setting `compatibilityVersion` to `5` changes defaults throughout your Nuxt configuration to opt in to Nuxt v5 behaviour, including enabling the [Vite Environment API](/docs/4.x/guide/going-further/experimental-features#viteenvironmentapi).
|
|
43
67
|
|
|
44
|
-
|
|
68
|
+
```ts
|
|
69
|
+
export default defineNuxtConfig({
|
|
70
|
+
future: {
|
|
71
|
+
compatibilityVersion: 5,
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
::read-more{to="/docs/4.x/getting-started/upgrade#testing-nuxt-5"}
|
|
77
|
+
Learn more about testing Nuxt 5.
|
|
78
|
+
::
|
|
79
|
+
|
|
80
|
+
### multiApp
|
|
81
|
+
|
|
82
|
+
This enables early access to the experimental multi-app support. You can follow the [tracker issue #21635](https://github.com/nuxt/nuxt/issues/21635) to see the progress of multi-app support in Nuxt.
|
|
83
|
+
|
|
84
|
+
```ts [nuxt.config.ts]
|
|
85
|
+
export default defineNuxtConfig({
|
|
86
|
+
future: {
|
|
87
|
+
multiApp: true,
|
|
88
|
+
},
|
|
89
|
+
})
|
|
90
|
+
```
|
|
45
91
|
|
|
46
92
|
### typescriptBundlerResolution
|
|
47
93
|
|
|
48
|
-
This enables 'Bundler' module resolution mode for TypeScript, which is the recommended setting
|
|
49
|
-
for frameworks like Nuxt and [Vite](https://vite.dev/guide/performance.html#reduce-resolve-operations).
|
|
94
|
+
This enables 'Bundler' module resolution mode for TypeScript, which is the recommended setting for frameworks like Nuxt and [Vite](https://vite.dev/guide/performance.html#reduce-resolve-operations).
|
|
50
95
|
|
|
51
96
|
It improves type support when using modern libraries with `exports`.
|
|
52
97
|
|
|
53
98
|
See [the original TypeScript pull request](https://github.com/microsoft/TypeScript/pull/51669).
|
|
54
99
|
|
|
100
|
+
You can set it to false to use the legacy 'Node' mode, which is the default for TypeScript.
|
|
101
|
+
|
|
55
102
|
```ts [nuxt.config.ts]
|
|
56
103
|
export default defineNuxtConfig({
|
|
57
104
|
future: {
|
|
58
|
-
typescriptBundlerResolution:
|
|
59
|
-
}
|
|
105
|
+
typescriptBundlerResolution: false,
|
|
106
|
+
},
|
|
60
107
|
})
|
|
61
108
|
```
|
|
@@ -7,15 +7,15 @@ 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 [`nuxt dev`](/docs/api/commands/dev) or building a production application with [`nuxt build`](/docs/api/commands/build),
|
|
10
|
+
When you start Nuxt in development mode with [`nuxt dev`](/docs/4.x/api/commands/dev) or building a production application with [`nuxt build`](/docs/4.x/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
|
-
some internal state, and a powerful [hooking system](/docs/api/advanced/hooks) powered by [unjs/hookable](https://github.com/unjs/hookable)
|
|
12
|
+
some internal state, and a powerful [hooking system](/docs/4.x/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**.
|
|
14
14
|
|
|
15
|
-
This context is globally available to be used with [Nuxt Kit](/docs/guide/going-further/kit) composables.
|
|
15
|
+
This context is globally available to be used with [Nuxt Kit](/docs/4.x/guide/going-further/kit) composables.
|
|
16
16
|
Therefore only one instance of Nuxt is allowed to run per process.
|
|
17
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).
|
|
18
|
+
To extend the Nuxt interface and hook into different stages of the build process, we can use [Nuxt Modules](/docs/4.x/guide/going-further/modules).
|
|
19
19
|
|
|
20
20
|
For more details, check out [the source code](https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nuxt.ts).
|
|
21
21
|
|
|
@@ -25,42 +25,42 @@ When rendering a page in the browser or on the server, a shared context will be
|
|
|
25
25
|
This context keeps vue instance, runtime hooks, and internal states like ssrContext and payload for hydration.
|
|
26
26
|
You can think of it as **Runtime Core**.
|
|
27
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.
|
|
28
|
+
This context can be accessed using [`useNuxtApp()`](/docs/4.x/api/composables/use-nuxt-app) composable within Nuxt plugins and `<script setup>` and vue composables.
|
|
29
29
|
Global usage is possible for the browser but not on the server, to avoid sharing context between users.
|
|
30
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.
|
|
31
|
+
Since [`useNuxtApp`](/docs/4.x/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/4.x/api/composables/use-nuxt-app#tryusenuxtapp) instead, which will return `null` instead of throwing an exception.
|
|
32
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).
|
|
33
|
+
To extend the `nuxtApp` interface and hook into different stages or access contexts, we can use [Nuxt Plugins](/docs/4.x/guide/directory-structure/plugins).
|
|
34
34
|
|
|
35
|
-
Check [Nuxt App](/docs/api/composables/use-nuxt-app) for more information about this interface.
|
|
35
|
+
Check [Nuxt App](/docs/4.x/api/composables/use-nuxt-app) for more information about this interface.
|
|
36
36
|
|
|
37
37
|
`nuxtApp` has the following properties:
|
|
38
38
|
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
vueApp
|
|
39
|
+
```ts
|
|
40
|
+
interface NuxtApp {
|
|
41
|
+
vueApp // the global Vue application: https://vuejs.org/api/application.html#application-api
|
|
42
42
|
|
|
43
|
-
versions
|
|
43
|
+
versions // an object containing Nuxt and Vue versions
|
|
44
44
|
|
|
45
45
|
// These let you call and add runtime NuxtApp hooks
|
|
46
46
|
// https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/nuxt.ts#L18
|
|
47
|
-
hooks
|
|
48
|
-
hook
|
|
49
|
-
callHook
|
|
47
|
+
hooks
|
|
48
|
+
hook
|
|
49
|
+
callHook
|
|
50
50
|
|
|
51
51
|
// Only accessible on server-side
|
|
52
52
|
ssrContext: {
|
|
53
|
-
url
|
|
54
|
-
req
|
|
55
|
-
res
|
|
56
|
-
runtimeConfig
|
|
57
|
-
noSSR
|
|
58
|
-
}
|
|
53
|
+
url
|
|
54
|
+
req
|
|
55
|
+
res
|
|
56
|
+
runtimeConfig
|
|
57
|
+
noSSR
|
|
58
|
+
}
|
|
59
59
|
|
|
60
60
|
// This will be stringified and passed from server to client
|
|
61
61
|
payload: {
|
|
62
|
-
serverRendered: true
|
|
63
|
-
data: {}
|
|
62
|
+
serverRendered: true
|
|
63
|
+
data: {}
|
|
64
64
|
state: {}
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -76,6 +76,6 @@ Nuxt builds and bundles project using Node.js but also has a runtime side.
|
|
|
76
76
|
|
|
77
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
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.
|
|
79
|
+
`nuxt.config` and [Nuxt Modules](/docs/4.x/guide/going-further/modules) can be used to extend the build context, and [Nuxt Plugins](/docs/4.x/guide/directory-structure/plugins) can be used to extend runtime.
|
|
80
80
|
|
|
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).
|
|
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/4.x/guide/going-further/modules).
|
|
@@ -5,7 +5,7 @@ description: "Nuxt provides a runtime config API to expose configuration and sec
|
|
|
5
5
|
|
|
6
6
|
## Exposing
|
|
7
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.
|
|
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/4.x/guide/directory-structure/nuxt-config) file, using the [`runtimeConfig`](/docs/4.x/api/nuxt-config#runtimeconfig) option.
|
|
9
9
|
|
|
10
10
|
```ts [nuxt.config.ts]
|
|
11
11
|
export default defineNuxtConfig({
|
|
@@ -14,9 +14,9 @@ export default defineNuxtConfig({
|
|
|
14
14
|
apiSecret: '123',
|
|
15
15
|
// Keys within public, will be also exposed to the client-side
|
|
16
16
|
public: {
|
|
17
|
-
apiBase: '/api'
|
|
18
|
-
}
|
|
19
|
-
}
|
|
17
|
+
apiBase: '/api',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
20
|
})
|
|
21
21
|
```
|
|
22
22
|
|
|
@@ -45,7 +45,7 @@ The most common way to provide configuration is by using [Environment Variables]
|
|
|
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
|
-
:read-more{to="/docs/guide/directory-structure/env"}
|
|
48
|
+
:read-more{to="/docs/4.x/guide/directory-structure/env"}
|
|
49
49
|
::
|
|
50
50
|
|
|
51
51
|
Runtime config values are **automatically replaced by matching environment variables at runtime**.
|
|
@@ -78,7 +78,7 @@ export default defineNuxtConfig({
|
|
|
78
78
|
apiSecret: '', // can be overridden by NUXT_API_SECRET environment variable
|
|
79
79
|
public: {
|
|
80
80
|
apiBase: '', // can be overridden by NUXT_PUBLIC_API_BASE environment variable
|
|
81
|
-
}
|
|
81
|
+
},
|
|
82
82
|
},
|
|
83
83
|
})
|
|
84
84
|
```
|
|
@@ -87,7 +87,7 @@ export default defineNuxtConfig({
|
|
|
87
87
|
|
|
88
88
|
### Vue App
|
|
89
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.
|
|
90
|
+
Within the Vue part of your Nuxt app, you will need to call [`useRuntimeConfig()`](/docs/4.x/api/composables/use-runtime-config) to access the runtime config.
|
|
91
91
|
|
|
92
92
|
::important
|
|
93
93
|
The behavior is different between the client-side and server-side:
|
|
@@ -120,14 +120,14 @@ if (import.meta.server) {
|
|
|
120
120
|
|
|
121
121
|
### Plugins
|
|
122
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.
|
|
123
|
+
If you want to use the runtime config within any (custom) plugin, you can use [`useRuntimeConfig()`](/docs/4.x/api/composables/use-runtime-config) inside of your `defineNuxtPlugin` function.
|
|
124
124
|
|
|
125
125
|
```ts [app/plugins/config.ts]
|
|
126
126
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
127
127
|
const config = useRuntimeConfig()
|
|
128
128
|
|
|
129
129
|
console.log('API base URL:', config.public.apiBase)
|
|
130
|
-
})
|
|
130
|
+
})
|
|
131
131
|
```
|
|
132
132
|
|
|
133
133
|
### Server Routes
|
|
@@ -139,15 +139,15 @@ export default defineEventHandler(async (event) => {
|
|
|
139
139
|
const { apiSecret } = useRuntimeConfig(event)
|
|
140
140
|
const result = await $fetch('https://my.api.com/test', {
|
|
141
141
|
headers: {
|
|
142
|
-
Authorization: `Bearer ${apiSecret}
|
|
143
|
-
}
|
|
142
|
+
Authorization: `Bearer ${apiSecret}`,
|
|
143
|
+
},
|
|
144
144
|
})
|
|
145
145
|
return result
|
|
146
146
|
})
|
|
147
147
|
```
|
|
148
148
|
|
|
149
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.
|
|
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/4.x/guide/going-further/runtime-config#environment-variables) at runtime for server routes.
|
|
151
151
|
::
|
|
152
152
|
|
|
153
153
|
## Typing Runtime Config
|
|
@@ -9,15 +9,15 @@ The hooking system is powered by [unjs/hookable](https://github.com/unjs/hookabl
|
|
|
9
9
|
|
|
10
10
|
## Nuxt Hooks (Build Time)
|
|
11
11
|
|
|
12
|
-
These hooks are available for [Nuxt Modules](/docs/guide/going-further/modules) and build context.
|
|
12
|
+
These hooks are available for [Nuxt Modules](/docs/4.x/guide/going-further/modules) and build context.
|
|
13
13
|
|
|
14
14
|
### Within `nuxt.config.ts`
|
|
15
15
|
|
|
16
|
-
```
|
|
16
|
+
```ts [nuxt.config.ts]
|
|
17
17
|
export default defineNuxtConfig({
|
|
18
18
|
hooks: {
|
|
19
|
-
close: () => { }
|
|
20
|
-
}
|
|
19
|
+
close: () => { },
|
|
20
|
+
},
|
|
21
21
|
})
|
|
22
22
|
```
|
|
23
23
|
|
|
@@ -29,19 +29,19 @@ import { defineNuxtModule } from '@nuxt/kit'
|
|
|
29
29
|
export default defineNuxtModule({
|
|
30
30
|
setup (options, nuxt) {
|
|
31
31
|
nuxt.hook('close', async () => { })
|
|
32
|
-
}
|
|
32
|
+
},
|
|
33
33
|
})
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
::read-more{to="/docs/api/advanced/hooks#nuxt-hooks-build-time"}
|
|
36
|
+
::read-more{to="/docs/4.x/api/advanced/hooks#nuxt-hooks-build-time"}
|
|
37
37
|
Explore all available Nuxt hooks.
|
|
38
38
|
::
|
|
39
39
|
|
|
40
40
|
## App Hooks (Runtime)
|
|
41
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.
|
|
42
|
+
App hooks can be mainly used by [Nuxt Plugins](/docs/4.x/guide/directory-structure/plugins) to hook into rendering lifecycle but could also be used in Vue composables.
|
|
43
43
|
|
|
44
|
-
```
|
|
44
|
+
```ts [app/plugins/test.ts]
|
|
45
45
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
46
46
|
nuxtApp.hook('page:start', () => {
|
|
47
47
|
/* your code goes here */
|
|
@@ -49,15 +49,15 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
49
49
|
})
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
::read-more{to="/docs/api/advanced/hooks#app-hooks-runtime"}
|
|
52
|
+
::read-more{to="/docs/4.x/api/advanced/hooks#app-hooks-runtime"}
|
|
53
53
|
Explore all available App hooks.
|
|
54
54
|
::
|
|
55
55
|
|
|
56
56
|
## Server Hooks (Runtime)
|
|
57
57
|
|
|
58
|
-
These hooks are available for [server plugins](/docs/guide/directory-structure/server#server-plugins) to hook into Nitro's runtime behavior.
|
|
58
|
+
These hooks are available for [server plugins](/docs/4.x/guide/directory-structure/server#server-plugins) to hook into Nitro's runtime behavior.
|
|
59
59
|
|
|
60
|
-
```
|
|
60
|
+
```ts [~/server/plugins/test.ts]
|
|
61
61
|
export default defineNitroPlugin((nitroApp) => {
|
|
62
62
|
nitroApp.hooks.hook('render:html', (html, { event }) => {
|
|
63
63
|
console.log('render:html', html)
|
|
@@ -70,7 +70,7 @@ export default defineNitroPlugin((nitroApp) => {
|
|
|
70
70
|
})
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
::read-more{to="/docs/api/advanced/hooks#nitro-app-hooks-runtime-server-side"}
|
|
73
|
+
::read-more{to="/docs/4.x/api/advanced/hooks#nitro-app-hooks-runtime-server-side"}
|
|
74
74
|
Learn more about available Nitro lifecycle hooks.
|
|
75
75
|
::
|
|
76
76
|
|
|
@@ -79,7 +79,7 @@ Learn more about available Nitro lifecycle hooks.
|
|
|
79
79
|
You can define your own custom hooks support by extending Nuxt's hook interfaces.
|
|
80
80
|
|
|
81
81
|
```ts
|
|
82
|
-
import { HookResult } from
|
|
82
|
+
import type { HookResult } from '@nuxt/schema'
|
|
83
83
|
|
|
84
84
|
declare module '#app' {
|
|
85
85
|
interface RuntimeNuxtHooks {
|
|
@@ -92,7 +92,7 @@ declare module '#app' {
|
|
|
92
92
|
|
|
93
93
|
declare module 'nitropack/types' {
|
|
94
94
|
interface NitroRuntimeHooks {
|
|
95
|
-
'your-nitro-hook': () => void
|
|
95
|
+
'your-nitro-hook': () => void
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
```
|