Skip to content

Commit

Permalink
feat(plugin-vue-jsx): jsx plugin should have extra babel plugins opti…
Browse files Browse the repository at this point in the history
…on (vitejs#3923)
  • Loading branch information
Amour1688 authored and aleclarson committed Nov 8, 2021
1 parent d0ee2d0 commit 9f3e8a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-vue-jsx/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare interface FilterOptions {
}

declare function createPlugin(
options?: VueJSXPluginOptions & FilterOptions
options?: VueJSXPluginOptions & FilterOptions & { babelPlugins?: any[] }
): Plugin

export default createPlugin
17 changes: 13 additions & 4 deletions packages/plugin-vue-jsx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit 9f3e8a9

Please sign in to comment.