Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions packages/plugin-vue-jsx/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ function vueJsxPlugin(options: Options = {}): Plugin {
...babelPluginOptions
} = options
const filter = createFilter(include, exclude)
let tsPluginPromise: Promise<babel.ConfigItem> | undefined
const resolveTsPlugin = () => {
tsPluginPromise ??=
tsTransform === 'built-in'
? // @ts-ignore missing type
import('@babel/plugin-syntax-typescript').then(
(r) =>
babel.createConfigItem([r.default, { isTSX: true }], {
type: 'plugin',
})!,
)
: // @ts-ignore missing type
import('@babel/plugin-transform-typescript').then(
(r) =>
babel.createConfigItem(
[
r.default,
{ ...tsPluginOptions, isTSX: true, allowExtensions: true },
],
{ type: 'plugin' },
)!,
)
return tsPluginPromise
}

return {
name: 'vite:vue-jsx',
Expand Down Expand Up @@ -142,26 +166,7 @@ function vueJsxPlugin(options: Options = {}): Plugin {
if (filter(id) || filter(filepath)) {
const plugins = [[jsx, babelPluginOptions], ...babelPlugins]
if (id.endsWith('.tsx') || filepath.endsWith('.tsx')) {
if (tsTransform === 'built-in') {
// For 'built-in' add "syntax" plugin
// to enable parsing without transformation.
plugins.push([
// @ts-ignore missing type
await import('@babel/plugin-syntax-typescript').then(
(r) => r.default,
),
{ isTSX: true },
])
} else {
plugins.push([
// @ts-ignore missing type
await import('@babel/plugin-transform-typescript').then(
(r) => r.default,
),
// @ts-ignore
{ ...tsPluginOptions, isTSX: true, allowExtensions: true },
])
}
plugins.push(await resolveTsPlugin())
}

if (!ssr && !needHmr) {
Expand Down
Loading