From 916f9d3984d5e83f7cb869b3606a1f043a814b97 Mon Sep 17 00:00:00 2001 From: hyrious Date: Wed, 6 Oct 2021 01:25:16 +0800 Subject: [PATCH] fix(plugin-react): turn off jsx for .ts (#5198) Fixes #5102 --- packages/plugin-react/src/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts index cd8870e94ff2f6..6d5f05aef8a32f 100644 --- a/packages/plugin-react/src/index.ts +++ b/packages/plugin-react/src/index.ts @@ -97,7 +97,6 @@ export default function viteReact(opts: Options = {}): PluginOption[] { const parserPlugins: typeof userParserPlugins = [ ...userParserPlugins, - 'jsx', 'importMeta', // This plugin is applied before esbuild transforms the code, // so we need to enable some stage 3 syntax that is supported in @@ -108,6 +107,10 @@ export default function viteReact(opts: Options = {}): PluginOption[] { 'classPrivateMethods' ] + if (!id.endsWith('.ts')) { + parserPlugins.push('jsx') + } + const isTypeScript = /\.tsx?$/.test(id) if (isTypeScript) { parserPlugins.push('typescript')