@@ -82,7 +82,7 @@ type ReactBabelHookContext = { ssr: boolean; id: string }
8282
8383export type ViteReactPluginApi = {
8484 /**
85- * Manipulate the Babel options of `@vitejs /plugin-react`
85+ * Manipulate the Babel options of `@dhw /plugin-react-native-web `
8686 */
8787 reactBabel ?: ReactBabelHook
8888}
@@ -146,6 +146,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
146146 'process.env.NODE_ENV' : JSON . stringify (
147147 process . env . NODE_ENV || env . mode ,
148148 ) ,
149+ __reanimatedLoggerConfig : `{}` ,
149150 } ,
150151 optimizeDeps : {
151152 esbuildOptions : {
@@ -166,18 +167,18 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
166167
167168 if ( opts . jsxRuntime === 'classic' ) {
168169 return {
170+ ...commonOptions ,
169171 esbuild : {
170172 jsx : 'transform' ,
171173 } ,
172- ...commonOptions ,
173174 } satisfies ViteOptions
174175 } else {
175176 return {
177+ ...commonOptions ,
176178 esbuild : {
177179 jsx : 'automatic' ,
178180 jsxImportSource : opts . jsxImportSource ,
179181 } ,
180- ...commonOptions ,
181182 optimizeDeps : {
182183 ...commonOptions . optimizeDeps ,
183184 esbuildOptions : {
@@ -199,7 +200,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
199200
200201 if ( 'jsxPure' in opts ) {
201202 config . logger . warnOnce (
202- '[@vitejs /plugin-react] jsxPure was removed. You can configure esbuild.jsxSideEffects directly.' ,
203+ '[@dhw /plugin-react-native-web ] jsxPure was removed. You can configure esbuild.jsxSideEffects directly.' ,
203204 )
204205 }
205206
@@ -234,9 +235,20 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
234235 return newBabelOptions
235236 } ) ( )
236237 const plugins = [
237- loadPlugin ( 'babel-plugin-react-native-web' ) ,
238- loadPlugin ( '@babel/plugin-transform-flow-strip-types' ) ,
239- loadPlugin ( '@babel/plugin-transform-modules-commonjs' ) ,
238+ await loadPlugin ( 'babel-plugin-react-native-web' ) ,
239+ await loadPlugin ( '@babel/plugin-transform-flow-strip-types' ) ,
240+ await loadPlugin ( '@babel/plugin-syntax-export-default-from' ) ,
241+ // [
242+ // // this is a fix for reanimated not working in production
243+ // '@babel/plugin-transform-modules-commonjs',
244+ // {
245+ // strict: false,
246+ // strictMode: false, // prevent "use strict" injections
247+ // allowTopLevelThis: true, // dont rewrite global `this` -> `undefined`
248+ // },
249+ // ],
250+
251+ // await loadPlugin('@babel/plugin-transform-modules-commonjs'),
240252 ...babelOptions . plugins ,
241253 ]
242254
@@ -336,7 +348,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
336348 jsxImportRuntime ,
337349 ]
338350 const staticBabelPlugins =
339- typeof opts . babel === 'object' ? opts . babel ?. plugins ?? [ ] : [ ]
351+ typeof opts . babel === 'object' ? ( opts . babel ?. plugins ?? [ ] ) : [ ]
340352 const reactCompilerPlugin = getReactCompilerPlugin ( staticBabelPlugins )
341353 if ( reactCompilerPlugin != null ) {
342354 const reactCompilerRuntimeModule =
@@ -353,7 +365,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
353365 include : dependencies ,
354366 } ,
355367 resolve : {
356- dedupe : [ 'react' , 'react-dom' ] ,
368+ dedupe : [ 'react' , 'react-dom' , 'react-native' , 'react-native-web' ] ,
357369 } ,
358370 } ) ,
359371 resolveId ( id ) {
0 commit comments