Skip to content

Commit 599f3d8

Browse files
dannyhwjbroma
andauthored
docs: update reanimated docs to be accurate for reanimated v4 (#1313)
Co-authored-by: Jakub Romańczyk <[email protected]>
1 parent e6e3f25 commit 599f3d8

File tree

1 file changed

+60
-36
lines changed

1 file changed

+60
-36
lines changed

website/src/latest/docs/features/reanimated.mdx

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,93 @@ import { PackageManagerTabs } from '@theme';
22

33
# React Native Reanimated
44

5-
Re.Pack provides first-class support for [React Native Reanimated](https://docs.swmansion.com/react-native-reanimated/) through a dedicated plugin that simplifies integration and optimizes build performance.
5+
Re.Pack provides first-class support for [React Native Reanimated](https://docs.swmansion.com/react-native-reanimated/) through a dedicated plugin that simplifies integration and in some cases, optimizes your build performance.
66

7-
:::warning This plugin is primarily intended for Rspack users.
7+
:::info This plugin is primarily used to disable console warnings that are not relevant when bundling a React Native app.
88

9-
The main purpose of this plugin is to limit the **build performance impact** of the `react-native-reanimated` babel plugin.
9+
:::
1010

11-
If you're using webpack with `babel-loader`, you probably don't need this plugin. Instead, you should follow the [official Reanimated documentation](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started/#step-2-add-reanimateds-babel-plugin) and add the Reanimated Babel plugin directly to your `babel.config.js`:
11+
## How it Works
1212

13-
```js
14-
module.exports = {
15-
presets: ["module:@react-native/babel-preset"],
16-
plugins: ["react-native-reanimated/plugin"],
17-
};
18-
```
13+
The Worklets Babel Plugin transforms your code so that it can run on the Worklet Runtimes. It looks for functions marked with a `'worklet';` directive and converts them into serializable objects.
1914

20-
:::
15+
When using Rspack, the worklets babel plugin is executed via `babel-swc-loader`. The `ReanimatedPlugin` handles configuration and suppresses warnings that would otherwise appear during the build process.
2116

22-
## How It Works
17+
## Installation
2318

24-
### The Problem
19+
If you haven't already, install the `react-native-reanimated` package:
2520

26-
React Native Reanimated requires a special Babel plugin to transform your code, particularly functions marked with `'worklet'`.
27-
This transformation is necessary but comes with a cost - the babel transformation can slow down your build process significantly
28-
when applied to all files. With Rspack under the hood, we want to make sure that we use `babel-loader` only as a last resort.
21+
<PackageManagerTabs command="install react-native-reanimated" />
2922

30-
### The Solution
23+
To add Reanimated support to your Re.Pack project with Rspack, install the plugin:
3124

32-
Our plugin takes a smarter approach by only applying the Reanimated transformation to files that actually need it:
25+
<PackageManagerTabs command="install -D @callstack/repack-plugin-reanimated" />
3326

34-
- **Smart Detection**: Before running babel, we scan files for Reanimated keywords like `worklet`
35-
- **Targeted Processing**: Only files containing these keywords go through the transformation
36-
- **Performance Boost**: Everything else skips this heavy processing step
27+
## Usage with Reanimated 4+
3728

38-
In simple terms: we make your builds faster by only doing the heavy Reanimated processing where it's actually needed.
29+
For Reanimated 4 and above, the worklet transformation is handled by the `react-native-worklets/plugin` babel plugin.
3930

40-
:::note Credits
41-
Shoutout to [Nate Wienert](https://x.com/natebirdman) who came up with a similar approach in [one.dev](https://one.dev) - his work was the inspiration for this plugin.
42-
:::
31+
Install the worklets package:
4332

44-
## Installation
33+
<PackageManagerTabs command="install react-native-worklets" />
4534

46-
If you haven't already, install the `react-native-reanimated` package:
35+
### Babel Configuration
4736

48-
<PackageManagerTabs command="install react-native-reanimated" />
37+
Add the worklets plugin to your `babel.config.js`:
4938

50-
To add Reanimated support to your Re.Pack project with Rspack, install the plugin:
39+
```js title="babel.config.js"
40+
module.exports = {
41+
presets: ["module:@react-native/babel-preset"],
42+
plugins: ["react-native-worklets/plugin"],
43+
};
44+
```
5145

52-
<PackageManagerTabs command="install -D @callstack/repack-plugin-reanimated" />
46+
### Rspack Configuration
47+
48+
Add the plugin to your Rspack configuration with the `unstable_disableTransform` option set to `true`.
49+
50+
```js title="rspack.config.cjs"
51+
const Repack = require("@callstack/repack");
52+
const { ReanimatedPlugin } = require("@callstack/repack-plugin-reanimated");
5353

54-
## Usage
54+
module.exports = {
55+
plugins: [
56+
new Repack.RepackPlugin(),
57+
new ReanimatedPlugin({
58+
unstable_disableTransform: true,
59+
}),
60+
],
61+
};
62+
```
5563

56-
### Plugin Configuration
64+
This will disable adding now redundant `babel-loader` rules, and defer the transformation to Babel through `babel-swc-loader`.
65+
66+
67+
## Usage with Reanimated 3
68+
69+
First add the `react-native-reanimated` babel plugin to your `babel.config.js`:
70+
71+
```js title="babel.config.js"
72+
module.exports = {
73+
presets: ["module:@react-native/babel-preset"],
74+
plugins: [
75+
"react-native-reanimated/plugin",
76+
],
77+
};
78+
```
5779

58-
Add the plugin to your Rspack configuration file (`rspack.config.js`):
80+
Then apply the `ReanimatedPlugin` with the unstable_disableTransform option set to `true`.
5981

6082
```js title="rspack.config.cjs"
6183
const Repack = require("@callstack/repack");
6284
const { ReanimatedPlugin } = require("@callstack/repack-plugin-reanimated");
6385

6486
module.exports = {
6587
plugins: [
66-
new Repack.RepackPlugin(),
67-
new ReanimatedPlugin(),
68-
],
88+
new Repack.RepackPlugin(),
89+
new ReanimatedPlugin({
90+
unstable_disableTransform: true,
91+
}),
92+
],
6993
};
7094
```

0 commit comments

Comments
 (0)