From 3e46a33d38bf284f1e87ff8d56b2d3b9d17627ee Mon Sep 17 00:00:00 2001 From: JacobDel Date: Wed, 2 Jul 2025 10:13:34 +0200 Subject: [PATCH] make transformWithEsbuild optional Add option to disable transformWithEsbuild for Babel --- package-lock.json | 4 ++-- src/index.ts | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 74f1bc2..93cdc94 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vite-plugin-react-native-web", - "version": "2.0.2", + "version": "2.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "vite-plugin-react-native-web", - "version": "2.0.2", + "version": "2.1.1", "license": "MIT", "dependencies": { "flow-remove-types": "^2.259.1" diff --git a/src/index.ts b/src/index.ts index 1de3cb2..f8228ba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,10 @@ import type { SourceMap } from 'rollup' import type { Plugin as VitePlugin } from 'vite' // import type { ViteReactNativeWebOptions } from '../types' +type ViteReactNativeWebOptions = { + transformJsx?: boolean +} + const development = process.env.NODE_ENV === 'development' const extensions = [ @@ -70,7 +74,7 @@ const esbuildPlugin = (): ESBuildPlugin => ({ }, }) -const reactNativeWeb = (/*options: ViteReactNativeWebOptions = {}*/): VitePlugin => ({ +const reactNativeWeb = (options: ViteReactNativeWebOptions = {}): VitePlugin => ({ enforce: 'pre', name: 'react-native-web', @@ -111,7 +115,12 @@ const reactNativeWeb = (/*options: ViteReactNativeWebOptions = {}*/): VitePlugin } } - if (jsxElementPattern.test(code) || jsxSelfClosingPattern.test(code) || jsxFragmentPattern.test(code)) { + const shouldTransformJsx = options.transformJsx !== false + + if ( + shouldTransformJsx && + (jsxElementPattern.test(code) || jsxSelfClosingPattern.test(code) || jsxFragmentPattern.test(code)) + ) { const result = await transformWithEsbuild(code, id, { loader: reactNativeFlowJsxLoader, tsconfigRaw: {