Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add defineModel and propsDestructure options #173

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/plugin-vue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ export interface Options {
*/
reactivityTransform?: boolean | string | RegExp | (string | RegExp)[]

/**
* Enable `defineModel` macro (experimental).
* https://github.com/vuejs/rfcs/discussions/503
* @default false
*/
defineModel?: boolean

/**
* Enable reactive props destructure (experimental).
* https://github.com/vuejs/rfcs/discussions/502
* @default false
*/
propsDestructure?: boolean

/**
* Use custom compiler-sfc instance. Can be used to force a specific version.
*/
Expand Down
14 changes: 14 additions & 0 deletions packages/plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ export interface Options {
*/
reactivityTransform?: boolean | string | RegExp | (string | RegExp)[]
so1ve marked this conversation as resolved.
Show resolved Hide resolved

/**
* Enable `defineModel` macro (experimental).
* https://github.com/vuejs/rfcs/discussions/503
* @default false
*/
defineModel?: boolean

/**
* Enable reactive props destructure (experimental).
* https://github.com/vuejs/rfcs/discussions/502
* @default false
*/
propsDestructure?: boolean

/**
* Use custom compiler-sfc instance. Can be used to force a specific version.
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-vue/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export function resolveScript(
isProd: options.isProduction,
inlineTemplate: isUseInlineTemplate(descriptor, !options.devServer),
reactivityTransform: options.reactivityTransform !== false,
defineModel: options.defineModel,
propsDestructure: options.propsDestructure,
templateOptions: resolveTemplateCompilerOptions(descriptor, options, ssr),
sourceMap: options.sourceMap,
genDefaultAs: canInlineMain(descriptor, options)
Expand Down
2 changes: 2 additions & 0 deletions playground/vue/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<AsyncComponent />
</Suspense>
<ReactivityTransform :foo="time" />
<PropDestructure :bar="time" />
<SetupImportTemplate />
<WorkerTest />
<Url />
Expand All @@ -45,6 +46,7 @@ import ScanDep from './ScanDep.vue'
import TsImport from './TsImport.vue'
import AsyncComponent from './AsyncComponent.vue'
import ReactivityTransform from './ReactivityTransform.vue'
import PropDestructure from './PropDestructure.vue'
import SetupImportTemplate from './setup-import-template/SetupImportTemplate.vue'
import WorkerTest from './worker.vue'
import { ref } from 'vue'
Expand Down
8 changes: 8 additions & 0 deletions playground/vue/PropDestructure.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script setup>
const { bar: baz } = defineProps(['foo'])
</script>

<template>
<h2>Prop Destructure</h2>
<p>Prop bar: {{ baz }}</p>
</template>
2 changes: 2 additions & 0 deletions playground/vue/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export default defineConfig({
plugins: [
vuePlugin({
reactivityTransform: true,
defineModel: true,
propsDestructure: true,
}),
splitVendorChunkPlugin(),
vueI18nPlugin,
Expand Down