@react-native-anywhere/anywhere
is a build tool to help you expose browserified libraries to React Native.
There are a lot of really amazing libraries such as Web3 that we don't get to use in React Native because they assume the availability of core Node.js libraries such as crypto
.
This tool can be used to compile compatible implementations of these libraries for the React Native runtime.
Using yarn
:
yarn add @react-native-anywhere/anywhere
Next, append the following command to your postinstall
script in your package.json
:
"scripts": {
+ "postinstall": "npx @react-native-anywhere/anywhereify"
}
Finally, declare an anywhere.config.json
at the root of your project. Here, you declare the libraries and naming conventions you'd like to expose to the React Native runtime:
{
"exports": [
{ "name": "@react-native-anywhere/polyfill-base64" },
{ "name": "web3-providers-http", "alias": "Web3HttpProvider" },
{
"name": "@opengsn/gsn",
"alias": "OpenGSN",
"exports": [
{ "name": "dist/RelayProvider", "alias": "RelayProvider" },
{ "name": "dist/GSNConfigurator", "alias": "GSNConfigurator" }
]
}
]
}
Now you're all set! โจ
Whenever you reinstall your project, npx @react-native-anywhere/anywhereify
will recompile the dependencies defined in your anywhere.config.json
into a React Native compatible format. Once this is done, they will become available via imports:
import { Web3HttpProvider, OpenGSN } from "@react-native-anywhere/anywhere";
const { RelayProvider, GSNConfigurator } = OpenGSN;
You can check out some Example Projects here.