0
# Configuration
1
2
Configuration system for unplugin-vue-macros with comprehensive options for all macro features.
3
4
## Capabilities
5
6
### Configuration Definition
7
8
Define configuration for Vue Macros with full type safety.
9
10
```typescript { .api }
11
/**
12
* Define configuration for Vue Macros
13
* @param options - Configuration options
14
* @returns Configuration object
15
*/
16
function defineConfig(options: Options): Options;
17
```
18
19
**Usage Examples:**
20
21
```typescript
22
import { defineConfig } from "unplugin-vue-macros";
23
24
export default defineConfig({
25
// Enable/disable specific macros
26
defineOptions: true,
27
defineModels: true,
28
chainCall: false,
29
30
// Configure plugins
31
plugins: {
32
vue: vue(),
33
vueJsx: vueJsx(),
34
},
35
36
// Advanced configuration
37
reactivityTransform: {
38
include: ["**/*.vue", "**/*.ts"],
39
exclude: ["node_modules/**"],
40
},
41
});
42
```
43
44
### Options Resolution
45
46
Resolve configuration options with defaults and Vue version detection.
47
48
```typescript { .api }
49
/**
50
* Resolve configuration options with defaults
51
* @param options - User configuration options
52
* @param cwd - Current working directory
53
* @returns Resolved configuration
54
*/
55
function resolveOptions(options?: Options, cwd?: string): OptionsResolved;
56
```
57
58
### Core Configuration Interface
59
60
Main configuration interface with all macro options.
61
62
```typescript { .api }
63
interface Options extends OptionsCommon {
64
// Props & Models Macros
65
/** @see https://vue-macros.dev/macros/chain-call.html @default true */
66
chainCall?: boolean | OptionsChainCall;
67
/** @see https://vue-macros.dev/macros/define-props.html @default true */
68
defineProps?: boolean | OptionsDefineProps;
69
/** @see https://vue-macros.dev/macros/define-props-refs.html @default true */
70
definePropsRefs?: boolean | OptionsDefinePropsRefs;
71
/** @see https://vue-macros.dev/macros/define-models.html @default true */
72
defineModels?: boolean | OptionsDefineModels;
73
/** @see https://vue-macros.dev/macros/define-prop.html @default true */
74
defineProp?: boolean | OptionsDefineProp;
75
76
// Component Options Macros
77
/** @see https://vue-macros.dev/macros/define-options.html @default vueVersion < 3.3 */
78
defineOptions?: boolean | OptionsDefineOptions;
79
/** @see https://vue-macros.dev/macros/define-slots.html @default vueVersion < 3.3 */
80
defineSlots?: boolean | OptionsDefineSlots;
81
/** @see https://vue-macros.dev/macros/define-emit.html @default true */
82
defineEmit?: boolean | OptionsDefineEmit;
83
/** @see https://vue-macros.dev/macros/define-render.html @default true */
84
defineRender?: boolean | OptionsDefineRender;
85
86
// Advanced Features
87
/** @see https://vue-macros.dev/features/better-define.html @default true */
88
betterDefine?: boolean | OptionsBetterDefine;
89
/** @see https://vue-macros.dev/features/reactivity-transform.html @default true */
90
reactivityTransform?: boolean | OptionsReactivityTransform;
91
/** @see https://vue-macros.dev/macros/setup-component.html @default true */
92
setupComponent?: boolean | OptionsSetupComponent;
93
/** @see https://vue-macros.dev/macros/setup-sfc.html @default false */
94
setupSFC?: boolean | OptionsSetupSFC;
95
/** @default false */
96
setupBlock?: boolean | OptionsSetupBlock;
97
98
// Syntax Sugar
99
/** @see https://vue-macros.dev/macros/short-emits.html @default vueVersion < 3.3 */
100
shortEmits?: boolean | OptionsShortEmits;
101
/** @see https://vue-macros.dev/macros/short-vmodel.html @default true */
102
shortVmodel?: boolean | OptionsShortVmodel;
103
/** @see https://vue-macros.dev/features/short-bind.html @default vueVersion < 3.4 */
104
shortBind?: boolean | OptionsShortBind;
105
/** @see https://vue-macros.dev/features/boolean-prop.html @default false */
106
booleanProp?: boolean | OptionsBooleanProp;
107
108
// Export Features
109
/** @see https://vue-macros.dev/features/export-expose.html @default false */
110
exportExpose?: boolean | OptionsExportExpose;
111
/** @see https://vue-macros.dev/features/export-props.html @default false */
112
exportProps?: boolean | OptionsExportProps;
113
/** @see https://vue-macros.dev/features/export-render.html @default false */
114
exportRender?: boolean | OptionsExportRender;
115
116
// Optimization
117
/** @see https://vue-macros.dev/features/hoist-static.html @default true */
118
hoistStatic?: boolean | OptionsHoistStatic;
119
120
// JSX Features
121
/** @see https://vue-macros.dev/features/jsx-directive.html @default true */
122
jsxDirective?: boolean | OptionsJsxDirective;
123
/** @see https://vue-macros.dev/features/jsx-ref.html @default false */
124
jsxRef?: FilterOptions & { alias?: string[] };
125
126
// Language Features
127
/** @see https://vue-macros.dev/features/script-lang.html @default false */
128
scriptLang?: boolean | OptionsScriptLang;
129
130
// Styling
131
/** @see https://vue-macros.dev/macros/define-stylex.html @default false */
132
defineStyleX?: boolean | OptionsDefineStyleX;
133
134
// Templates
135
/** @see https://vue-macros.dev/features/named-template.html @default false @deprecated */
136
namedTemplate?: boolean | OptionsNamedTemplate;
137
138
// Volar Integration
139
/** @see https://vue-macros.dev/volar/define-generic.html @default true */
140
defineGeneric?: FilterOptions;
141
/** @see https://vue-macros.dev/volar/script-sfc.html @default false */
142
scriptSFC?: FilterOptions;
143
/** @see https://vue-macros.dev/volar/setup-jsdoc.html @default true */
144
setupJsdoc?: FilterOptions;
145
}
146
147
interface OptionsCommon extends Omit<BaseOptions, keyof FilterOptions> {
148
/** Root directory for resolving files */
149
root?: string;
150
/** Plugin instances for integration */
151
plugins?: {
152
vue?: any;
153
vueJsx?: any;
154
vueRouter?: any;
155
};
156
/** @internal Nuxt context information */
157
nuxtContext?: {
158
isClient?: boolean;
159
};
160
}
161
162
// Base options from @vue-macros/common
163
interface BaseOptions {
164
/** Vue version override */
165
version?: string;
166
/** Enable production optimizations */
167
isProduction?: boolean;
168
}
169
170
// Filter options for file targeting
171
interface FilterOptions {
172
/** File inclusion patterns */
173
include?: string | RegExp | (string | RegExp)[];
174
/** File exclusion patterns */
175
exclude?: string | RegExp | (string | RegExp)[];
176
}
177
```
178
179
### Resolved Configuration
180
181
Type for fully resolved configuration with all defaults applied.
182
183
```typescript { .api }
184
type OptionsResolved = Required<OptionsCommon> & {
185
[K in keyof FeatureOptionsMap]: false | FeatureOptionsMap[K];
186
};
187
188
// Feature mapping for all macro options
189
interface FeatureOptionsMap {
190
betterDefine: OptionsBetterDefine;
191
booleanProp: OptionsBooleanProp;
192
chainCall: OptionsChainCall;
193
defineEmit: OptionsDefineEmit;
194
defineGeneric: FilterOptions;
195
defineModels: OptionsDefineModels;
196
defineOptions: OptionsDefineOptions;
197
defineProp: OptionsDefineProp;
198
defineProps: OptionsDefineProps;
199
definePropsRefs: OptionsDefinePropsRefs;
200
defineRender: OptionsDefineRender;
201
defineSlots: OptionsDefineSlots;
202
defineStyleX: OptionsDefineStyleX;
203
exportExpose: OptionsExportExpose;
204
exportProps: OptionsExportProps;
205
exportRender: OptionsExportRender;
206
hoistStatic: OptionsHoistStatic;
207
jsxDirective: OptionsJsxDirective;
208
jsxRef: FilterOptions & { alias?: string[] };
209
namedTemplate: OptionsNamedTemplate;
210
reactivityTransform: OptionsReactivityTransform;
211
scriptLang: OptionsScriptLang;
212
scriptSFC: FilterOptions;
213
setupBlock: OptionsSetupBlock;
214
setupComponent: OptionsSetupComponent;
215
setupJsdoc: FilterOptions;
216
setupSFC: OptionsSetupSFC;
217
shortBind: OptionsShortBind;
218
shortEmits: OptionsShortEmits;
219
shortVmodel: OptionsShortVmodel;
220
}
221
222
type FeatureName = keyof FeatureOptionsMap;
223
type FeatureOptions = FeatureOptionsMap[FeatureName];
224
```
225
226
## Usage Examples
227
228
### Vite Configuration
229
230
```typescript
231
// vite.config.ts
232
import { defineConfig } from "vite";
233
import vue from "@vitejs/plugin-vue";
234
import VueMacros from "unplugin-vue-macros/vite";
235
236
export default defineConfig({
237
plugins: [
238
VueMacros({
239
plugins: {
240
vue: vue(),
241
},
242
// Customize macro options
243
defineOptions: true,
244
defineModels: true,
245
reactivityTransform: {
246
include: ["src/**/*.vue"],
247
},
248
}),
249
],
250
});
251
```
252
253
### Webpack Configuration
254
255
```javascript
256
// webpack.config.js
257
const VueMacros = require("unplugin-vue-macros/webpack");
258
259
module.exports = {
260
plugins: [
261
VueMacros({
262
defineOptions: true,
263
chainCall: false,
264
shortEmits: true,
265
}),
266
],
267
};
268
```
269
270
### Nuxt Configuration
271
272
```typescript
273
// nuxt.config.ts
274
export default defineNuxtConfig({
275
modules: [
276
["@vue-macros/nuxt", {
277
defineOptions: true,
278
defineModels: true,
279
betterDefine: false,
280
}],
281
],
282
});
283
```