Skip to content

Commit

Permalink
feat(jsx): should support extra babel plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Amour1688 committed Jun 23, 2021
1 parent 615a022 commit 6894a9e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/plugin-vue-jsx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>] } 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 = {}) {
Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit 6894a9e

Please sign in to comment.