Skip to content

Commit 9a0773e

Browse files
authored
feat(plugin-vue-jsx): jsx plugin should have extra babel plugins option (#3923)
1 parent efa4e4d commit 9a0773e

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

packages/plugin-vue-jsx/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ declare interface FilterOptions {
88
}
99

1010
declare function createPlugin(
11-
options?: VueJSXPluginOptions & FilterOptions
11+
options?: VueJSXPluginOptions & FilterOptions & { babelPlugins?: any[] }
1212
): Plugin
1313

1414
export default createPlugin

packages/plugin-vue-jsx/index.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ function ssrRegisterHelper(comp, filename) {
3030

3131
/**
3232
* @typedef { import('@rollup/pluginutils').FilterPattern} FilterPattern
33-
* @typedef { { include?: FilterPattern, exclude?: FilterPattern } } CommonOtions
33+
* @typedef { { include?: FilterPattern, exclude?: FilterPattern, babelPlugins?: any[] } } CommonOptions
3434
*/
3535

3636
/**
3737
*
38-
* @param {import('@vue/babel-plugin-jsx').VueJSXPluginOptions & CommonOtions} options
38+
* @param {import('@vue/babel-plugin-jsx').VueJSXPluginOptions & CommonOptions} options
3939
* @returns {import('vite').Plugin}
4040
*/
4141
function vueJsxPlugin(options = {}) {
@@ -78,12 +78,21 @@ function vueJsxPlugin(options = {}) {
7878
},
7979

8080
transform(code, id, ssr) {
81-
const { include, exclude, ...babelPluginOptions } = options
81+
const {
82+
include,
83+
exclude,
84+
babelPlugins = [],
85+
...babelPluginOptions
86+
} = options
8287

8388
const filter = createFilter(include || /\.[jt]sx$/, exclude)
8489

8590
if (filter(id)) {
86-
const plugins = [importMeta, [jsx, babelPluginOptions]]
91+
const plugins = [
92+
importMeta,
93+
[jsx, babelPluginOptions],
94+
...babelPlugins
95+
]
8796
if (id.endsWith('.tsx')) {
8897
plugins.push([
8998
require('@babel/plugin-transform-typescript'),

0 commit comments

Comments
 (0)