Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to substitute
isWeb
and shouldBeUseWeb
in babel plugin. (
#5283) <!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect. --> ## Summary This PR changes the Babel plugin to substitute `isWeb()` and `shouldBeUseWeb()` calls with `true` so that Webpack is able to recognize dead code. ## Test plan Modify the NextExample/babel.config.js file: ```js ['react-native-reanimated/plugin', { omitNativeOnlyData: true, substituteWebPlatformChecks: true }] ``` Run yarn build in NextExample and verify that the difference between reanimated and noreanimated is around 34KB.
- Loading branch information
1 parent
ea5c667
commit 1932f8d
Showing
6 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { NodePath } from '@babel/core'; | ||
import { booleanLiteral, isIdentifier } from '@babel/types'; | ||
import type { CallExpression } from '@babel/types'; | ||
|
||
export function substituteWebCallExpression(path: NodePath<CallExpression>) { | ||
const callee = path.node.callee; | ||
if (isIdentifier(callee)) { | ||
const name = callee.name; | ||
if (name === 'isWeb' || name === 'shouldBeUseWeb') { | ||
path.replaceWith(booleanLiteral(true)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters