Skip to content

Commit ece451c

Browse files
authored
feat: add option to disable transforms in Reanimated plugin (#1270)
1 parent 58a459f commit ece451c

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

.changeset/thick-facts-make.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@callstack/repack-plugin-reanimated": patch
3+
"@callstack/repack": patch
4+
---
5+
6+
ReanimatedPlugin: add option to disable transforms. This is useful when using `babel-swc-loader` or `babel-loader`

apps/tester-app/rspack.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export default Repack.defineRspackConfig((env) => {
122122
}),
123123
new ReanimatedPlugin({
124124
babelPluginOptions: { relativeSourceLocation: true },
125+
unstable_disableTransform: true,
125126
}),
126127
new NativeWindPlugin({ cssInteropOptions: { inlineRem: 16 } }),
127128
process.env.RSDOCTOR && new RsdoctorRspackPlugin(),

packages/plugin-reanimated/src/loader.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,13 @@ export function pitch(
9494
if (!warningDisplayed) {
9595
warningDisplayed = true;
9696
logger.warn(
97-
'`@callstack/repack-plugin-reanimated` should not be used with `@callstack/repack/babel-swc-loader`. ' +
98-
'Instead, add the `react-native-reanimated/plugin` (or `react-native-worklets/plugin`) directly to your list of babel plugins in the `babel.config.js` file in the project root.'
97+
'When using `@callstack/repack-plugin-reanimated` together with ' +
98+
'`@callstack/repack/babel-swc-loader` you should turn off the ' +
99+
'transforms for `react-native-reanimated` via the ' +
100+
'`unstable_disableTransform` option. Instead, please add the ' +
101+
'`react-native-reanimated/plugin` (or ' +
102+
'`react-native-worklets/plugin`) directly to your list of babel ' +
103+
'plugins in the `babel.config.js` file in the project root.'
99104
);
100105
}
101106
}

packages/plugin-reanimated/src/plugin.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ interface ReanimatedPluginOptions {
99
* Custom options passed to 'react-native-reanimated/plugin' or 'react-native-worklets/plugin' babel plugins.
1010
*/
1111
babelPluginOptions?: Record<string, any>;
12+
13+
/**
14+
* Disable adding transformation rules for reanimated / worklets babel plugin.
15+
* This is useful when handling using `babel-swc-loader` or `babel-loader` and
16+
* you have already added the babel plugin to your babel config.
17+
*/
18+
unstable_disableTransform?: boolean;
1219
}
1320

1421
export class ReanimatedPlugin {
@@ -31,14 +38,16 @@ export class ReanimatedPlugin {
3138
this.ensureDependencyInstalled(compiler.context, 'react-native-worklets');
3239
}
3340

34-
// add rules for transpiling with reanimated loader
35-
// TODO made obsolete by the new babel-swc-loader, remove in 6.0
36-
compiler.options.module.rules.push(
37-
createReanimatedModuleRules(
38-
reanimatedVersion.major,
39-
this.options.babelPluginOptions
40-
)
41-
);
41+
if (!this.options.unstable_disableTransform) {
42+
// add rules for transpiling with reanimated loader
43+
// TODO made obsolete by the new babel-swc-loader, remove in 6.0
44+
compiler.options.module.rules.push(
45+
createReanimatedModuleRules(
46+
reanimatedVersion.major,
47+
this.options.babelPluginOptions
48+
)
49+
);
50+
}
4251

4352
// ignore the 'setUpTests' warning from reanimated which is not relevant
4453
compiler.options.ignoreWarnings = compiler.options.ignoreWarnings ?? [];

0 commit comments

Comments
 (0)