Skip to content

Commit

Permalink
feat(plugin-vue): add reactivityTransform option.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yyx990803 committed Dec 12, 2021
1 parent 5e60562 commit 955d0fe
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/playground/vue/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<Suspense>
<AsyncComponent />
</Suspense>
<RefTransform />
<ReactivityTransform :foo="time" />
<SetupImportTemplate />
</template>

Expand All @@ -33,7 +33,7 @@ import SrcImport from './src-import/SrcImport.vue'
import Slotted from './Slotted.vue'
import ScanDep from './ScanDep.vue'
import AsyncComponent from './AsyncComponent.vue'
import RefTransform from './RefTransform.vue'
import ReactivityTransform from './ReactivityTransform.vue'
import SetupImportTemplate from './setup-import-template/SetupImportTemplate.vue'
import { ref } from 'vue'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<script setup>
const { foo: bar } = defineProps(['foo'])
let a = $ref(0)
const inc = () => a++
</script>

<template>
<h2>Ref Transform</h2>
<h2>Reactivity Transform</h2>
<p>Prop foo: {{ bar }}</p>
<button class="ref-transform" @click="inc">{{ a }}</button>
</template>
3 changes: 1 addition & 2 deletions packages/playground/vue/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import path from 'path'
import { defineConfig } from 'vite'
import vuePlugin from '@vitejs/plugin-vue'
import { vueI18nPlugin } from './CustomBlockPlugin'
Expand All @@ -11,7 +10,7 @@ export default defineConfig({
},
plugins: [
vuePlugin({
refTransform: true
reactivityTransform: true
}),
vueI18nPlugin
],
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-vue#readme",
"peerDependencies": {
"vite": "^2.5.10",
"vue": "^3.2.13"
"vue": "^3.2.25"
},
"devDependencies": {
"@rollup/pluginutils": "^4.1.1",
Expand All @@ -42,6 +42,6 @@
"rollup": "^2.59.0",
"slash": "^4.0.0",
"source-map": "^0.6.1",
"vue": "^3.2.23"
"vue": "^3.2.25"
}
}
23 changes: 14 additions & 9 deletions packages/plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export interface Options {
customElement?: boolean | string | RegExp | (string | RegExp)[]

/**
* Enable Vue ref transform (experimental).
* https://github.com/vuejs/vue-next/tree/master/packages/ref-transform
* Enable Vue reactivity transform (experimental).
* https://github.com/vuejs/vue-next/tree/master/packages/reactivity-transform
*
* **requires Vue \>= 3.2.5**
* **requires vue\@^3.2.25**
*
* - `true`: transform will be enabled for all vue,js(x),ts(x) files except
* those inside node_modules
Expand All @@ -55,7 +55,12 @@ export interface Options {
*
* @default false
*/
refTransform?: boolean | string | RegExp | (string | RegExp)[]
reactivityTransform?: boolean | string | RegExp | (string | RegExp)[]

/**
* @deprecated use `reactivityTransform` instead.
*/
refTransform?: any

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

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

const refTransformFilter =
refTransform === false
reactivityTransform === false
? () => false
: refTransform === true
: reactivityTransform === true
? createFilter(/\.(j|t)sx?$/, /node_modules/)
: createFilter(refTransform)
: createFilter(reactivityTransform)

let options: ResolvedOptions = {
isProduction: process.env.NODE_ENV === 'production',
...rawOptions,
include,
exclude,
customElement,
refTransform,
reactivityTransform,
root: process.cwd(),
sourceMap: true,
compiler: null as any // to be set in configResolved
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function resolveScript(
id: descriptor.id,
isProd: options.isProduction,
inlineTemplate: isUseInlineTemplate(descriptor, !options.devServer),
refTransform: options.refTransform !== false,
reactivityTransform: options.reactivityTransform !== false,
templateOptions: resolveTemplateCompilerOptions(descriptor, options, ssr),
sourceMap: options.sourceMap
})
Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 955d0fe

Please sign in to comment.