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 f60874c commit b873333
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
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

0 comments on commit b873333

Please sign in to comment.