Skip to content

Commit

Permalink
refactor: move propsDestructure & customElement to features
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jun 18, 2024
1 parent 8e79acc commit 065855f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
35 changes: 25 additions & 10 deletions packages/plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface Options {
| 'genDefaultAs'
| 'customElement'
| 'defineModel'
| 'propsDestructure'
>
> & {
/**
Expand Down Expand Up @@ -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)[]

Expand All @@ -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)[]
}
}

Expand Down Expand Up @@ -142,11 +155,13 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin<Api> {
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',
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-vue/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function resolveScript(
? scriptIdentifier
: undefined,
customElement,
propsDestructure: options.features?.propsDestructure,
})

if (!options.isProduction && resolved?.deps) {
Expand Down

0 comments on commit 065855f

Please sign in to comment.