@nuxt/docs 3.17.0 → 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.
- package/1.getting-started/07.routing.md +1 -1
- package/1.getting-started/18.upgrade.md +41 -0
- package/2.guide/1.concepts/1.auto-imports.md +1 -1
- package/2.guide/3.going-further/1.events.md +82 -0
- package/2.guide/3.going-further/2.hooks.md +1 -20
- package/3.api/5.kit/1.modules.md +105 -92
- package/3.api/5.kit/10.runtime-config.md +2 -0
- package/3.api/5.kit/10.templates.md +187 -163
- package/3.api/5.kit/11.nitro.md +206 -167
- package/3.api/5.kit/12.resolving.md +79 -133
- package/3.api/5.kit/13.logging.md +19 -29
- package/3.api/5.kit/14.builder.md +140 -373
- package/3.api/5.kit/2.programmatic.md +11 -64
- package/3.api/5.kit/3.compatibility.md +88 -135
- package/3.api/5.kit/4.autoimports.md +3 -3
- package/3.api/5.kit/5.components.md +22 -3
- package/3.api/5.kit/6.context.md +92 -48
- package/3.api/5.kit/7.pages.md +95 -197
- package/3.api/5.kit/8.layout.md +68 -49
- package/3.api/5.kit/9.plugins.md +140 -139
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Builder
|
|
3
|
-
description: Nuxt Kit provides a set of utilities to help you work with the builder. These functions allow you to extend the
|
|
3
|
+
description: Nuxt Kit provides a set of utilities to help you work with the builder. These functions allow you to extend the Vite and webpack configurations.
|
|
4
4
|
links:
|
|
5
5
|
- label: Source
|
|
6
6
|
icon: i-simple-icons-github
|
|
@@ -8,284 +8,170 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
Nuxt have builders based on [
|
|
11
|
+
Nuxt have builders based on [Vite](https://github.com/nuxt/nuxt/tree/main/packages/vite) and [webpack](https://github.com/nuxt/nuxt/tree/main/packages/webpack). You can extend the config passed to each one using `extendViteConfig` and `extendWebpackConfig` functions. You can also add additional plugins via `addVitePlugin`, `addWebpackPlugin` and `addBuildPlugin`.
|
|
12
12
|
|
|
13
|
-
## `
|
|
13
|
+
## `extendViteConfig`
|
|
14
14
|
|
|
15
|
-
Extends the
|
|
15
|
+
Extends the Vite configuration. Callback function can be called multiple times, when applying to both client and server builds.
|
|
16
16
|
|
|
17
|
-
###
|
|
17
|
+
### Usage
|
|
18
18
|
|
|
19
|
-
```ts
|
|
20
|
-
|
|
19
|
+
```ts twoslash
|
|
20
|
+
import { defineNuxtModule, extendViteConfig } from '@nuxt/kit'
|
|
21
21
|
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
22
|
+
export default defineNuxtModule({
|
|
23
|
+
setup () {
|
|
24
|
+
extendViteConfig((config) => {
|
|
25
|
+
config.optimizeDeps ||= {}
|
|
26
|
+
config.optimizeDeps.include ||= []
|
|
27
|
+
config.optimizeDeps.include.push('cross-fetch')
|
|
28
|
+
})
|
|
29
|
+
},
|
|
30
|
+
})
|
|
29
31
|
```
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
Checkout webpack website for more information about its configuration.
|
|
33
|
-
::
|
|
34
|
-
|
|
35
|
-
### Parameters
|
|
36
|
-
|
|
37
|
-
#### `callback`
|
|
38
|
-
|
|
39
|
-
**Type**: `(config: WebpackConfig) => void`
|
|
40
|
-
|
|
41
|
-
**Required**: `true`
|
|
42
|
-
|
|
43
|
-
A callback function that will be called with the webpack configuration object.
|
|
44
|
-
|
|
45
|
-
#### `options`
|
|
46
|
-
|
|
47
|
-
**Type**: `ExtendWebpackConfigOptions`
|
|
48
|
-
|
|
49
|
-
**Default**: `{}`
|
|
50
|
-
|
|
51
|
-
Options to pass to the callback function. This object can have the following properties:
|
|
52
|
-
|
|
53
|
-
- `dev` (optional)
|
|
54
|
-
|
|
55
|
-
**Type**: `boolean`
|
|
56
|
-
|
|
57
|
-
**Default**: `true`
|
|
58
|
-
|
|
59
|
-
If set to `true`, the callback function will be called when building in development mode.
|
|
60
|
-
|
|
61
|
-
- `build` (optional)
|
|
62
|
-
|
|
63
|
-
**Type**: `boolean`
|
|
64
|
-
|
|
65
|
-
**Default**: `true`
|
|
66
|
-
|
|
67
|
-
If set to `true`, the callback function will be called when building in production mode.
|
|
68
|
-
|
|
69
|
-
- `server` (optional)
|
|
70
|
-
|
|
71
|
-
**Type**: `boolean`
|
|
72
|
-
|
|
73
|
-
**Default**: `true`
|
|
33
|
+
### Type
|
|
74
34
|
|
|
75
|
-
|
|
35
|
+
```ts twoslash
|
|
36
|
+
// @errors: 2391
|
|
37
|
+
import type { UserConfig as ViteConfig } from 'vite'
|
|
38
|
+
import type { ExtendViteConfigOptions } from '@nuxt/kit'
|
|
39
|
+
// ---cut---
|
|
40
|
+
function extendViteConfig (callback: ((config: ViteConfig) => void), options?: ExtendViteConfigOptions): void
|
|
41
|
+
```
|
|
76
42
|
|
|
77
|
-
-
|
|
43
|
+
::read-more{to="https://vite.dev/config" target="_blank" icon="i-simple-icons-vite"}
|
|
44
|
+
Checkout Vite website for more information about its configuration.
|
|
45
|
+
::
|
|
78
46
|
|
|
79
|
-
|
|
47
|
+
### Parameters
|
|
80
48
|
|
|
81
|
-
|
|
49
|
+
**`callback`**: A callback function that will be called with the Vite configuration object.
|
|
82
50
|
|
|
83
|
-
|
|
51
|
+
**`options`**: Options to pass to the callback function. This object can have the following properties:
|
|
84
52
|
|
|
85
|
-
|
|
53
|
+
| Property | Type | Required | Description |
|
|
54
|
+
| --------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------ |
|
|
55
|
+
| `dev` | `boolean` | `false` | If set to `true`, the callback function will be called when building in development mode. |
|
|
56
|
+
| `build` | `boolean` | `false` | If set to `true`, the callback function will be called when building in production mode. |
|
|
57
|
+
| `server` | `boolean` | `false` | If set to `true`, the callback function will be called when building the server bundle. |
|
|
58
|
+
| `client` | `boolean` | `false` | If set to `true`, the callback function will be called when building the client bundle. |
|
|
59
|
+
| `prepend` | `boolean` | `false` | If set to `true`, the callback function will be prepended to the array with `unshift()` instead of `push()`. |
|
|
86
60
|
|
|
87
|
-
|
|
61
|
+
## `extendWebpackConfig`
|
|
88
62
|
|
|
89
|
-
|
|
63
|
+
Extends the webpack configuration. Callback function can be called multiple times, when applying to both client and server builds.
|
|
90
64
|
|
|
91
|
-
###
|
|
65
|
+
### Usage
|
|
92
66
|
|
|
93
|
-
```ts
|
|
67
|
+
```ts twoslash
|
|
94
68
|
import { defineNuxtModule, extendWebpackConfig } from '@nuxt/kit'
|
|
95
69
|
|
|
96
70
|
export default defineNuxtModule({
|
|
97
|
-
setup() {
|
|
71
|
+
setup () {
|
|
98
72
|
extendWebpackConfig((config) => {
|
|
99
|
-
config.module
|
|
73
|
+
config.module!.rules!.push({
|
|
100
74
|
test: /\.txt$/,
|
|
101
|
-
use: 'raw-loader'
|
|
75
|
+
use: 'raw-loader',
|
|
102
76
|
})
|
|
103
77
|
})
|
|
104
|
-
}
|
|
78
|
+
},
|
|
105
79
|
})
|
|
106
80
|
```
|
|
107
81
|
|
|
108
|
-
## `extendViteConfig`
|
|
109
|
-
|
|
110
|
-
Extends the Vite configuration. Callback function can be called multiple times, when applying to both client and server builds.
|
|
111
|
-
|
|
112
82
|
### Type
|
|
113
83
|
|
|
114
|
-
```ts
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
server?: boolean
|
|
121
|
-
client?: boolean
|
|
122
|
-
prepend?: boolean
|
|
123
|
-
}
|
|
84
|
+
```ts twoslash
|
|
85
|
+
// @errors: 2391
|
|
86
|
+
import type { Configuration as WebpackConfig } from 'webpack'
|
|
87
|
+
import type { ExtendWebpackConfigOptions } from '@nuxt/kit'
|
|
88
|
+
// ---cut---
|
|
89
|
+
function extendWebpackConfig (callback: ((config: WebpackConfig) => void), options?: ExtendWebpackConfigOptions): void
|
|
124
90
|
```
|
|
125
91
|
|
|
126
|
-
::read-more{to="https://
|
|
127
|
-
Checkout
|
|
92
|
+
::read-more{to="https://webpack.js.org/configuration" target="_blank" icon="i-simple-icons-webpack"}
|
|
93
|
+
Checkout webpack website for more information about its configuration.
|
|
128
94
|
::
|
|
129
95
|
|
|
130
96
|
### Parameters
|
|
131
97
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
**Type**: `(config: ViteConfig) => void`
|
|
135
|
-
|
|
136
|
-
**Required**: `true`
|
|
137
|
-
|
|
138
|
-
A callback function that will be called with the Vite configuration object.
|
|
139
|
-
|
|
140
|
-
#### `options`
|
|
141
|
-
|
|
142
|
-
**Type**: `ExtendViteConfigOptions`
|
|
143
|
-
|
|
144
|
-
**Default**: `{}`
|
|
145
|
-
|
|
146
|
-
Options to pass to the callback function. This object can have the following properties:
|
|
147
|
-
|
|
148
|
-
- `dev` (optional)
|
|
149
|
-
|
|
150
|
-
**Type**: `boolean`
|
|
151
|
-
|
|
152
|
-
**Default**: `true`
|
|
153
|
-
|
|
154
|
-
If set to `true`, the callback function will be called when building in development mode.
|
|
155
|
-
|
|
156
|
-
- `build` (optional)
|
|
157
|
-
|
|
158
|
-
**Type**: `boolean`
|
|
159
|
-
|
|
160
|
-
**Default**: `true`
|
|
161
|
-
|
|
162
|
-
If set to `true`, the callback function will be called when building in production mode.
|
|
163
|
-
|
|
164
|
-
- `server` (optional)
|
|
165
|
-
|
|
166
|
-
**Type**: `boolean`
|
|
167
|
-
|
|
168
|
-
**Default**: `true`
|
|
169
|
-
|
|
170
|
-
If set to `true`, the callback function will be called when building the server bundle.
|
|
171
|
-
|
|
172
|
-
- `client` (optional)
|
|
173
|
-
|
|
174
|
-
**Type**: `boolean`
|
|
98
|
+
**`callback`**: A callback function that will be called with the webpack configuration object.
|
|
175
99
|
|
|
176
|
-
|
|
100
|
+
**`options`**: Options to pass to the callback function. This object can have the following properties:
|
|
177
101
|
|
|
178
|
-
|
|
102
|
+
| Property | Type | Required | Description |
|
|
103
|
+
| --------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------ |
|
|
104
|
+
| `dev` | `boolean` | `false` | If set to `true`, the callback function will be called when building in development mode. |
|
|
105
|
+
| `build` | `boolean` | `false` | If set to `true`, the callback function will be called when building in production mode. |
|
|
106
|
+
| `server` | `boolean` | `false` | If set to `true`, the callback function will be called when building the server bundle. |
|
|
107
|
+
| `client` | `boolean` | `false` | If set to `true`, the callback function will be called when building the client bundle. |
|
|
108
|
+
| `prepend` | `boolean` | `false` | If set to `true`, the callback function will be prepended to the array with `unshift()` instead of `push()`. |
|
|
179
109
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
**Type**: `boolean`
|
|
110
|
+
## `addVitePlugin`
|
|
183
111
|
|
|
184
|
-
|
|
112
|
+
Append Vite plugin to the config.
|
|
185
113
|
|
|
186
|
-
###
|
|
114
|
+
### Usage
|
|
187
115
|
|
|
188
|
-
```ts
|
|
189
|
-
//
|
|
190
|
-
|
|
116
|
+
```ts twoslash
|
|
117
|
+
// @errors: 2307
|
|
118
|
+
// ---cut---
|
|
119
|
+
import { addVitePlugin, defineNuxtModule } from '@nuxt/kit'
|
|
120
|
+
import { svg4VuePlugin } from 'vite-plugin-svg4vue'
|
|
191
121
|
|
|
192
122
|
export default defineNuxtModule({
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
123
|
+
meta: {
|
|
124
|
+
name: 'nuxt-svg-icons',
|
|
125
|
+
configKey: 'nuxtSvgIcons',
|
|
126
|
+
},
|
|
127
|
+
defaults: {
|
|
128
|
+
svg4vue: {
|
|
129
|
+
assetsDirName: 'assets/icons',
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
setup (options) {
|
|
133
|
+
addVitePlugin(svg4VuePlugin(options.svg4vue))
|
|
134
|
+
},
|
|
200
135
|
})
|
|
201
136
|
```
|
|
202
137
|
|
|
203
|
-
## `addWebpackPlugin`
|
|
204
|
-
|
|
205
|
-
Append webpack plugin to the config.
|
|
206
|
-
|
|
207
138
|
### Type
|
|
208
139
|
|
|
209
|
-
```ts
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
type
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
dev?: boolean
|
|
216
|
-
build?: boolean
|
|
217
|
-
server?: boolean
|
|
218
|
-
client?: boolean
|
|
219
|
-
prepend?: boolean
|
|
220
|
-
}
|
|
140
|
+
```ts twoslash
|
|
141
|
+
// @errors: 2391
|
|
142
|
+
import type { Plugin as VitePlugin } from 'vite'
|
|
143
|
+
import type { ExtendViteConfigOptions } from '@nuxt/kit'
|
|
144
|
+
// ---cut---
|
|
145
|
+
function addVitePlugin (pluginOrGetter: VitePlugin | VitePlugin[] | (() => VitePlugin | VitePlugin[]), options?: ExtendViteConfigOptions): void
|
|
221
146
|
```
|
|
222
147
|
|
|
223
148
|
::tip
|
|
224
|
-
See [
|
|
149
|
+
See [Vite website](https://vite.dev/guide/api-plugin.html) for more information about Vite plugins. You can also use [this repository](https://github.com/vitejs/awesome-vite#plugins) to find a plugin that suits your needs.
|
|
225
150
|
::
|
|
226
151
|
|
|
227
152
|
### Parameters
|
|
228
153
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
**Type**: `PluginOrGetter`
|
|
232
|
-
|
|
233
|
-
**Required**: `true`
|
|
234
|
-
|
|
235
|
-
A webpack plugin instance or an array of webpack plugin instances. If a function is provided, it must return a webpack plugin instance or an array of webpack plugin instances.
|
|
236
|
-
|
|
237
|
-
#### `options`
|
|
238
|
-
|
|
239
|
-
**Type**: `ExtendWebpackConfigOptions`
|
|
240
|
-
|
|
241
|
-
**Default**: `{}`
|
|
242
|
-
|
|
243
|
-
Options to pass to the callback function. This object can have the following properties:
|
|
244
|
-
|
|
245
|
-
- `dev` (optional)
|
|
246
|
-
|
|
247
|
-
**Type**: `boolean`
|
|
248
|
-
|
|
249
|
-
**Default**: `true`
|
|
250
|
-
|
|
251
|
-
If set to `true`, the callback function will be called when building in development mode.
|
|
154
|
+
**`pluginOrGetter`**: A Vite plugin instance or an array of Vite plugin instances. If a function is provided, it must return a Vite plugin instance or an array of Vite plugin instances.
|
|
252
155
|
|
|
253
|
-
|
|
156
|
+
**`options`**: Options to pass to the callback function. This object can have the following properties:
|
|
254
157
|
|
|
255
|
-
|
|
158
|
+
| Property | Type | Required | Description |
|
|
159
|
+
| --------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------ |
|
|
160
|
+
| `dev` | `boolean` | `false` | If set to `true`, the callback function will be called when building in development mode. |
|
|
161
|
+
| `build` | `boolean` | `false` | If set to `true`, the callback function will be called when building in production mode. |
|
|
162
|
+
| `server` | `boolean` | `false` | If set to `true`, the callback function will be called when building the server bundle. |
|
|
163
|
+
| `client` | `boolean` | `false` | If set to `true`, the callback function will be called when building the client bundle. |
|
|
164
|
+
| `prepend` | `boolean` | `false` | If set to `true`, the callback function will be prepended to the array with `unshift()` instead of `push()`. |
|
|
256
165
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
If set to `true`, the callback function will be called when building in production mode.
|
|
260
|
-
|
|
261
|
-
- `server` (optional)
|
|
262
|
-
|
|
263
|
-
**Type**: `boolean`
|
|
264
|
-
|
|
265
|
-
**Default**: `true`
|
|
266
|
-
|
|
267
|
-
If set to `true`, the callback function will be called when building the server bundle.
|
|
268
|
-
|
|
269
|
-
- `client` (optional)
|
|
270
|
-
|
|
271
|
-
**Type**: `boolean`
|
|
272
|
-
|
|
273
|
-
**Default**: `true`
|
|
274
|
-
|
|
275
|
-
If set to `true`, the callback function will be called when building the client bundle.
|
|
276
|
-
|
|
277
|
-
- `prepend` (optional)
|
|
278
|
-
|
|
279
|
-
**Type**: `boolean`
|
|
166
|
+
## `addWebpackPlugin`
|
|
280
167
|
|
|
281
|
-
|
|
168
|
+
Append webpack plugin to the config.
|
|
282
169
|
|
|
283
|
-
###
|
|
170
|
+
### Usage
|
|
284
171
|
|
|
285
172
|
```ts
|
|
286
|
-
// https://github.com/nuxt-modules/eslint
|
|
287
173
|
import EslintWebpackPlugin from 'eslint-webpack-plugin'
|
|
288
|
-
import {
|
|
174
|
+
import { addWebpackPlugin, defineNuxtModule } from '@nuxt/kit'
|
|
289
175
|
|
|
290
176
|
export default defineNuxtModule({
|
|
291
177
|
meta: {
|
|
@@ -296,196 +182,77 @@ export default defineNuxtModule({
|
|
|
296
182
|
include: [`${nuxt.options.srcDir}/**/*.{js,jsx,ts,tsx,vue}`],
|
|
297
183
|
lintOnStart: true,
|
|
298
184
|
}),
|
|
299
|
-
setup(options, nuxt) {
|
|
185
|
+
setup (options, nuxt) {
|
|
300
186
|
const webpackOptions = {
|
|
301
187
|
...options,
|
|
302
188
|
context: nuxt.options.srcDir,
|
|
303
189
|
files: options.include,
|
|
304
|
-
lintDirtyModulesOnly: !options.lintOnStart
|
|
190
|
+
lintDirtyModulesOnly: !options.lintOnStart,
|
|
305
191
|
}
|
|
306
192
|
addWebpackPlugin(new EslintWebpackPlugin(webpackOptions), { server: false })
|
|
307
|
-
}
|
|
193
|
+
},
|
|
308
194
|
})
|
|
309
195
|
```
|
|
310
196
|
|
|
311
|
-
## `addVitePlugin`
|
|
312
|
-
|
|
313
|
-
Append Vite plugin to the config.
|
|
314
|
-
|
|
315
197
|
### Type
|
|
316
198
|
|
|
317
|
-
```ts
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
type
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
dev?: boolean
|
|
324
|
-
build?: boolean
|
|
325
|
-
server?: boolean
|
|
326
|
-
client?: boolean
|
|
327
|
-
prepend?: boolean
|
|
328
|
-
}
|
|
199
|
+
```ts twoslash
|
|
200
|
+
// @errors: 2391
|
|
201
|
+
import type { WebpackPluginInstance } from 'webpack'
|
|
202
|
+
import type { ExtendWebpackConfigOptions } from '@nuxt/kit'
|
|
203
|
+
// ---cut---
|
|
204
|
+
function addWebpackPlugin (pluginOrGetter: WebpackPluginInstance | WebpackPluginInstance[] | (() => WebpackPluginInstance | WebpackPluginInstance[]), options?: ExtendWebpackConfigOptions): void
|
|
329
205
|
```
|
|
330
206
|
|
|
331
207
|
::tip
|
|
332
|
-
See [
|
|
208
|
+
See [webpack website](https://webpack.js.org/concepts/plugins) for more information about webpack plugins. You can also use [this collection](https://webpack.js.org/awesome-webpack/#webpack-plugins) to find a plugin that suits your needs.
|
|
333
209
|
::
|
|
334
210
|
|
|
335
211
|
### Parameters
|
|
336
212
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
**Type**: `PluginOrGetter`
|
|
340
|
-
|
|
341
|
-
**Required**: `true`
|
|
342
|
-
|
|
343
|
-
A Vite plugin instance or an array of Vite plugin instances. If a function is provided, it must return a Vite plugin instance or an array of Vite plugin instances.
|
|
344
|
-
|
|
345
|
-
#### `options`
|
|
346
|
-
|
|
347
|
-
**Type**: `ExtendViteConfigOptions`
|
|
348
|
-
|
|
349
|
-
**Default**: `{}`
|
|
350
|
-
|
|
351
|
-
Options to pass to the callback function. This object can have the following properties:
|
|
352
|
-
|
|
353
|
-
- `dev` (optional)
|
|
354
|
-
|
|
355
|
-
**Type**: `boolean`
|
|
356
|
-
|
|
357
|
-
**Default**: `true`
|
|
358
|
-
|
|
359
|
-
If set to `true`, the callback function will be called when building in development mode.
|
|
360
|
-
|
|
361
|
-
- `build` (optional)
|
|
362
|
-
|
|
363
|
-
**Type**: `boolean`
|
|
364
|
-
|
|
365
|
-
**Default**: `true`
|
|
366
|
-
|
|
367
|
-
If set to `true`, the callback function will be called when building in production mode.
|
|
368
|
-
|
|
369
|
-
- `server` (optional)
|
|
370
|
-
|
|
371
|
-
**Type**: `boolean`
|
|
372
|
-
|
|
373
|
-
**Default**: `true`
|
|
213
|
+
**`pluginOrGetter`**: A webpack plugin instance or an array of webpack plugin instances. If a function is provided, it must return a webpack plugin instance or an array of webpack plugin instances.
|
|
374
214
|
|
|
375
|
-
|
|
215
|
+
**`options`**: Options to pass to the callback function. This object can have the following properties:
|
|
376
216
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
If set to `true`, the callback function will be
|
|
384
|
-
|
|
385
|
-
- `prepend` (optional)
|
|
386
|
-
|
|
387
|
-
**Type**: `boolean`
|
|
388
|
-
|
|
389
|
-
If set to `true`, the callback function will be prepended to the array with `unshift()` instead of `push()`.
|
|
390
|
-
|
|
391
|
-
### Examples
|
|
392
|
-
|
|
393
|
-
```ts
|
|
394
|
-
// https://github.com/yisibell/nuxt-svg-icons
|
|
395
|
-
import { defineNuxtModule, addVitePlugin } from '@nuxt/kit'
|
|
396
|
-
import { svg4VuePlugin } from 'vite-plugin-svg4vue'
|
|
397
|
-
|
|
398
|
-
export default defineNuxtModule({
|
|
399
|
-
meta: {
|
|
400
|
-
name: 'nuxt-svg-icons',
|
|
401
|
-
configKey: 'nuxtSvgIcons',
|
|
402
|
-
},
|
|
403
|
-
defaults: {
|
|
404
|
-
svg4vue: {
|
|
405
|
-
assetsDirName: 'assets/icons',
|
|
406
|
-
},
|
|
407
|
-
},
|
|
408
|
-
setup(options) {
|
|
409
|
-
addVitePlugin(svg4VuePlugin(options.svg4vue))
|
|
410
|
-
},
|
|
411
|
-
})
|
|
412
|
-
```
|
|
217
|
+
| Property | Type | Required | Description |
|
|
218
|
+
| --------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------ |
|
|
219
|
+
| `dev` | `boolean` | `false` | If set to `true`, the callback function will be called when building in development mode. |
|
|
220
|
+
| `build` | `boolean` | `false` | If set to `true`, the callback function will be called when building in production mode. |
|
|
221
|
+
| `server` | `boolean` | `false` | If set to `true`, the callback function will be called when building the server bundle. |
|
|
222
|
+
| `client` | `boolean` | `false` | If set to `true`, the callback function will be called when building the client bundle. |
|
|
223
|
+
| `prepend` | `boolean` | `false` | If set to `true`, the callback function will be prepended to the array with `unshift()` instead of `push()`. |
|
|
413
224
|
|
|
414
225
|
## `addBuildPlugin`
|
|
415
226
|
|
|
416
|
-
Builder-agnostic version of `
|
|
227
|
+
Builder-agnostic version of `addVitePlugin` and `addWebpackPlugin`. It will add the plugin to both Vite and webpack configurations if they are present.
|
|
417
228
|
|
|
418
229
|
### Type
|
|
419
230
|
|
|
420
|
-
```ts
|
|
421
|
-
|
|
422
|
-
|
|
231
|
+
```ts twoslash
|
|
232
|
+
// @errors: 2391
|
|
233
|
+
import type { ExtendConfigOptions } from '@nuxt/kit'
|
|
234
|
+
import type { Plugin as VitePlugin } from 'vite'
|
|
235
|
+
import type { WebpackPluginInstance } from 'webpack'
|
|
236
|
+
import type { RspackPluginInstance } from '@rspack/core'
|
|
423
237
|
interface AddBuildPluginFactory {
|
|
424
238
|
vite?: () => VitePlugin | VitePlugin[]
|
|
425
239
|
webpack?: () => WebpackPluginInstance | WebpackPluginInstance[]
|
|
240
|
+
rspack?: () => RspackPluginInstance | RspackPluginInstance[]
|
|
426
241
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
dev?: boolean
|
|
430
|
-
build?: boolean
|
|
431
|
-
server?: boolean
|
|
432
|
-
client?: boolean
|
|
433
|
-
prepend?: boolean
|
|
434
|
-
}
|
|
242
|
+
// ---cut---
|
|
243
|
+
function addBuildPlugin (pluginFactory: AddBuildPluginFactory, options?: ExtendConfigOptions): void
|
|
435
244
|
```
|
|
436
245
|
|
|
437
246
|
### Parameters
|
|
438
247
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
**Type**: `AddBuildPluginFactory`
|
|
442
|
-
|
|
443
|
-
**Required**: `true`
|
|
444
|
-
|
|
445
|
-
A factory function that returns an object with `vite` and/or `webpack` properties. These properties must be functions that return a Vite plugin instance or an array of Vite plugin instances and/or a webpack plugin instance or an array of webpack plugin instances.
|
|
446
|
-
|
|
447
|
-
#### `options`
|
|
448
|
-
|
|
449
|
-
**Type**: `ExtendConfigOptions`
|
|
450
|
-
|
|
451
|
-
**Default**: `{}`
|
|
452
|
-
|
|
453
|
-
Options to pass to the callback function. This object can have the following properties:
|
|
454
|
-
|
|
455
|
-
- `dev` (optional)
|
|
456
|
-
|
|
457
|
-
**Type**: `boolean`
|
|
458
|
-
|
|
459
|
-
**Default**: `true`
|
|
460
|
-
|
|
461
|
-
If set to `true`, the callback function will be called when building in development mode.
|
|
462
|
-
|
|
463
|
-
- `build` (optional)
|
|
464
|
-
|
|
465
|
-
**Type**: `boolean`
|
|
466
|
-
|
|
467
|
-
**Default**: `true`
|
|
468
|
-
|
|
469
|
-
If set to `true`, the callback function will be called when building in production mode.
|
|
470
|
-
|
|
471
|
-
- `server` (optional)
|
|
472
|
-
|
|
473
|
-
**Type**: `boolean`
|
|
474
|
-
|
|
475
|
-
**Default**: `true`
|
|
476
|
-
|
|
477
|
-
If set to `true`, the callback function will be called when building the server bundle.
|
|
478
|
-
|
|
479
|
-
- `client` (optional)
|
|
480
|
-
|
|
481
|
-
**Type**: `boolean`
|
|
482
|
-
|
|
483
|
-
**Default**: `true`
|
|
484
|
-
|
|
485
|
-
If set to `true`, the callback function will be called when building the client bundle.
|
|
486
|
-
|
|
487
|
-
- `prepend` (optional)
|
|
248
|
+
**`pluginFactory`**: A factory function that returns an object with `vite` and/or `webpack` properties. These properties must be functions that return a Vite plugin instance or an array of Vite plugin instances and/or a webpack plugin instance or an array of webpack plugin instances.
|
|
488
249
|
|
|
489
|
-
|
|
250
|
+
**`options`**: Options to pass to the callback function. This object can have the following properties:
|
|
490
251
|
|
|
491
|
-
|
|
252
|
+
| Property | Type | Required | Description |
|
|
253
|
+
| --------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------ |
|
|
254
|
+
| `dev` | `boolean` | `false` | If set to `true`, the callback function will be called when building in development mode. |
|
|
255
|
+
| `build` | `boolean` | `false` | If set to `true`, the callback function will be called when building in production mode. |
|
|
256
|
+
| `server` | `boolean` | `false` | If set to `true`, the callback function will be called when building the server bundle. |
|
|
257
|
+
| `client` | `boolean` | `false` | If set to `true`, the callback function will be called when building the client bundle. |
|
|
258
|
+
| `prepend` | `boolean` | `false` | If set to `true`, the callback function will be prepended to the array with `unshift()` instead of `push()`. |
|