2
2
const babel = require ( '@babel/core' )
3
3
const jsx = require ( '@vue/babel-plugin-jsx' )
4
4
const importMeta = require ( '@babel/plugin-syntax-import-meta' )
5
+ const { createFilter } = require ( '@rollup/pluginutils' )
5
6
const hash = require ( 'hash-sum' )
6
7
7
8
const ssrRegisterHelperId = '/__vue-jsx-ssr-register-helper'
@@ -28,7 +29,13 @@ function ssrRegisterHelper(comp, filename) {
28
29
}
29
30
30
31
/**
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
32
39
* @returns {import('vite').Plugin }
33
40
*/
34
41
function vueJsxPlugin ( options = { } ) {
@@ -71,8 +78,12 @@ function vueJsxPlugin(options = {}) {
71
78
} ,
72
79
73
80
transform ( code , id , ssr ) {
74
- if ( / \. [ j t ] s x $ / . test ( id ) ) {
75
- const plugins = [ importMeta , [ jsx , options ] ]
81
+ const { include, exclude, ...babelPluginOptions } = options
82
+
83
+ const filter = createFilter ( include || / \. [ j t ] s x $ / , exclude )
84
+
85
+ if ( filter ( id ) ) {
86
+ const plugins = [ importMeta , [ jsx , babelPluginOptions ] ]
76
87
if ( id . endsWith ( '.tsx' ) ) {
77
88
plugins . push ( [
78
89
require ( '@babel/plugin-transform-typescript' ) ,
0 commit comments