@@ -5,6 +5,10 @@ interface ReanimatedLoaderOptions {
55 babelPlugins ?: string [ ] ;
66}
77
8+ interface ReanimatedLoaderData {
9+ skip ?: boolean ;
10+ }
11+
812// Reference: https://github.com/software-mansion/react-native-reanimated/blob/3.16.3/packages/react-native-reanimated/plugin/src/autoworkletization.ts#L19-L59
913const REANIMATED_AUTOWORKLETIZATION_KEYWORDS = [
1014 'worklet' ,
@@ -39,7 +43,8 @@ export default function reanimatedLoader(
3943 const callback = this . async ( ) ;
4044 const options = this . getOptions ( ) ;
4145
42- if ( ! REANIMATED_REGEX . test ( source ) ) {
46+ const loaderData = this . data as ReanimatedLoaderData ;
47+ if ( loaderData . skip || ! REANIMATED_REGEX . test ( source ) ) {
4348 callback ( null , source ) ;
4449 return ;
4550 }
@@ -68,3 +73,24 @@ export default function reanimatedLoader(
6873 }
6974 ) ;
7075}
76+
77+ // resolve the path to the hybrid-js-loader once
78+ const hybridJsLoaderPath = require . resolve (
79+ '@callstack/repack/hybrid-js-loader'
80+ ) ;
81+
82+ export function pitch (
83+ this : LoaderContext < ReanimatedLoaderOptions > ,
84+ _remainingRequest : string ,
85+ _previousRequest : string ,
86+ data : ReanimatedLoaderData
87+ ) {
88+ for ( const loader of this . loaders ) {
89+ // if the hybrid-js-loader is found, we skip the reanimated loader
90+ // since hybrid-js-loader is more performant and uses the official
91+ // babel plugin directly
92+ if ( loader . path === hybridJsLoaderPath ) {
93+ data . skip = true ;
94+ }
95+ }
96+ }
0 commit comments