@@ -2,9 +2,18 @@ import path from 'node:path';
22import type { Compiler as RspackCompiler } from '@rspack/core' ;
33import semver , { type SemVer } from 'semver' ;
44import type { Compiler as WebpackCompiler } from 'webpack' ;
5- import { reanimated3ModuleRules , reanimated4ModuleRules } from './rules.js' ;
5+ import { createReanimatedModuleRules } from './rules.js' ;
6+
7+ interface ReanimatedPluginOptions {
8+ /**
9+ * Custom options passed to 'react-native-reanimated/plugin' or 'react-native-worklets/plugin' babel plugins.
10+ */
11+ babelPluginOptions ?: Record < string , any > ;
12+ }
613
714export class ReanimatedPlugin {
15+ constructor ( private options : ReanimatedPluginOptions = { } ) { }
16+
817 apply ( compiler : RspackCompiler ) : void ;
918 apply ( compiler : WebpackCompiler ) : void ;
1019
@@ -18,12 +27,17 @@ export class ReanimatedPlugin {
1827
1928 const reanimatedVersion = this . getReanimatedVersion ( reanimatedPath ) ;
2029
21- // add rules for transpiling wih reanimated loader
30+ if ( reanimatedVersion . major >= 4 ) {
31+ this . ensureDependencyInstalled ( compiler . context , 'react-native-worklets' ) ;
32+ }
33+
34+ // add rules for transpiling with reanimated loader
2235 // TODO made obsolete by the new babel-swc-loader, remove in 6.0
2336 compiler . options . module . rules . push (
24- reanimatedVersion . major < 4
25- ? reanimated3ModuleRules
26- : reanimated4ModuleRules
37+ createReanimatedModuleRules (
38+ reanimatedVersion . major ,
39+ this . options . babelPluginOptions
40+ )
2741 ) ;
2842
2943 // ignore the 'setUpTests' warning from reanimated which is not relevant
0 commit comments