@nuxt/docs-nightly 4.4.7-29652887.e4d5cc70 → 4.4.7-29673443.69f58084
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/3.guide/4.modules/3.recipes-basics.md +5 -33
- package/3.guide/4.modules/4.module-dependencies.md +84 -0
- package/3.guide/4.modules/index.md +3 -0
- package/4.api/5.kit/12.resolving.md +3 -3
- package/4.api/6.nuxt-config.md +21 -7
- package/package.json +1 -1
- /package/3.guide/4.modules/{4.recipes-advanced.md → 5.recipes-advanced.md} +0 -0
- /package/3.guide/4.modules/{5.testing.md → 6.testing.md} +0 -0
- /package/3.guide/4.modules/{6.best-practices.md → 7.best-practices.md} +0 -0
- /package/3.guide/4.modules/{7.ecosystem.md → 8.ecosystem.md} +0 -0
|
@@ -393,47 +393,19 @@ export default defineNuxtModule({
|
|
|
393
393
|
|
|
394
394
|
## Use Other Modules
|
|
395
395
|
|
|
396
|
-
If your module depends on other modules, you can specify them using the `moduleDependencies` option
|
|
396
|
+
If your module depends on other modules, you can specify them using the `moduleDependencies` option:
|
|
397
397
|
|
|
398
398
|
```ts
|
|
399
|
-
import {
|
|
400
|
-
|
|
401
|
-
const resolver = createResolver(import.meta.url)
|
|
399
|
+
import { defineNuxtModule } from '@nuxt/kit'
|
|
402
400
|
|
|
403
|
-
export default defineNuxtModule
|
|
401
|
+
export default defineNuxtModule({
|
|
404
402
|
meta: {
|
|
405
403
|
name: 'my-module',
|
|
406
404
|
},
|
|
407
405
|
moduleDependencies: {
|
|
408
|
-
'@nuxtjs/tailwindcss': {
|
|
409
|
-
// You can specify a version constraint for the module
|
|
410
|
-
version: '>=6',
|
|
411
|
-
// Any configuration that should override `nuxt.options`
|
|
412
|
-
overrides: {
|
|
413
|
-
exposeConfig: true,
|
|
414
|
-
},
|
|
415
|
-
// Any configuration that should be set. It will override module defaults but
|
|
416
|
-
// will not override any configuration set in `nuxt.options`
|
|
417
|
-
defaults: {
|
|
418
|
-
config: {
|
|
419
|
-
darkMode: 'class',
|
|
420
|
-
content: {
|
|
421
|
-
files: [
|
|
422
|
-
resolver.resolve('./runtime/components/**/*.{vue,mjs,ts}'),
|
|
423
|
-
resolver.resolve('./runtime/*.{mjs,js,ts}'),
|
|
424
|
-
],
|
|
425
|
-
},
|
|
426
|
-
},
|
|
427
|
-
},
|
|
428
|
-
},
|
|
429
|
-
},
|
|
430
|
-
setup (options, nuxt) {
|
|
431
|
-
// We can inject our CSS file which includes Tailwind's directives
|
|
432
|
-
nuxt.options.css.push(resolver.resolve('./runtime/assets/styles.css'))
|
|
406
|
+
'@nuxtjs/tailwindcss': {},
|
|
433
407
|
},
|
|
434
408
|
})
|
|
435
409
|
```
|
|
436
410
|
|
|
437
|
-
|
|
438
|
-
The `moduleDependencies` option replaces the deprecated `installModule` function and ensures proper setup order and configuration merging.
|
|
439
|
-
::
|
|
411
|
+
:read-more{to="/docs/4.x/guide/modules/module-dependencies"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'Module Dependencies'
|
|
3
|
+
description: 'Declare dependencies on other modules with version constraints and configuration merging.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
If your module depends on other modules, you can declare them using the `moduleDependencies` option. Nuxt then ensures those modules are installed in the correct order, validates any version constraints you provide, and merges configuration you supply for them.
|
|
7
|
+
|
|
8
|
+
## Basic Usage
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
12
|
+
|
|
13
|
+
const resolver = createResolver(import.meta.url)
|
|
14
|
+
|
|
15
|
+
export default defineNuxtModule<ModuleOptions>({
|
|
16
|
+
meta: {
|
|
17
|
+
name: 'my-module',
|
|
18
|
+
},
|
|
19
|
+
moduleDependencies: {
|
|
20
|
+
'@nuxtjs/tailwindcss': {
|
|
21
|
+
// You can specify a version constraint for the module
|
|
22
|
+
version: '>=6',
|
|
23
|
+
// Any configuration that should override `nuxt.options`
|
|
24
|
+
overrides: {
|
|
25
|
+
exposeConfig: true,
|
|
26
|
+
},
|
|
27
|
+
// Any configuration that should be set. It will override module defaults but
|
|
28
|
+
// will not override any configuration set in `nuxt.options`
|
|
29
|
+
defaults: {
|
|
30
|
+
config: {
|
|
31
|
+
darkMode: 'class',
|
|
32
|
+
content: {
|
|
33
|
+
files: [
|
|
34
|
+
resolver.resolve('./runtime/components/**/*.{vue,mjs,ts}'),
|
|
35
|
+
resolver.resolve('./runtime/*.{mjs,js,ts}'),
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
setup (options, nuxt) {
|
|
43
|
+
// We can inject our CSS file which includes Tailwind's directives
|
|
44
|
+
nuxt.options.css.push(resolver.resolve('./runtime/assets/styles.css'))
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
::callout{type="info"}
|
|
50
|
+
The `moduleDependencies` option replaces the deprecated `installModule` function.
|
|
51
|
+
::
|
|
52
|
+
|
|
53
|
+
The key of each entry identifies the module to depend on. You can use an npm package name, a path to a local module directory, or a Nuxt alias such as `~` or `@`.
|
|
54
|
+
|
|
55
|
+
## Depending on Local Modules
|
|
56
|
+
|
|
57
|
+
When the dependency lives inside the [`modules/` directory](/docs/4.x/guide/directory-structure/modules), use a file path to declare the dependency:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { defineNuxtModule } from '@nuxt/kit'
|
|
61
|
+
|
|
62
|
+
export default defineNuxtModule({
|
|
63
|
+
moduleDependencies: {
|
|
64
|
+
// Path relative to the project root
|
|
65
|
+
'./modules/my-local-module': {},
|
|
66
|
+
// Or using a Nuxt alias
|
|
67
|
+
'~/modules/another-local-module': {},
|
|
68
|
+
},
|
|
69
|
+
// ...
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
::important
|
|
74
|
+
**Relative paths are resolved from your project's `rootDir`**, not from the file declaring the dependency. A module at `modules/foo.ts` referencing `modules/bar.ts` must use `'./modules/bar'`, not `'./bar'`. Using a Nuxt alias such as `~/modules/bar` avoids this ambiguity.
|
|
75
|
+
::
|
|
76
|
+
|
|
77
|
+
## Options
|
|
78
|
+
|
|
79
|
+
Each entry in `moduleDependencies` accepts the following fields:
|
|
80
|
+
|
|
81
|
+
- `version`: A semver range. If the resolved module's version does not satisfy this range, Nuxt throws an error. Version checks only apply when the dependency can be resolved to a `package.json`, so they are a no-op for project-local modules.
|
|
82
|
+
- `overrides`: Configuration applied on top of `nuxt.options`, taking precedence over user configuration.
|
|
83
|
+
- `defaults`: Configuration applied below `nuxt.options`. User configuration takes precedence over these.
|
|
84
|
+
- `optional`: If `true`, the module is not installed automatically when missing. `overrides` and `defaults` are still applied if the module is installed elsewhere.
|
|
@@ -21,6 +21,9 @@ With modules, you can encapsulate, properly test, and share custom solutions as
|
|
|
21
21
|
::card{icon="i-lucide-code" title="Add Plugins, Components & More" to="/docs/4.x/guide/modules/recipes-basics"}
|
|
22
22
|
Learn how to inject plugins, components, composables and server routes from your module.
|
|
23
23
|
::
|
|
24
|
+
::card{icon="i-lucide-link" title="Depend on Other Modules" to="/docs/4.x/guide/modules/module-dependencies"}
|
|
25
|
+
Declare dependencies on other modules with version constraints and configuration merging.
|
|
26
|
+
::
|
|
24
27
|
::card{icon="i-lucide-layers" title="Use Hooks & Extend Types" to="/docs/4.x/guide/modules/recipes-advanced"}
|
|
25
28
|
Master lifecycle hooks, virtual files and TypeScript declarations in your modules.
|
|
26
29
|
::
|
|
@@ -8,11 +8,11 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
Sometimes you need to resolve a
|
|
11
|
+
Sometimes you need to resolve a path relative to the current module without knowing the name or extension. For example, you may want to add a plugin that is located in the same directory as the module. To handle these cases, Nuxt provides a set of utilities to resolve paths. `resolvePath` and `resolveAlias` are used to resolve paths relative to the current module. `findPath` is used to find the first existing file in a given set of paths. `createResolver` is used to create a resolver relative to the base path.
|
|
12
12
|
|
|
13
13
|
## `resolvePath`
|
|
14
14
|
|
|
15
|
-
Resolves full path to a file or directory respecting Nuxt alias and extensions options. If path could not be resolved, normalized input path will be returned.
|
|
15
|
+
Resolves the full path to a file or directory, respecting Nuxt alias and extensions options. If a path could not be resolved, a normalized input path will be returned.
|
|
16
16
|
|
|
17
17
|
### Usage
|
|
18
18
|
|
|
@@ -115,7 +115,7 @@ function resolveAlias (path: string, alias?: Record<string, string>): string
|
|
|
115
115
|
|
|
116
116
|
## `findPath`
|
|
117
117
|
|
|
118
|
-
Try to resolve first existing file in given paths.
|
|
118
|
+
Try to resolve first existing file in a given set of paths.
|
|
119
119
|
|
|
120
120
|
### Usage
|
|
121
121
|
|
package/4.api/6.nuxt-config.md
CHANGED
|
@@ -313,7 +313,7 @@ This can be overridden with `definePageMeta` on an individual page.
|
|
|
313
313
|
- **Type**: `boolean`
|
|
314
314
|
- **Default:** `false`
|
|
315
315
|
|
|
316
|
-
**See**: [Nuxt View Transition API docs](
|
|
316
|
+
**See**: [Nuxt View Transition API docs](/docs/4.x/getting-started/transitions#view-transitions-api-experimental)
|
|
317
317
|
|
|
318
318
|
## appConfig
|
|
319
319
|
|
|
@@ -506,7 +506,7 @@ Any components in the directories configured here can be used throughout your pa
|
|
|
506
506
|
}
|
|
507
507
|
```
|
|
508
508
|
|
|
509
|
-
**See**: [`app/components/` directory documentation](
|
|
509
|
+
**See**: [`app/components/` directory documentation](/docs/4.x/directory-structure/app/components)
|
|
510
510
|
|
|
511
511
|
## css
|
|
512
512
|
|
|
@@ -837,7 +837,7 @@ Any file in `app/pages/`, `app/layouts/`, `app/middleware/`, and `public/` direc
|
|
|
837
837
|
|
|
838
838
|
Configure how Nuxt auto-imports composables into your application.
|
|
839
839
|
|
|
840
|
-
**See**: [Nuxt documentation](
|
|
840
|
+
**See**: [Nuxt documentation](/docs/4.x/directory-structure/app/composables)
|
|
841
841
|
|
|
842
842
|
### `dirs`
|
|
843
843
|
|
|
@@ -1159,7 +1159,7 @@ and these plugins do not need to be listed in `nuxt.config` unless you
|
|
|
1159
1159
|
need to customize their order. All plugins are deduplicated by their src path.
|
|
1160
1160
|
::
|
|
1161
1161
|
|
|
1162
|
-
**See**: [`app/plugins/` directory documentation](
|
|
1162
|
+
**See**: [`app/plugins/` directory documentation](/docs/4.x/directory-structure/app/plugins)
|
|
1163
1163
|
|
|
1164
1164
|
**Example**:
|
|
1165
1165
|
```ts
|
|
@@ -1320,7 +1320,7 @@ Each handler accepts the following options:
|
|
|
1320
1320
|
|
|
1321
1321
|
- **Type**: `array`
|
|
1322
1322
|
|
|
1323
|
-
**See**: [`server/` directory documentation](
|
|
1323
|
+
**See**: [`server/` directory documentation](/docs/4.x/directory-structure/server)
|
|
1324
1324
|
|
|
1325
1325
|
::callout
|
|
1326
1326
|
**Note**: Files from `server/api`, `server/middleware` and `server/routes` will be automatically registered by Nuxt.
|
|
@@ -1521,6 +1521,18 @@ Include parent workspace in the Nuxt project. Mostly useful for themes and modul
|
|
|
1521
1521
|
- **Type**: `boolean`
|
|
1522
1522
|
- **Default:** `false`
|
|
1523
1523
|
|
|
1524
|
+
### `nodeTsConfig`
|
|
1525
|
+
|
|
1526
|
+
You can extend the generated `.nuxt/tsconfig.node.json` TypeScript configuration using this option.
|
|
1527
|
+
|
|
1528
|
+
**See**: [tsconfig.json information](/docs/4.x/directory-structure/tsconfig)
|
|
1529
|
+
|
|
1530
|
+
### `sharedTsConfig`
|
|
1531
|
+
|
|
1532
|
+
You can extend the generated `.nuxt/tsconfig.shared.json` TypeScript configuration using this option.
|
|
1533
|
+
|
|
1534
|
+
**See**: [tsconfig.json information](/docs/4.x/directory-structure/tsconfig)
|
|
1535
|
+
|
|
1524
1536
|
### `shim`
|
|
1525
1537
|
|
|
1526
1538
|
Generate a `*.vue` shim.
|
|
@@ -1542,7 +1554,9 @@ TypeScript comes with certain checks to give you more safety and analysis of you
|
|
|
1542
1554
|
|
|
1543
1555
|
### `tsConfig`
|
|
1544
1556
|
|
|
1545
|
-
You can extend the generated
|
|
1557
|
+
You can extend the generated `.nuxt/tsconfig.app.json` TypeScript configuration using this option.
|
|
1558
|
+
|
|
1559
|
+
**See**: [tsconfig.json information](/docs/4.x/directory-structure/tsconfig)
|
|
1546
1560
|
|
|
1547
1561
|
### `typeCheck`
|
|
1548
1562
|
|
|
@@ -1553,7 +1567,7 @@ If set to true, this will type check in development. You can restrict this to bu
|
|
|
1553
1567
|
- **Type**: `boolean`
|
|
1554
1568
|
- **Default:** `false`
|
|
1555
1569
|
|
|
1556
|
-
**See**: [Nuxt TypeScript docs](
|
|
1570
|
+
**See**: [Nuxt TypeScript docs](/docs/4.x/guide/concepts/typescript)
|
|
1557
1571
|
|
|
1558
1572
|
## unhead
|
|
1559
1573
|
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|