@nuxt/docs 3.17.1 → 3.17.2

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.
@@ -17,39 +17,17 @@ Load Nuxt programmatically. It will load the Nuxt configuration, instantiate and
17
17
  ### Type
18
18
 
19
19
  ```ts
20
- async function loadNuxt (loadOptions?: LoadNuxtOptions): Promise<Nuxt>
21
-
22
- interface LoadNuxtOptions extends LoadNuxtConfigOptions {
23
- dev?: boolean
24
- ready?: boolean
25
- }
20
+ function loadNuxt (loadOptions?: LoadNuxtOptions): Promise<Nuxt>
26
21
  ```
27
22
 
28
23
  ### Parameters
29
24
 
30
- #### `loadOptions`
31
-
32
- **Type**: `LoadNuxtOptions`
33
-
34
- **Default**: `{}`
35
-
36
- Loading conditions for Nuxt. `loadNuxt` uses [`c12`](https://github.com/unjs/c12) under the hood, so it accepts the same options as `c12.loadConfig` with some additional options:
37
-
38
- - `dev` (optional)
25
+ **`loadOptions`**: Loading conditions for Nuxt. `loadNuxt` uses [`c12`](https://github.com/unjs/c12) under the hood, so it accepts the same options as `c12.loadConfig` with some additional options:
39
26
 
40
- **Type**: `boolean`
41
-
42
- **Default**: `false`
43
-
44
- If set to `true`, Nuxt will be loaded in development mode.
45
-
46
- - `ready` (optional)
47
-
48
- **Type**: `boolean`
49
-
50
- **Default**: `true`
51
-
52
- If set to `true`, Nuxt will be ready to use after the `loadNuxt` call. If set to `false`, you will need to call `nuxt.ready()` to make sure Nuxt is ready to use.
27
+ | Property | Type | Required | Description |
28
+ | -------- | --------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
29
+ | `dev` | `boolean` | `false` | If set to `true`, Nuxt will be loaded in development mode. |
30
+ | `ready` | `boolean` | `true` | If set to `true`, Nuxt will be ready to use after the `loadNuxt` call. If set to `false`, you will need to call `nuxt.ready()` to make sure Nuxt is ready to use. |
53
31
 
54
32
  ## `buildNuxt`
55
33
 
@@ -58,18 +36,12 @@ Build Nuxt programmatically. It will invoke the builder (currently [@nuxt/vite-b
58
36
  ### Type
59
37
 
60
38
  ```ts
61
- async function buildNuxt (nuxt: Nuxt): Promise<any>
39
+ function buildNuxt (nuxt: Nuxt): Promise<any>
62
40
  ```
63
41
 
64
42
  ### Parameters
65
43
 
66
- #### `nuxt`
67
-
68
- **Type**: `Nuxt`
69
-
70
- **Required**: `true`
71
-
72
- Nuxt instance to build. It can be retrieved from the context via `useNuxt()` call.
44
+ **`nuxt`**: Nuxt instance to build. It can be retrieved from the context via `useNuxt()` call.
73
45
 
74
46
  ## `loadNuxtConfig`
75
47
 
@@ -78,18 +50,12 @@ Load Nuxt configuration. It will return the promise with the configuration objec
78
50
  ### Type
79
51
 
80
52
  ```ts
81
- async function loadNuxtConfig (options: LoadNuxtConfigOptions): Promise<NuxtOptions>
53
+ function loadNuxtConfig (options: LoadNuxtConfigOptions): Promise<NuxtOptions>
82
54
  ```
83
55
 
84
56
  ### Parameters
85
57
 
86
- #### `options`
87
-
88
- **Type**: `LoadNuxtConfigOptions`
89
-
90
- **Required**: `true`
91
-
92
- Options to pass in [`c12`](https://github.com/unjs/c12#options) `loadConfig` call.
58
+ **`options`**: Options to pass in [`c12`](https://github.com/unjs/c12#options) `loadConfig` call.
93
59
 
94
60
  ## `writeTypes`
95
61
 
@@ -99,27 +65,8 @@ Generates `tsconfig.json` and writes it to the project buildDir.
99
65
 
100
66
  ```ts
101
67
  function writeTypes (nuxt?: Nuxt): void
102
-
103
- interface Nuxt {
104
- options: NuxtOptions
105
- hooks: Hookable<NuxtHooks>
106
- hook: Nuxt['hooks']['hook']
107
- callHook: Nuxt['hooks']['callHook']
108
- addHooks: Nuxt['hooks']['addHooks']
109
- ready: () => Promise<void>
110
- close: () => Promise<void>
111
- server?: any
112
- vfs: Record<string, string>
113
- apps: Record<string, NuxtApp>
114
- }
115
68
  ```
116
69
 
117
70
  ### Parameters
118
71
 
119
- #### `nuxt`
120
-
121
- **Type**: `Nuxt`
122
-
123
- **Required**: `true`
124
-
125
- Nuxt instance to build. It can be retrieved from the context via `useNuxt()` call.
72
+ **`nuxt`**: Nuxt instance to build. It can be retrieved from the context via `useNuxt()` call.
@@ -14,64 +14,39 @@ Nuxt Kit utilities can be used in Nuxt 3, Nuxt 2 with Bridge and even Nuxt 2 wit
14
14
 
15
15
  Checks if constraints are met for the current Nuxt version. If not, returns an array of messages. Nuxt 2 version also checks for `bridge` support.
16
16
 
17
+ ### Usage
18
+
19
+ ```ts twoslash
20
+ import { defineNuxtModule, checkNuxtCompatibility } from '@nuxt/kit'
21
+
22
+ export default defineNuxtModule({
23
+ async setup (_options, nuxt) {
24
+ const issues = await checkNuxtCompatibility({ nuxt: '^2.16.0' }, nuxt)
25
+ if (issues.length) {
26
+ console.warn('Nuxt compatibility issues found:\n' + issues.toString())
27
+ } else {
28
+ // do something
29
+ }
30
+ }
31
+ })
32
+ ```
33
+
17
34
  ### Type
18
35
 
19
36
  ```ts
20
- async function checkNuxtCompatibility(
21
- constraints: NuxtCompatibility,
22
- nuxt?: Nuxt
23
- ): Promise<NuxtCompatibilityIssues>;
24
-
25
- interface NuxtCompatibility {
26
- nuxt?: string;
27
- bridge?: boolean;
28
- builder?: {
29
- // Set `false` if your module is not compatible with a builder
30
- // or a semver-compatible string version constraint
31
- vite?: false | string;
32
- webpack?: false | string;
33
- };
34
- }
35
-
36
- interface NuxtCompatibilityIssue {
37
- name: string;
38
- message: string;
39
- }
40
-
41
- interface NuxtCompatibilityIssues extends Array<NuxtCompatibilityIssue> {
42
- toString(): string;
43
- }
37
+ function checkNuxtCompatibility(constraints: NuxtCompatibility, nuxt?: Nuxt): Promise<NuxtCompatibilityIssues>;
44
38
  ```
45
39
 
46
40
  ### Parameters
47
41
 
48
- #### `constraints`
49
-
50
- **Type**: `NuxtCompatibility`
51
-
52
- **Default**: `{}`
53
-
54
- Constraints to check for. It accepts the following properties:
55
-
56
- - `nuxt` (optional)
57
-
58
- **Type**: `string`
42
+ **`constraints`**: Version and builder constraints to check against. It accepts the following properties:
59
43
 
60
- Nuxt version in semver format. Versions may be defined in Node.js way, for example: `>=2.15.0 <3.0.0`.
44
+ | Property | Type | Required | Description |
45
+ | -------- | --------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
46
+ | `nuxt` | `string` | `false` | Nuxt version in semver format. Versions may be defined in Node.js way, for example: `>=2.15.0 <3.0.0`. |
47
+ | `bridge` | `Record<string, string \| false>`{lang="ts"} | `false` | Specifies version constraints or disables compatibility for specific Nuxt builders like `vite`, `webpack`, or `rspack`. Use `false` to disable. |
61
48
 
62
- - `bridge` (optional)
63
-
64
- **Type**: `boolean`
65
-
66
- If set to `true`, it will check if the current Nuxt version supports `bridge`.
67
-
68
- #### `nuxt`
69
-
70
- **Type**: `Nuxt`
71
-
72
- **Default**: `useNuxt()`
73
-
74
- Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
49
+ **`nuxt`**: Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
75
50
 
76
51
  ## `assertNuxtCompatibility`
77
52
 
@@ -79,135 +54,119 @@ Asserts that constraints are met for the current Nuxt version. If not, throws an
79
54
 
80
55
  ### Type
81
56
 
82
- ```ts
83
- async function assertNuxtCompatibility(
84
- constraints: NuxtCompatibility,
85
- nuxt?: Nuxt
86
- ): Promise<true>;
87
-
88
- interface NuxtCompatibility {
89
- nuxt?: string;
90
- bridge?: boolean;
91
- }
57
+ ```ts twoslash
58
+ // @errors: 2391
59
+ import type { Nuxt, NuxtCompatibility } from '@nuxt/schema'
60
+ // ---cut---
61
+ function assertNuxtCompatibility(constraints: NuxtCompatibility, nuxt?: Nuxt): Promise<true>;
92
62
  ```
93
63
 
94
64
  ### Parameters
95
65
 
96
- #### `constraints`
66
+ **`constraints`**: Version and builder constraints to check against. Refer to the [constraints table in `checkNuxtCompatibility`](#parameters) for details.
97
67
 
98
- **Type**: `NuxtCompatibility`
99
-
100
- **Default**: `{}`
101
-
102
- Constraints to check for. It accepts the following properties:
103
-
104
- - `nuxt` (optional)
105
-
106
- **Type**: `string`
107
-
108
- Nuxt version in semver format. Versions may be defined in Node.js way, for example: `>=2.15.0 <3.0.0`.
109
-
110
- - `bridge` (optional)
111
-
112
- **Type**: `boolean`
113
-
114
- If set to `true`, it will check if the current Nuxt version supports `bridge`.
115
-
116
- #### `nuxt`
117
-
118
- **Type**: `Nuxt`
119
-
120
- **Default**: `useNuxt()`
121
-
122
- Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
68
+ **`nuxt`**: Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
123
69
 
124
70
  ## `hasNuxtCompatibility`
125
71
 
126
72
  Checks if constraints are met for the current Nuxt version. Return `true` if all constraints are met, otherwise returns `false`. Nuxt 2 version also checks for `bridge` support.
127
73
 
74
+ ### Usage
75
+
76
+ ```ts twoslash
77
+ import { defineNuxtModule, hasNuxtCompatibility } from '@nuxt/kit'
78
+
79
+ export default defineNuxtModule({
80
+ async setup (_options, nuxt) {
81
+ const usingNewPostcss = await hasNuxtCompatibility({ nuxt: '^2.16.0' }, nuxt)
82
+ if (usingNewPostcss) {
83
+ // do something
84
+ } else {
85
+ // do something else
86
+ }
87
+ }
88
+ })
89
+ ```
90
+
128
91
  ### Type
129
92
 
130
93
  ```ts
131
- async function hasNuxtCompatibility(
132
- constraints: NuxtCompatibility,
133
- nuxt?: Nuxt
134
- ): Promise<boolean>;
135
-
136
- interface NuxtCompatibility {
137
- nuxt?: string;
138
- bridge?: boolean;
139
- }
94
+ function hasNuxtCompatibility(constraints: NuxtCompatibility, nuxt?: Nuxt): Promise<boolean>;
140
95
  ```
141
96
 
142
97
  ### Parameters
143
98
 
144
- #### `constraints`
145
-
146
- **Type**: `NuxtCompatibility`
99
+ **`constraints`**: Version and builder constraints to check against. Refer to the [constraints table in `checkNuxtCompatibility`](#parameters) for details.
147
100
 
148
- **Default**: `{}`
101
+ **`nuxt`**: Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
149
102
 
150
- Constraints to check for. It accepts the following properties:
103
+ ## `isNuxtMajorVersion`
151
104
 
152
- - `nuxt` (optional)
105
+ Check if current Nuxt instance is of specified major version
153
106
 
154
- **Type**: `string`
107
+ ### Usage
155
108
 
156
- Nuxt version in semver format. Versions may be defined in Node.js way, for example: `>=2.15.0 <3.0.0`.
109
+ ```ts twoslash
110
+ import { defineNuxtModule, isNuxtMajorVersion } from '@nuxt/kit'
157
111
 
158
- - `bridge` (optional)
112
+ export default defineNuxtModule({
113
+ async setup () {
114
+ if (isNuxtMajorVersion(3)) {
115
+ // do something for Nuxt 3
116
+ } else {
117
+ // do something else for other versions
118
+ }
119
+ }
120
+ })
121
+ ```
159
122
 
160
- **Type**: `boolean`
123
+ ### Type
161
124
 
162
- If set to `true`, it will check if the current Nuxt version supports `bridge`.
125
+ ```ts
126
+ function isNuxtMajorVersion(major: number, nuxt?: Nuxt): boolean;
127
+ ```
163
128
 
164
- #### `nuxt`
129
+ ### Parameters
165
130
 
166
- **Type**: `Nuxt`
131
+ **`major`**: Major version to check against.
167
132
 
168
- **Default**: `useNuxt()`
133
+ **`nuxt`**: Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
169
134
 
170
- Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
135
+ ## `isNuxt3`
171
136
 
172
- ## `isNuxt2`
137
+ Checks if the current Nuxt version is 3.x.
173
138
 
174
- Checks if the current Nuxt version is 2.x.
139
+ ::note
140
+ Use `isNuxtMajorVersion(2, nuxt)` instead. This may be removed in \@nuxt/kit v5 or a future major version.
141
+ ::
175
142
 
176
143
  ### Type
177
144
 
178
145
  ```ts
179
- function isNuxt2(nuxt?: Nuxt): boolean;
146
+ function isNuxt3(nuxt?: Nuxt): boolean;
180
147
  ```
181
148
 
182
149
  ### Parameters
183
150
 
184
- #### `nuxt`
185
-
186
- **Type**: `Nuxt`
151
+ **`nuxt`**: Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
187
152
 
188
- **Default**: `useNuxt()`
153
+ ## `isNuxt2`
189
154
 
190
- Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
155
+ Checks if the current Nuxt version is 2.x.
191
156
 
192
- ## `isNuxt3`
193
-
194
- Checks if the current Nuxt version is 3.x.
157
+ ::note
158
+ Use `isNuxtMajorVersion(2, nuxt)` instead. This may be removed in \@nuxt/kit v5 or a future major version.
159
+ ::
195
160
 
196
161
  ### Type
197
162
 
198
163
  ```ts
199
- function isNuxt3(nuxt?: Nuxt): boolean;
164
+ function isNuxt2(nuxt?: Nuxt): boolean;
200
165
  ```
201
166
 
202
167
  ### Parameters
203
168
 
204
- #### `nuxt`
205
-
206
- **Type**: `Nuxt`
207
-
208
- **Default**: `useNuxt()`
209
-
210
- Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
169
+ **`nuxt`**: Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
211
170
 
212
171
  ## `getNuxtVersion`
213
172
 
@@ -221,10 +180,4 @@ function getNuxtVersion(nuxt?: Nuxt): string;
221
180
 
222
181
  ### Parameters
223
182
 
224
- #### `nuxt`
225
-
226
- **Type**: `Nuxt`
227
-
228
- **Default**: `useNuxt()`
229
-
230
- Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
183
+ **`nuxt`**: Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call.
@@ -58,7 +58,7 @@ function addImports (imports: Import | Import[]): void
58
58
 
59
59
  `imports`: An object or an array of objects with the following properties:
60
60
 
61
- | Prop | Type | Required | Description |
61
+ | Property | Type | Required | Description |
62
62
  | ------------------ | ---------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |
63
63
  | `name` | `string` | `true` | Import name to be detected. |
64
64
  | `from` | `string` | `true` | Module specifier to import from. |
@@ -98,7 +98,7 @@ function addImportsDir (dirs: string | string[], options?: { prepend?: boolean }
98
98
 
99
99
  ### Parameters
100
100
 
101
- | Prop | Type | Required | Description |
101
+ | Property | Type | Required | Description |
102
102
  | ------------------ | ---------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |
103
103
  | `dirs` | `string \| string[]`{lang="ts"} | `true` | A string or an array of strings with the path to the directory to import from. |
104
104
  | `options` | `{ prepend?: boolean }`{lang="ts"} | `false` | Options to pass to the import. If `prepend` is set to `true`, the imports will be prepended to the list of imports. |
@@ -138,7 +138,7 @@ function addImportsSources (importSources: ImportSource | ImportSource[]): void
138
138
 
139
139
  **importSources**: An object or an array of objects with the following properties:
140
140
 
141
- | Prop | Type | Required | Description |
141
+ | Property | Type | Required | Description |
142
142
  | ------------------ | ---------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |
143
143
  | `from` | `string` | `true` | Module specifier to import from. |
144
144
  | `imports` | `PresetImport \| ImportSource[]`{lang="ts"} | `true` | An object or an array of objects, which can be import names, import objects or import sources. |
@@ -46,7 +46,7 @@ function addComponentsDir (dir: ComponentsDir, opts: { prepend?: boolean } = {})
46
46
 
47
47
  `dir` An object with the following properties:
48
48
 
49
- | Prop | Type | Required | Description |
49
+ | Property | Type | Required | Description |
50
50
  | ------------------ | ---------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |
51
51
  | `path` | `string` | `true` | Path (absolute or relative) to the directory containing your components. You can use Nuxt aliases (~ or @) to refer to directories inside project or directly use an npm package path similar to require. |
52
52
  | `pattern` | `string \| string[]`{lang="ts"} | `false` | Accept Pattern that will be run against specified path. |
@@ -66,7 +66,7 @@ function addComponentsDir (dir: ComponentsDir, opts: { prepend?: boolean } = {})
66
66
 
67
67
  `opts`
68
68
 
69
- | Prop | Type | Required | Description |
69
+ | Property | Type | Required | Description |
70
70
  | ------------------ | ---------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |
71
71
  | `prepend` | `boolean` | `false` | If set to `true`, the directory will be prepended to the array with `unshift()` instead of `push()`. |
72
72
 
@@ -110,7 +110,7 @@ function addComponent (options: AddComponentOptions): void
110
110
 
111
111
  `options`: An object with the following properties:
112
112
 
113
- | Prop | Type | Required | Description |
113
+ | Property | Type | Required | Description |
114
114
  | ------------------ | ---------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |
115
115
  | `name` | `string` | `true` | Component name. |
116
116
  | `filePath` | `string` | `true` | Path to the component. |
@@ -125,3 +125,22 @@ function addComponent (options: AddComponentOptions): void
125
125
  | `island` | `boolean` | `false` | If enabled, registers component as island. You can read more about islands in [`<NuxtIsland/>`](/docs/api/components/nuxt-island#nuxtisland) component description. |
126
126
  | `mode` | `'client' \| 'server' \| 'all'`{lang="ts"} | `false` | This options indicates if component should render on client, server or both. By default, it will render on both client and server. |
127
127
  | `priority` | `number` | `false` | Priority of the component, if multiple components have the same name, the one with the highest priority will be used. |
128
+
129
+ ### Examples
130
+
131
+ If you want to auto-import a component from an npm package, and the component is a named export (rather than the default), you can use the `export` option to specify it.
132
+
133
+ ```ts
134
+ import { addComponent, defineNuxtModule } from '@nuxt/kit'
135
+
136
+ export default defineNuxtModule({
137
+ setup () {
138
+ // import { MyComponent as MyAutoImportedComponent } from 'my-npm-package'
139
+ addComponent({
140
+ name: 'MyAutoImportedComponent',
141
+ export: 'MyComponent',
142
+ filePath: 'my-npm-package',
143
+ })
144
+ },
145
+ })
146
+ ```