From 065855f909a9c38d1c2d14ef198b15f84eabc5c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Tue, 18 Jun 2024 16:26:59 +0800 Subject: [PATCH] refactor: move `propsDestructure` & `customElement` to features --- packages/plugin-vue/src/index.ts | 35 ++++++++++++++++++++++--------- packages/plugin-vue/src/script.ts | 1 + 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/packages/plugin-vue/src/index.ts b/packages/plugin-vue/src/index.ts index 6392d14d..d49e904a 100644 --- a/packages/plugin-vue/src/index.ts +++ b/packages/plugin-vue/src/index.ts @@ -50,6 +50,7 @@ export interface Options { | 'genDefaultAs' | 'customElement' | 'defineModel' + | 'propsDestructure' > > & { /** @@ -91,12 +92,9 @@ export interface Options { | 'preprocessOptions' > > + /** - * Transform Vue SFCs into custom elements. - * - `true`: all `*.vue` imports are converted into custom elements - * - `string | RegExp`: matched files are converted into custom elements - * - * @default /\.ce\.vue$/ + * @deprecated moved to `features.customElement`. */ customElement?: boolean | string | RegExp | (string | RegExp)[] @@ -109,6 +107,21 @@ export interface Options { optionsAPI?: boolean prodDevtools?: boolean prodHydrationMismatchDetails?: boolean + /** + * Enable reactive destructure for `defineProps`. + * - Available in Vue 3.4 and later. + * - Defaults to true in Vue 3.5+ + * - Defaults to false in Vue 3.4 (**experimental**) + */ + propsDestructure?: boolean + /** + * Transform Vue SFCs into custom elements. + * - `true`: all `*.vue` imports are converted into custom elements + * - `string | RegExp`: matched files are converted into custom elements + * + * @default /\.ce\.vue$/ + */ + customElement?: boolean | string | RegExp | (string | RegExp)[] } } @@ -142,11 +155,13 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { const filter = computed(() => createFilter(options.value.include, options.value.exclude), ) - const customElementFilter = computed(() => - typeof options.value.customElement === 'boolean' - ? () => options.value.customElement as boolean - : createFilter(options.value.customElement), - ) + const customElementFilter = computed(() => { + const customElement = + options.value.features?.customElement || options.value.customElement + return typeof customElement === 'boolean' + ? () => customElement + : createFilter(customElement) + }) return { name: 'vite:vue', diff --git a/packages/plugin-vue/src/script.ts b/packages/plugin-vue/src/script.ts index 1583c03a..e0e821c3 100644 --- a/packages/plugin-vue/src/script.ts +++ b/packages/plugin-vue/src/script.ts @@ -77,6 +77,7 @@ export function resolveScript( ? scriptIdentifier : undefined, customElement, + propsDestructure: options.features?.propsDestructure, }) if (!options.isProduction && resolved?.deps) {