Skip to content

Commit 955d0fe

Browse files
committed
feat(plugin-vue): add reactivityTransform option.
Enabling this option will apply both ref transform and props destructure transform. BREAKING CHANGE: `refTransform` option has been replaced by `reactivityTransform` option. Now also requires vue@^3.2.25.
1 parent 5e60562 commit 955d0fe

File tree

7 files changed

+26
-17
lines changed

7 files changed

+26
-17
lines changed

packages/playground/vue/Main.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<Suspense>
1919
<AsyncComponent />
2020
</Suspense>
21-
<RefTransform />
21+
<ReactivityTransform :foo="time" />
2222
<SetupImportTemplate />
2323
</template>
2424

@@ -33,7 +33,7 @@ import SrcImport from './src-import/SrcImport.vue'
3333
import Slotted from './Slotted.vue'
3434
import ScanDep from './ScanDep.vue'
3535
import AsyncComponent from './AsyncComponent.vue'
36-
import RefTransform from './RefTransform.vue'
36+
import ReactivityTransform from './ReactivityTransform.vue'
3737
import SetupImportTemplate from './setup-import-template/SetupImportTemplate.vue'
3838
3939
import { ref } from 'vue'
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<script setup>
2+
const { foo: bar } = defineProps(['foo'])
3+
24
let a = $ref(0)
35
const inc = () => a++
46
</script>
57

68
<template>
7-
<h2>Ref Transform</h2>
9+
<h2>Reactivity Transform</h2>
10+
<p>Prop foo: {{ bar }}</p>
811
<button class="ref-transform" @click="inc">{{ a }}</button>
912
</template>

packages/playground/vue/vite.config.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import path from 'path'
21
import { defineConfig } from 'vite'
32
import vuePlugin from '@vitejs/plugin-vue'
43
import { vueI18nPlugin } from './CustomBlockPlugin'
@@ -11,7 +10,7 @@ export default defineConfig({
1110
},
1211
plugins: [
1312
vuePlugin({
14-
refTransform: true
13+
reactivityTransform: true
1514
}),
1615
vueI18nPlugin
1716
],

packages/plugin-vue/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-vue#readme",
3333
"peerDependencies": {
3434
"vite": "^2.5.10",
35-
"vue": "^3.2.13"
35+
"vue": "^3.2.25"
3636
},
3737
"devDependencies": {
3838
"@rollup/pluginutils": "^4.1.1",
@@ -42,6 +42,6 @@
4242
"rollup": "^2.59.0",
4343
"slash": "^4.0.0",
4444
"source-map": "^0.6.1",
45-
"vue": "^3.2.23"
45+
"vue": "^3.2.25"
4646
}
4747
}

packages/plugin-vue/src/index.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ export interface Options {
4242
customElement?: boolean | string | RegExp | (string | RegExp)[]
4343

4444
/**
45-
* Enable Vue ref transform (experimental).
46-
* https://github.com/vuejs/vue-next/tree/master/packages/ref-transform
45+
* Enable Vue reactivity transform (experimental).
46+
* https://github.com/vuejs/vue-next/tree/master/packages/reactivity-transform
4747
*
48-
* **requires Vue \>= 3.2.5**
48+
* **requires vue\@^3.2.25**
4949
*
5050
* - `true`: transform will be enabled for all vue,js(x),ts(x) files except
5151
* those inside node_modules
@@ -55,7 +55,12 @@ export interface Options {
5555
*
5656
* @default false
5757
*/
58-
refTransform?: boolean | string | RegExp | (string | RegExp)[]
58+
reactivityTransform?: boolean | string | RegExp | (string | RegExp)[]
59+
60+
/**
61+
* @deprecated use `reactivityTransform` instead.
62+
*/
63+
refTransform?: any
5964

6065
/**
6166
* @deprecated the plugin now auto-detects whether it's being invoked for ssr.
@@ -80,7 +85,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
8085
include = /\.vue$/,
8186
exclude,
8287
customElement = /\.ce\.vue$/,
83-
refTransform = false
88+
reactivityTransform = false
8489
} = rawOptions
8590

8691
const filter = createFilter(include, exclude)
@@ -91,19 +96,19 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
9196
: createFilter(customElement)
9297

9398
const refTransformFilter =
94-
refTransform === false
99+
reactivityTransform === false
95100
? () => false
96-
: refTransform === true
101+
: reactivityTransform === true
97102
? createFilter(/\.(j|t)sx?$/, /node_modules/)
98-
: createFilter(refTransform)
103+
: createFilter(reactivityTransform)
99104

100105
let options: ResolvedOptions = {
101106
isProduction: process.env.NODE_ENV === 'production',
102107
...rawOptions,
103108
include,
104109
exclude,
105110
customElement,
106-
refTransform,
111+
reactivityTransform,
107112
root: process.cwd(),
108113
sourceMap: true,
109114
compiler: null as any // to be set in configResolved

packages/plugin-vue/src/script.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function resolveScript(
5353
id: descriptor.id,
5454
isProd: options.isProduction,
5555
inlineTemplate: isUseInlineTemplate(descriptor, !options.devServer),
56-
refTransform: options.refTransform !== false,
56+
reactivityTransform: options.reactivityTransform !== false,
5757
templateOptions: resolveTemplateCompilerOptions(descriptor, options, ssr),
5858
sourceMap: options.sourceMap
5959
})

pnpm-lock.yaml

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)