From 094f67a1795e4f400d8bc4704c4e5831c5fd9533 Mon Sep 17 00:00:00 2001 From: Amour1688 Date: Thu, 24 Jun 2021 10:06:02 +0800 Subject: [PATCH] feat(jsx): should support extra babel plugins --- packages/plugin-vue-jsx/index.d.ts | 2 +- packages/plugin-vue-jsx/index.js | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/plugin-vue-jsx/index.d.ts b/packages/plugin-vue-jsx/index.d.ts index 22aad9b5eecb45..2cac80ba56632e 100644 --- a/packages/plugin-vue-jsx/index.d.ts +++ b/packages/plugin-vue-jsx/index.d.ts @@ -8,7 +8,7 @@ declare interface FilterOptions { } declare function createPlugin( - options?: VueJSXPluginOptions & FilterOptions + options?: VueJSXPluginOptions & FilterOptions & { babelPlugins?: any[] } ): Plugin export default createPlugin diff --git a/packages/plugin-vue-jsx/index.js b/packages/plugin-vue-jsx/index.js index 8e7898a58fdc8a..eb5d26d8073f0e 100644 --- a/packages/plugin-vue-jsx/index.js +++ b/packages/plugin-vue-jsx/index.js @@ -30,12 +30,12 @@ function ssrRegisterHelper(comp, filename) { /** * @typedef { import('@rollup/pluginutils').FilterPattern} FilterPattern - * @typedef { { include?: FilterPattern, exclude?: FilterPattern } } CommonOtions + * @typedef { { include?: FilterPattern, exclude?: FilterPattern, babelPlugins?: any[] } } 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 +78,21 @@ function vueJsxPlugin(options = {}) { }, transform(code, id, ssr) { - const { include, exclude, ...babelPluginOptions } = options + const { + include, + exclude, + babelPlugins = [], + ...babelPluginOptions + } = options const filter = createFilter(include || /\.[jt]sx$/, exclude) if (filter(id)) { - const plugins = [importMeta, [jsx, babelPluginOptions]] + const plugins = [ + importMeta, + [jsx, babelPluginOptions], + ...babelPlugins + ] if (id.endsWith('.tsx')) { plugins.push([ require('@babel/plugin-transform-typescript'),