@@ -54,6 +54,7 @@ export interface Options {
54
54
| 'genDefaultAs'
55
55
| 'customElement'
56
56
| 'defineModel'
57
+ | 'propsDestructure'
57
58
>
58
59
> & {
59
60
/**
@@ -97,11 +98,7 @@ export interface Options {
97
98
>
98
99
99
100
/**
100
- * Transform Vue SFCs into custom elements.
101
- * - `true`: all `*.vue` imports are converted into custom elements
102
- * - `string | RegExp`: matched files are converted into custom elements
103
- *
104
- * @default /\.ce\.vue$/
101
+ * @deprecated moved to `features.customElement`.
105
102
*/
106
103
customElement ?: boolean | string | RegExp | ( string | RegExp ) [ ]
107
104
@@ -114,11 +111,32 @@ export interface Options {
114
111
* @default true
115
112
*/
116
113
inlineTemplate ?: boolean
114
+
115
+ features ?: {
116
+ optionsAPI ?: boolean
117
+ prodDevtools ?: boolean
118
+ prodHydrationMismatchDetails ?: boolean
119
+ /**
120
+ * Enable reactive destructure for `defineProps`.
121
+ * - Available in Vue 3.4 and later.
122
+ * - Defaults to true in Vue 3.5+
123
+ * - Defaults to false in Vue 3.4 (**experimental**)
124
+ */
125
+ propsDestructure ?: boolean
126
+ /**
127
+ * Transform Vue SFCs into custom elements.
128
+ * - `true`: all `*.vue` imports are converted into custom elements
129
+ * - `string | RegExp`: matched files are converted into custom elements
130
+ *
131
+ * @default /\.ce\.vue$/
132
+ */
133
+ customElement ?: boolean | string | RegExp | ( string | RegExp ) [ ]
134
+ }
117
135
}
118
136
119
137
export type Context = UnpluginContext & UnpluginContextMeta
120
138
121
- export type ResolvedOptions = Options &
139
+ export type ResolvedOptions = Omit < Options , 'customElement' > &
122
140
Required <
123
141
Pick <
124
142
Options ,
@@ -127,7 +145,6 @@ export type ResolvedOptions = Options &
127
145
| 'ssr'
128
146
| 'sourceMap'
129
147
| 'root'
130
- | 'customElement'
131
148
| 'compiler'
132
149
| 'inlineTemplate'
133
150
>
@@ -136,6 +153,7 @@ export type ResolvedOptions = Options &
136
153
devServer ?: ViteDevServer
137
154
devToolsEnabled ?: boolean
138
155
cssDevSourcemap : boolean
156
+ features : NonNullable < Options [ 'features' ] >
139
157
}
140
158
141
159
function resolveOptions ( rawOptions : Options ) : ResolvedOptions {
@@ -149,11 +167,20 @@ function resolveOptions(rawOptions: Options): ResolvedOptions {
149
167
ssr : rawOptions . ssr ?? false ,
150
168
sourceMap : rawOptions . sourceMap ?? true ,
151
169
root,
152
- customElement : rawOptions . customElement ?? / \. c e \. v u e $ / ,
153
170
compiler : rawOptions . compiler as any , // to be set in buildStart
154
171
devToolsEnabled : ! isProduction ,
155
172
cssDevSourcemap : false ,
156
173
inlineTemplate : rawOptions . inlineTemplate ?? true ,
174
+ features : {
175
+ optionsAPI : true ,
176
+ prodDevtools : false ,
177
+ prodHydrationMismatchDetails : false ,
178
+ propsDestructure : false ,
179
+ ...rawOptions . features ,
180
+ customElement :
181
+ ( rawOptions . features ?. customElement || rawOptions . customElement ) ??
182
+ / \. c e \. v u e $ / ,
183
+ } ,
157
184
}
158
185
}
159
186
@@ -165,11 +192,12 @@ export const plugin = createUnplugin<Options | undefined, false>(
165
192
createFilter ( options . value . include , options . value . exclude ) ,
166
193
)
167
194
168
- const customElementFilter = computed ( ( ) =>
169
- typeof options . value . customElement === 'boolean'
170
- ? ( ) => options . value . customElement as boolean
171
- : createFilter ( options . value . customElement ) ,
172
- )
195
+ const customElementFilter = computed ( ( ) => {
196
+ const customElement = options . value . features . customElement
197
+ return typeof customElement === 'boolean'
198
+ ? ( ) => customElement as boolean
199
+ : createFilter ( customElement )
200
+ } )
173
201
174
202
const api = {
175
203
get options ( ) {
@@ -208,11 +236,18 @@ export const plugin = createUnplugin<Options | undefined, false>(
208
236
dedupe : config . build ?. ssr ? [ ] : [ 'vue' ] ,
209
237
} ,
210
238
define : {
211
- __VUE_OPTIONS_API__ : config . define ?. __VUE_OPTIONS_API__ ?? true ,
239
+ __VUE_OPTIONS_API__ :
240
+ ( options . value . features . optionsAPI ||
241
+ config . define ?. __VUE_OPTIONS_API__ ) ??
242
+ true ,
212
243
__VUE_PROD_DEVTOOLS__ :
213
- config . define ?. __VUE_PROD_DEVTOOLS__ ?? false ,
244
+ ( options . value . features . prodDevtools ||
245
+ config . define ?. __VUE_PROD_DEVTOOLS__ ) ??
246
+ false ,
214
247
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__ :
215
- config . define ?. __VUE_PROD_HYDRATION_MISMATCH_DETAILS__ ?? false ,
248
+ ( options . value . features . prodHydrationMismatchDetails ||
249
+ config . define ?. __VUE_PROD_HYDRATION_MISMATCH_DETAILS__ ) ??
250
+ false ,
216
251
} ,
217
252
ssr : {
218
253
// @ts -ignore -- config.legacy.buildSsrCjsExternalHeuristics will be removed in Vite 5
@@ -232,8 +267,11 @@ export const plugin = createUnplugin<Options | undefined, false>(
232
267
cssDevSourcemap : config . css ?. devSourcemap ?? false ,
233
268
isProduction : config . isProduction ,
234
269
compiler : options . value . compiler || resolveCompiler ( config . root ) ,
235
- devToolsEnabled :
236
- ! ! config . define ! . __VUE_PROD_DEVTOOLS__ || ! config . isProduction ,
270
+ devToolsEnabled : ! ! (
271
+ options . value . features . prodDevtools ||
272
+ config . define ! . __VUE_PROD_DEVTOOLS__ ||
273
+ ! config . isProduction
274
+ ) ,
237
275
}
238
276
} ,
239
277
0 commit comments