Skip to content

Commit 8466330

Browse files
authored
feat: include/exclude options for vue-jsx plugin (#1953)
1 parent 49d19a6 commit 8466330

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Diff for: packages/plugin-vue-jsx/index.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const babel = require('@babel/core')
33
const jsx = require('@vue/babel-plugin-jsx')
44
const importMeta = require('@babel/plugin-syntax-import-meta')
5+
const { createFilter } = require('@rollup/pluginutils')
56
const hash = require('hash-sum')
67

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

3031
/**
31-
* @param {import('@vue/babel-plugin-jsx').VueJSXPluginOptions} options
32+
* @typedef { import('@rollup/pluginutils').FilterPattern} FilterPattern
33+
* @typedef { { include?: FilterPattern, exclude?: FilterPattern } } CommonOtions
34+
*/
35+
36+
/**
37+
*
38+
* @param {import('@vue/babel-plugin-jsx').VueJSXPluginOptions & CommonOtions} options
3239
* @returns {import('vite').Plugin}
3340
*/
3441
function vueJsxPlugin(options = {}) {
@@ -71,8 +78,12 @@ function vueJsxPlugin(options = {}) {
7178
},
7279

7380
transform(code, id, ssr) {
74-
if (/\.[jt]sx$/.test(id)) {
75-
const plugins = [importMeta, [jsx, options]]
81+
const { include, exclude, ...babelPluginOptions } = options
82+
83+
const filter = createFilter(include || /\.[jt]sx$/, exclude)
84+
85+
if (filter(id)) {
86+
const plugins = [importMeta, [jsx, babelPluginOptions]]
7687
if (id.endsWith('.tsx')) {
7788
plugins.push([
7889
require('@babel/plugin-transform-typescript'),

Diff for: packages/plugin-vue-jsx/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@babel/core": "^7.12.10",
3030
"@babel/plugin-syntax-import-meta": "^7.10.4",
3131
"@babel/plugin-transform-typescript": "^7.12.1",
32+
"@rollup/pluginutils": "^4.1.0",
3233
"@vue/babel-plugin-jsx": "^1.0.3",
3334
"hash-sum": "^2.0.0"
3435
}

0 commit comments

Comments
 (0)