Skip to content

Commit

Permalink
feat: include/exclude options for vue-jsx plugin (#1953)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jokcy committed Apr 19, 2021
1 parent 49d19a6 commit 8466330
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/plugin-vue-jsx/index.js
Expand Up @@ -2,6 +2,7 @@
const babel = require('@babel/core')
const jsx = require('@vue/babel-plugin-jsx')
const importMeta = require('@babel/plugin-syntax-import-meta')
const { createFilter } = require('@rollup/pluginutils')
const hash = require('hash-sum')

const ssrRegisterHelperId = '/__vue-jsx-ssr-register-helper'
Expand All @@ -28,7 +29,13 @@ function ssrRegisterHelper(comp, filename) {
}

/**
* @param {import('@vue/babel-plugin-jsx').VueJSXPluginOptions} options
* @typedef { import('@rollup/pluginutils').FilterPattern} FilterPattern
* @typedef { { include?: FilterPattern, exclude?: FilterPattern } } CommonOtions
*/

/**
*
* @param {import('@vue/babel-plugin-jsx').VueJSXPluginOptions & CommonOtions} options
* @returns {import('vite').Plugin}
*/
function vueJsxPlugin(options = {}) {
Expand Down Expand Up @@ -71,8 +78,12 @@ function vueJsxPlugin(options = {}) {
},

transform(code, id, ssr) {
if (/\.[jt]sx$/.test(id)) {
const plugins = [importMeta, [jsx, options]]
const { include, exclude, ...babelPluginOptions } = options

const filter = createFilter(include || /\.[jt]sx$/, exclude)

if (filter(id)) {
const plugins = [importMeta, [jsx, babelPluginOptions]]
if (id.endsWith('.tsx')) {
plugins.push([
require('@babel/plugin-transform-typescript'),
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-vue-jsx/package.json
Expand Up @@ -29,6 +29,7 @@
"@babel/core": "^7.12.10",
"@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/plugin-transform-typescript": "^7.12.1",
"@rollup/pluginutils": "^4.1.0",
"@vue/babel-plugin-jsx": "^1.0.3",
"hash-sum": "^2.0.0"
}
Expand Down

0 comments on commit 8466330

Please sign in to comment.