@nuxt/docs 4.1.2 → 4.1.3
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 +2 -1
- 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 +53 -71
- 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 +17 -15
- 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 +246 -85
- package/2.guide/3.going-further/1.features.md +44 -9
- 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 +96 -94
- 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 +62 -53
- 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 +4 -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 +44 -17
- 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 +20 -20
- 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 +58 -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 +36 -36
- 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 +62 -62
- package/3.api/5.kit/12.resolving.md +2 -2
- package/3.api/5.kit/14.builder.md +1 -0
- package/3.api/5.kit/15.examples.md +2 -2
- 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 +7 -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.plugins.md +5 -4
- package/3.api/6.advanced/1.hooks.md +3 -3
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/3.api/6.nuxt-config.md +300 -865
- package/3.api/index.md +7 -7
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +11 -11
- package/5.community/5.framework-contribution.md +4 -4
- package/5.community/6.roadmap.md +1 -1
- 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
|
@@ -21,7 +21,7 @@ npx nuxt module add <MODULENAME> [--cwd=<directory>] [--logLevel=<silent|info|ve
|
|
|
21
21
|
<!--module-add-args-->
|
|
22
22
|
Argument | Description
|
|
23
23
|
--- | ---
|
|
24
|
-
`MODULENAME` |
|
|
24
|
+
`MODULENAME` | Specify one or more modules to install by name, separated by spaces
|
|
25
25
|
<!--/module-add-args-->
|
|
26
26
|
|
|
27
27
|
<!--module-add-opts-->
|
|
@@ -31,7 +31,7 @@ Option | Default | Description
|
|
|
31
31
|
`--logLevel=<silent\|info\|verbose>` | | Specify build-time log level
|
|
32
32
|
`--skipInstall` | | Skip npm install
|
|
33
33
|
`--skipConfig` | | Skip nuxt.config.ts update
|
|
34
|
-
`--dev` | | Install
|
|
34
|
+
`--dev` | | Install modules as dev dependencies
|
|
35
35
|
<!--/module-add-opts-->
|
|
36
36
|
|
|
37
37
|
The command lets you install [Nuxt modules](/modules) in your application with no manual work.
|
|
@@ -39,8 +39,8 @@ The command lets you install [Nuxt modules](/modules) in your application with n
|
|
|
39
39
|
When running the command, it will:
|
|
40
40
|
|
|
41
41
|
- install the module as a dependency using your package manager
|
|
42
|
-
- add it to your [package.json](/docs/guide/directory-structure/package) file
|
|
43
|
-
- update your [`nuxt.config`](/docs/guide/directory-structure/nuxt-config) file
|
|
42
|
+
- add it to your [package.json](/docs/4.x/guide/directory-structure/package) file
|
|
43
|
+
- update your [`nuxt.config`](/docs/4.x/guide/directory-structure/nuxt-config) file
|
|
44
44
|
|
|
45
45
|
**Example:**
|
|
46
46
|
|
|
@@ -10,11 +10,11 @@ links:
|
|
|
10
10
|
|
|
11
11
|
<!--prepare-cmd-->
|
|
12
12
|
```bash [Terminal]
|
|
13
|
-
npx nuxt prepare [ROOTDIR] [--dotenv] [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--envName]
|
|
13
|
+
npx nuxt prepare [ROOTDIR] [--dotenv] [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--envName] [-e, --extends=<layer-name>]
|
|
14
14
|
```
|
|
15
15
|
<!--/prepare-cmd-->
|
|
16
16
|
|
|
17
|
-
The `prepare` command creates a [`.nuxt`](/docs/guide/directory-structure/nuxt) directory in your application and generates types. This can be useful in a CI environment or as a `postinstall` command in your [`package.json`](/docs/guide/directory-structure/package).
|
|
17
|
+
The `prepare` command creates a [`.nuxt`](/docs/4.x/guide/directory-structure/nuxt) directory in your application and generates types. This can be useful in a CI environment or as a `postinstall` command in your [`package.json`](/docs/4.x/guide/directory-structure/package).
|
|
18
18
|
|
|
19
19
|
## Arguments
|
|
20
20
|
|
|
@@ -33,4 +33,9 @@ Option | Default | Description
|
|
|
33
33
|
`--cwd=<directory>` | | Specify the working directory, this takes precedence over ROOTDIR (default: `.`)
|
|
34
34
|
`--logLevel=<silent\|info\|verbose>` | | Specify build-time log level
|
|
35
35
|
`--envName` | | The environment to use when resolving configuration overrides (default is `production` when building, and `development` when running the dev server)
|
|
36
|
+
`-e, --extends=<layer-name>` | | Extend from a Nuxt layer
|
|
36
37
|
<!--/prepare-opts-->
|
|
38
|
+
|
|
39
|
+
::note
|
|
40
|
+
This command sets `process.env.NODE_ENV` to `production`.
|
|
41
|
+
::
|
|
@@ -10,11 +10,11 @@ links:
|
|
|
10
10
|
|
|
11
11
|
<!--preview-cmd-->
|
|
12
12
|
```bash [Terminal]
|
|
13
|
-
npx nuxt preview [ROOTDIR] [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--envName] [--
|
|
13
|
+
npx nuxt preview [ROOTDIR] [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--envName] [-e, --extends=<layer-name>] [-p, --port] [--dotenv]
|
|
14
14
|
```
|
|
15
15
|
<!--/preview-cmd-->
|
|
16
16
|
|
|
17
|
-
The `preview` command starts a server to preview your Nuxt application after running the `build` command. The `start` command is an alias for `preview`. When running your application in production refer to the [Deployment section](/docs/getting-started/deployment).
|
|
17
|
+
The `preview` command starts a server to preview your Nuxt application after running the `build` command. The `start` command is an alias for `preview`. When running your application in production refer to the [Deployment section](/docs/4.x/getting-started/deployment).
|
|
18
18
|
|
|
19
19
|
## Arguments
|
|
20
20
|
|
|
@@ -32,12 +32,13 @@ Option | Default | Description
|
|
|
32
32
|
`--cwd=<directory>` | | Specify the working directory, this takes precedence over ROOTDIR (default: `.`)
|
|
33
33
|
`--logLevel=<silent\|info\|verbose>` | | Specify build-time log level
|
|
34
34
|
`--envName` | | The environment to use when resolving configuration overrides (default is `production` when building, and `development` when running the dev server)
|
|
35
|
+
`-e, --extends=<layer-name>` | | Extend from a Nuxt layer
|
|
36
|
+
`-p, --port` | | Port to listen on (use `PORT` environment variable to override)
|
|
35
37
|
`--dotenv` | | Path to `.env` file to load, relative to the root directory
|
|
36
|
-
`-p, --port` | | Port to listen on (default: `NUXT_PORT \|\| NITRO_PORT \|\| PORT`)
|
|
37
38
|
<!--/preview-opts-->
|
|
38
39
|
|
|
39
40
|
This command sets `process.env.NODE_ENV` to `production`. To override, define `NODE_ENV` in a `.env` file or as command-line argument.
|
|
40
41
|
|
|
41
42
|
::note
|
|
42
|
-
For convenience, in preview mode, your [`.env`](/docs/guide/directory-structure/env) file will be loaded into `process.env`. (However, in production you will need to ensure your environment variables are set yourself. For example, with Node.js 20+ you could do this by running `node --env-file .env .output/server/index.mjs` to start your server.)
|
|
43
|
+
For convenience, in preview mode, your [`.env`](/docs/4.x/guide/directory-structure/env) file will be loaded into `process.env`. (However, in production you will need to ensure your environment variables are set yourself. For example, with Node.js 20+ you could do this by running `node --env-file .env .output/server/index.mjs` to start your server.)
|
|
43
44
|
::
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "nuxt test"
|
|
3
|
+
description: The test command runs tests using @nuxt/test-utils.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/cli/blob/main/packages/nuxi/src/commands/test.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
<!--test-cmd-->
|
|
12
|
+
```bash [Terminal]
|
|
13
|
+
npx nuxt test [ROOTDIR] [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--dev] [--watch]
|
|
14
|
+
```
|
|
15
|
+
<!--/test-cmd-->
|
|
16
|
+
|
|
17
|
+
The `test` command runs tests using [`@nuxt/test-utils`](/docs/getting-started/testing). This command sets `process.env.NODE_ENV` to `test` if not already set.
|
|
18
|
+
|
|
19
|
+
## Arguments
|
|
20
|
+
|
|
21
|
+
<!--test-args-->
|
|
22
|
+
Argument | Description
|
|
23
|
+
--- | ---
|
|
24
|
+
`ROOTDIR="."` | Specifies the working directory (default: `.`)
|
|
25
|
+
<!--/test-args-->
|
|
26
|
+
|
|
27
|
+
## Options
|
|
28
|
+
|
|
29
|
+
<!--test-opts-->
|
|
30
|
+
Option | Default | Description
|
|
31
|
+
--- | --- | ---
|
|
32
|
+
`--cwd=<directory>` | | Specify the working directory, this takes precedence over ROOTDIR (default: `.`)
|
|
33
|
+
`--logLevel=<silent\|info\|verbose>` | | Specify build-time log level
|
|
34
|
+
`--dev` | | Run in dev mode
|
|
35
|
+
`--watch` | | Watch mode
|
|
36
|
+
<!--/test-opts-->
|
|
37
|
+
|
|
38
|
+
::note
|
|
39
|
+
This command sets `process.env.NODE_ENV` to `test`.
|
|
40
|
+
::
|
|
@@ -10,7 +10,7 @@ links:
|
|
|
10
10
|
|
|
11
11
|
<!--typecheck-cmd-->
|
|
12
12
|
```bash [Terminal]
|
|
13
|
-
npx nuxt typecheck [ROOTDIR] [--cwd=<directory>] [--logLevel=<silent|info|verbose>]
|
|
13
|
+
npx nuxt typecheck [ROOTDIR] [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--dotenv] [-e, --extends=<layer-name>]
|
|
14
14
|
```
|
|
15
15
|
<!--/typecheck-cmd-->
|
|
16
16
|
|
|
@@ -31,12 +31,14 @@ Option | Default | Description
|
|
|
31
31
|
--- | --- | ---
|
|
32
32
|
`--cwd=<directory>` | | Specify the working directory, this takes precedence over ROOTDIR (default: `.`)
|
|
33
33
|
`--logLevel=<silent\|info\|verbose>` | | Specify build-time log level
|
|
34
|
+
`--dotenv` | | Path to `.env` file to load, relative to the root directory
|
|
35
|
+
`-e, --extends=<layer-name>` | | Extend from a Nuxt layer
|
|
34
36
|
<!--/typecheck-opts-->
|
|
35
37
|
|
|
36
38
|
::note
|
|
37
|
-
This command sets `process.env.NODE_ENV` to `production`. To override, define `NODE_ENV` in a [`.env`](/docs/guide/directory-structure/env) file or as a command-line argument.
|
|
39
|
+
This command sets `process.env.NODE_ENV` to `production`. To override, define `NODE_ENV` in a [`.env`](/docs/4.x/guide/directory-structure/env) file or as a command-line argument.
|
|
38
40
|
::
|
|
39
41
|
|
|
40
|
-
::read-more{to="/docs/guide/concepts/typescript#type-checking"}
|
|
42
|
+
::read-more{to="/docs/4.x/guide/concepts/typescript#type-checking"}
|
|
41
43
|
Read more on how to enable type-checking at build or development time.
|
|
42
44
|
::
|
|
@@ -10,7 +10,7 @@ links:
|
|
|
10
10
|
|
|
11
11
|
<!--upgrade-cmd-->
|
|
12
12
|
```bash [Terminal]
|
|
13
|
-
npx nuxt upgrade [ROOTDIR] [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--dedupe] [-f, --force] [-ch, --channel=<stable|nightly>]
|
|
13
|
+
npx nuxt upgrade [ROOTDIR] [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--dedupe] [-f, --force] [-ch, --channel=<stable|nightly|v3|v4|v4-nightly|v3-nightly>]
|
|
14
14
|
```
|
|
15
15
|
<!--/upgrade-cmd-->
|
|
16
16
|
|
|
@@ -31,7 +31,7 @@ Option | Default | Description
|
|
|
31
31
|
--- | --- | ---
|
|
32
32
|
`--cwd=<directory>` | | Specify the working directory, this takes precedence over ROOTDIR (default: `.`)
|
|
33
33
|
`--logLevel=<silent\|info\|verbose>` | | Specify build-time log level
|
|
34
|
-
`--dedupe` | |
|
|
34
|
+
`--dedupe` | | Dedupe dependencies after upgrading
|
|
35
35
|
`-f, --force` | | Force upgrade to recreate lockfile and node_modules
|
|
36
|
-
`-ch, --channel=<stable\|nightly>` | `stable` | Specify a channel to install from (default: stable)
|
|
36
|
+
`-ch, --channel=<stable\|nightly\|v3\|v4\|v4-nightly\|v3-nightly>` | `stable` | Specify a channel to install from (default: stable)
|
|
37
37
|
<!--/upgrade-opts-->
|
package/3.api/5.kit/1.modules.md
CHANGED
|
@@ -22,16 +22,16 @@ import { defineNuxtModule } from '@nuxt/kit'
|
|
|
22
22
|
export default defineNuxtModule({
|
|
23
23
|
meta: {
|
|
24
24
|
name: 'my-module',
|
|
25
|
-
configKey: 'myModule'
|
|
25
|
+
configKey: 'myModule',
|
|
26
26
|
},
|
|
27
27
|
defaults: {
|
|
28
|
-
enabled: true
|
|
28
|
+
enabled: true,
|
|
29
29
|
},
|
|
30
30
|
setup (options) {
|
|
31
31
|
if (options.enabled) {
|
|
32
32
|
console.log('My Nuxt module is enabled!')
|
|
33
33
|
}
|
|
34
|
-
}
|
|
34
|
+
},
|
|
35
35
|
})
|
|
36
36
|
```
|
|
37
37
|
|
|
@@ -78,17 +78,17 @@ import { defineNuxtModule } from '@nuxt/kit'
|
|
|
78
78
|
export default defineNuxtModule({
|
|
79
79
|
meta: {
|
|
80
80
|
name: 'my-module',
|
|
81
|
-
configKey: 'myModule'
|
|
81
|
+
configKey: 'myModule',
|
|
82
82
|
},
|
|
83
83
|
defaults: {
|
|
84
84
|
// Module options
|
|
85
|
-
enabled: true
|
|
85
|
+
enabled: true,
|
|
86
86
|
},
|
|
87
87
|
setup (options) {
|
|
88
88
|
if (options.enabled) {
|
|
89
89
|
console.log('My Nuxt module is enabled!')
|
|
90
90
|
}
|
|
91
|
-
}
|
|
91
|
+
},
|
|
92
92
|
})
|
|
93
93
|
```
|
|
94
94
|
|
|
@@ -97,8 +97,8 @@ Users can provide options for this module under the corresponding key in `nuxt.c
|
|
|
97
97
|
```ts
|
|
98
98
|
export default defineNuxtConfig({
|
|
99
99
|
myModule: {
|
|
100
|
-
enabled: false
|
|
101
|
-
}
|
|
100
|
+
enabled: false,
|
|
101
|
+
},
|
|
102
102
|
})
|
|
103
103
|
```
|
|
104
104
|
|
|
@@ -116,7 +116,7 @@ export default defineNuxtModule({
|
|
|
116
116
|
nuxt: '>=3.0.0', // or use '^3.0.0'
|
|
117
117
|
},
|
|
118
118
|
},
|
|
119
|
-
|
|
119
|
+
setup () {
|
|
120
120
|
const resolver = createResolver(import.meta.url)
|
|
121
121
|
// Implement
|
|
122
122
|
},
|
|
@@ -148,26 +148,26 @@ interface ModuleOptions {
|
|
|
148
148
|
export default defineNuxtModule<ModuleOptions>().with({
|
|
149
149
|
meta: {
|
|
150
150
|
name: '@nuxtjs/my-api',
|
|
151
|
-
configKey: 'myApi'
|
|
151
|
+
configKey: 'myApi',
|
|
152
152
|
},
|
|
153
153
|
defaults: {
|
|
154
154
|
baseURL: 'https://api.example.com',
|
|
155
155
|
timeout: 5000,
|
|
156
|
-
retries: 3
|
|
156
|
+
retries: 3,
|
|
157
157
|
},
|
|
158
|
-
setup(resolvedOptions, nuxt) {
|
|
158
|
+
setup (resolvedOptions, nuxt) {
|
|
159
159
|
// resolvedOptions is properly typed as:
|
|
160
160
|
// {
|
|
161
161
|
// apiKey: string // Required, no default provided
|
|
162
162
|
// baseURL: string // Required, has default value
|
|
163
163
|
// timeout: number // Optional, has default value
|
|
164
|
-
// retries: number // Optional, has default value
|
|
164
|
+
// retries: number // Optional, has default value
|
|
165
165
|
// }
|
|
166
|
-
|
|
166
|
+
|
|
167
167
|
console.log(resolvedOptions.baseURL) // ✅ TypeScript knows this is always defined
|
|
168
168
|
console.log(resolvedOptions.timeout) // ✅ TypeScript knows this is always defined
|
|
169
169
|
console.log(resolvedOptions.retries) // ✅ TypeScript knows this is always defined
|
|
170
|
-
}
|
|
170
|
+
},
|
|
171
171
|
})
|
|
172
172
|
```
|
|
173
173
|
|
|
@@ -197,45 +197,45 @@ export default defineNuxtModule({
|
|
|
197
197
|
meta: {
|
|
198
198
|
name: 'my-awesome-module',
|
|
199
199
|
version: '1.2.0', // Required for lifecycle hooks
|
|
200
|
-
configKey: 'myAwesomeModule'
|
|
200
|
+
configKey: 'myAwesomeModule',
|
|
201
201
|
},
|
|
202
202
|
defaults: {
|
|
203
203
|
apiKey: '',
|
|
204
|
-
enabled: true
|
|
204
|
+
enabled: true,
|
|
205
205
|
},
|
|
206
|
-
|
|
207
|
-
onInstall(nuxt) {
|
|
206
|
+
|
|
207
|
+
onInstall (nuxt) {
|
|
208
208
|
// This runs only when the module is first installed
|
|
209
209
|
console.log('Setting up my-awesome-module for the first time!')
|
|
210
|
-
|
|
210
|
+
|
|
211
211
|
// You might want to:
|
|
212
212
|
// - Create initial configuration files
|
|
213
213
|
// - Set up database schemas
|
|
214
214
|
// - Display welcome messages
|
|
215
215
|
// - Perform initial data migration
|
|
216
216
|
},
|
|
217
|
-
|
|
218
|
-
onUpgrade(options, nuxt, previousVersion) {
|
|
217
|
+
|
|
218
|
+
onUpgrade (options, nuxt, previousVersion) {
|
|
219
219
|
// This runs when the module is upgraded to a newer version
|
|
220
220
|
console.log(`Upgrading my-awesome-module from ${previousVersion} to 1.2.0`)
|
|
221
|
-
|
|
221
|
+
|
|
222
222
|
// You might want to:
|
|
223
223
|
// - Migrate configuration files
|
|
224
|
-
// - Update database schemas
|
|
224
|
+
// - Update database schemas
|
|
225
225
|
// - Clean up deprecated files
|
|
226
226
|
// - Display upgrade notes
|
|
227
|
-
|
|
227
|
+
|
|
228
228
|
if (semver.lt(previousVersion, '1.1.0')) {
|
|
229
229
|
console.log('⚠️ Breaking changes in 1.1.0 - please check the migration guide')
|
|
230
230
|
}
|
|
231
231
|
},
|
|
232
|
-
|
|
233
|
-
setup(options, nuxt) {
|
|
232
|
+
|
|
233
|
+
setup (options, nuxt) {
|
|
234
234
|
// Regular setup logic runs on every build
|
|
235
235
|
if (options.enabled) {
|
|
236
236
|
// Configure the module
|
|
237
237
|
}
|
|
238
|
-
}
|
|
238
|
+
},
|
|
239
239
|
})
|
|
240
240
|
```
|
|
241
241
|
|
|
@@ -248,7 +248,7 @@ Install specified Nuxt module programmatically. This is helpful when your module
|
|
|
248
248
|
```ts twoslash
|
|
249
249
|
import { defineNuxtModule, installModule } from '@nuxt/kit'
|
|
250
250
|
|
|
251
|
-
export default defineNuxtModule({
|
|
251
|
+
export default defineNuxtModule({
|
|
252
252
|
async setup () {
|
|
253
253
|
// will install @nuxtjs/fontaine with Roboto font and Impact fallback
|
|
254
254
|
await installModule('@nuxtjs/fontaine', {
|
|
@@ -258,10 +258,10 @@ export default defineNuxtModule({
|
|
|
258
258
|
family: 'Roboto',
|
|
259
259
|
fallbacks: ['Impact'],
|
|
260
260
|
fallbackName: 'fallback-a',
|
|
261
|
-
}
|
|
262
|
-
]
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
263
|
})
|
|
264
|
-
}
|
|
264
|
+
},
|
|
265
265
|
})
|
|
266
266
|
```
|
|
267
267
|
|
|
@@ -284,7 +284,7 @@ async function installModule (moduleToInstall: string | NuxtModule, inlineOption
|
|
|
284
284
|
```ts
|
|
285
285
|
import { defineNuxtModule, installModule } from '@nuxt/kit'
|
|
286
286
|
|
|
287
|
-
export default defineNuxtModule({
|
|
287
|
+
export default defineNuxtModule({
|
|
288
288
|
async setup (options, nuxt) {
|
|
289
289
|
// will install @nuxtjs/fontaine with Roboto font and Impact fallback
|
|
290
290
|
await installModule('@nuxtjs/fontaine', {
|
|
@@ -294,9 +294,9 @@ export default defineNuxtModule({
|
|
|
294
294
|
family: 'Roboto',
|
|
295
295
|
fallbacks: ['Impact'],
|
|
296
296
|
fallbackName: 'fallback-a',
|
|
297
|
-
}
|
|
298
|
-
]
|
|
297
|
+
},
|
|
298
|
+
],
|
|
299
299
|
})
|
|
300
|
-
}
|
|
300
|
+
},
|
|
301
301
|
})
|
|
302
302
|
```
|
|
@@ -10,7 +10,7 @@ links:
|
|
|
10
10
|
|
|
11
11
|
## `useRuntimeConfig`
|
|
12
12
|
|
|
13
|
-
At build-time, it is possible to access the resolved Nuxt [runtime config](/docs/guide/going-further/runtime-config).
|
|
13
|
+
At build-time, it is possible to access the resolved Nuxt [runtime config](/docs/4.x/guide/going-further/runtime-config).
|
|
14
14
|
|
|
15
15
|
### Type
|
|
16
16
|
|
|
@@ -21,17 +21,17 @@ import { addTemplate, defineNuxtModule } from '@nuxt/kit'
|
|
|
21
21
|
import { defu } from 'defu'
|
|
22
22
|
|
|
23
23
|
export default defineNuxtModule({
|
|
24
|
-
setup(options, nuxt) {
|
|
24
|
+
setup (options, nuxt) {
|
|
25
25
|
const globalMeta = defu(nuxt.options.app.head, {
|
|
26
26
|
charset: options.charset,
|
|
27
|
-
viewport: options.viewport
|
|
27
|
+
viewport: options.viewport,
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
addTemplate({
|
|
31
31
|
filename: 'meta.config.mjs',
|
|
32
|
-
getContents: () => 'export default ' + JSON.stringify({ globalMeta, mixinKey: 'setup' })
|
|
32
|
+
getContents: () => 'export default ' + JSON.stringify({ globalMeta, mixinKey: 'setup' }),
|
|
33
33
|
})
|
|
34
|
-
}
|
|
34
|
+
},
|
|
35
35
|
})
|
|
36
36
|
```
|
|
37
37
|
|
|
@@ -88,7 +88,7 @@ In the module above, we generate a virtual file named `meta.config.mjs`. In the
|
|
|
88
88
|
import { createHead as createServerHead } from '@unhead/vue/server'
|
|
89
89
|
import { createHead as createClientHead } from '@unhead/vue/client'
|
|
90
90
|
import { defineNuxtPlugin } from '#imports'
|
|
91
|
-
// @ts-
|
|
91
|
+
// @ts-expect-error - virtual file
|
|
92
92
|
import metaConfig from '#build/meta.config.mjs'
|
|
93
93
|
|
|
94
94
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
@@ -279,7 +279,9 @@ export default defineNuxtModule({
|
|
|
279
279
|
]
|
|
280
280
|
// watch and rebuild routes template list when one of the pages changes
|
|
281
281
|
nuxt.hook('builder:watch', async (event, relativePath) => {
|
|
282
|
-
if (event === 'change') {
|
|
282
|
+
if (event === 'change') {
|
|
283
|
+
return
|
|
284
|
+
}
|
|
283
285
|
|
|
284
286
|
const path = resolve(nuxt.options.srcDir, relativePath)
|
|
285
287
|
if (updateTemplatePaths.some(dir => path.startsWith(dir))) {
|