From 6894a9e94a112183dcd2de0d50aaafcd4583d566 Mon Sep 17 00:00:00 2001 From: Amour1688 Date: Wed, 23 Jun 2021 22:27:40 +0800 Subject: [PATCH] feat(jsx): should support extra babel plugins --- packages/plugin-vue-jsx/index.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/plugin-vue-jsx/index.js b/packages/plugin-vue-jsx/index.js index 8e7898a58fdc8a..8fce85c168fbc6 100644 --- a/packages/plugin-vue-jsx/index.js +++ b/packages/plugin-vue-jsx/index.js @@ -30,12 +30,13 @@ function ssrRegisterHelper(comp, filename) { /** * @typedef { import('@rollup/pluginutils').FilterPattern} FilterPattern - * @typedef { { include?: FilterPattern, exclude?: FilterPattern } } CommonOtions + * @typedef { any | [any] | [any, Record] } BabelPlugin + * @typedef { { include?: FilterPattern, exclude?: FilterPattern, extraBabelPlugins?: BabelPlugin[] } } CommonOptions */ /** * - * @param {import('@vue/babel-plugin-jsx').VueJSXPluginOptions & CommonOtions} options + * @param {import('@vue/babel-plugin-jsx').VueJSXPluginOptions & CommonOptions} options * @returns {import('vite').Plugin} */ function vueJsxPlugin(options = {}) { @@ -78,12 +79,21 @@ function vueJsxPlugin(options = {}) { }, transform(code, id, ssr) { - const { include, exclude, ...babelPluginOptions } = options + const { + include, + exclude, + extraBabelPlugins = [], + ...babelPluginOptions + } = options const filter = createFilter(include || /\.[jt]sx$/, exclude) if (filter(id)) { - const plugins = [importMeta, [jsx, babelPluginOptions]] + const plugins = [ + importMeta, + [jsx, babelPluginOptions], + ...extraBabelPlugins + ] if (id.endsWith('.tsx')) { plugins.push([ require('@babel/plugin-transform-typescript'),