From aada0c5e71e4826cf049596f3459d48b386ea4da Mon Sep 17 00:00:00 2001 From: Amour1688 Date: Sat, 26 Jun 2021 01:58:55 +0800 Subject: [PATCH] feat(plugin-vue-jsx): jsx plugin should have extra babel plugins option (#3923) --- 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'),