Skip to content

Commit 99f06d1

Browse files
committed
feat: skip reaniamted loader when hybrid loader is found
1 parent 9809ce0 commit 99f06d1

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

apps/tester-app/rspack.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'node:path';
22
import * as Repack from '@callstack/repack';
33
import { NativeWindPlugin } from '@callstack/repack-plugin-nativewind';
4-
// import { ReanimatedPlugin } from '@callstack/repack-plugin-reanimated';
4+
import { ReanimatedPlugin } from '@callstack/repack-plugin-reanimated';
55
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
66

77
const dirname = Repack.getDirname(import.meta.url);
@@ -129,7 +129,7 @@ export default Repack.defineRspackConfig((env) => {
129129
// exclude: /index.bundle$/,
130130
// }),
131131
process.env.RSDOCTOR && new RsdoctorRspackPlugin(),
132-
// new ReanimatedPlugin(),
132+
new ReanimatedPlugin(),
133133
new NativeWindPlugin({ cssInteropOptions: { inlineRem: 16 } }),
134134
].filter(Boolean),
135135
};

packages/plugin-reanimated/src/loader.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
913
const 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

Comments
 (0)