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: {