diff --git a/packages/playground/vue-jsx/OtherExt.tesx b/packages/playground/vue-jsx/OtherExt.tesx new file mode 100644 index 00000000000000..7ae585a014c566 --- /dev/null +++ b/packages/playground/vue-jsx/OtherExt.tesx @@ -0,0 +1,9 @@ +import { defineComponent } from 'vue' + +const Default = defineComponent(() => { + return () => ( +

Other Ext

+ ) +}) + +export default Default diff --git a/packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts b/packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts index 104d3bd52642b9..b17ba40ce772be 100644 --- a/packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts +++ b/packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts @@ -5,6 +5,7 @@ test('should render', async () => { expect(await page.textContent('.named-specifier')).toMatch('1') expect(await page.textContent('.default')).toMatch('2') expect(await page.textContent('.default-tsx')).toMatch('3') + expect(await page.textContent('.other-ext')).toMatch('Other Ext') }) test('should update', async () => { diff --git a/packages/playground/vue-jsx/main.jsx b/packages/playground/vue-jsx/main.jsx index b0cb108d6c7c88..f9de952320d709 100644 --- a/packages/playground/vue-jsx/main.jsx +++ b/packages/playground/vue-jsx/main.jsx @@ -1,6 +1,7 @@ import { createApp } from 'vue' import { Named, NamedSpec, default as Default } from './Comps' import { default as TsxDefault } from './Comp' +import OtherExt from './OtherExt.tesx' function App() { return ( @@ -9,6 +10,7 @@ function App() { + ) } diff --git a/packages/playground/vue-jsx/vite.config.js b/packages/playground/vue-jsx/vite.config.js index ba8fcd75a71c05..05d1ce17aabbe2 100644 --- a/packages/playground/vue-jsx/vite.config.js +++ b/packages/playground/vue-jsx/vite.config.js @@ -4,7 +4,11 @@ const vueJsxPlugin = require('@vitejs/plugin-vue-jsx') * @type {import('vite').UserConfig} */ module.exports = { - plugins: [vueJsxPlugin()], + plugins: [ + vueJsxPlugin({ + include: [/\.tesx$/, /\.[jt]sx$/] + }) + ], build: { // to make tests faster minify: false diff --git a/packages/plugin-vue-jsx/index.js b/packages/plugin-vue-jsx/index.js index 52a1e1a44020ca..8e7898a58fdc8a 100644 --- a/packages/plugin-vue-jsx/index.js +++ b/packages/plugin-vue-jsx/index.js @@ -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' @@ -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 = {}) { @@ -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'), diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index 09e4b169935222..9609af9589b140 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -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" }