A React Native monorepo boilerplate supporting multiple platforms: Android, iOS, macOS, Windows, web, browser extension, Electron.
This monorepo uses Yarn workspaces and TypeScript to support a modular React Native project.
It uses Yarn's nohoist
to ensure the react-native
libraries are stored within the workspace packages instead of being hosted to the top level.
On one hand, this approach has the drawback of (potentially) keeping multiple copies of the same React Native version in different workspace packages.
On the other hand, we get a predictable React Native setup: we don't have to deal with changing root directory references in the native code, and we can support different versions of React Native while still sharing the app's code.
Please notice that I'm not saying that this is not the right way to do React Native monorepos. It's just an approach that I enjoy using.
- Android (React-Native 0.65)
- iOS (React-Native 0.65)
- Windows (React-Native 0.65)
- MacOS (React-Native 0.63)
- Web (React-Native 0.65)
- Web - Browser Extension (React-Native 0.65)
- Web - Electron (React-Native 0.65)
- Clone the repository:
[email protected]:mmazzarolo/react-native-universal-monorepo.git
- Run yarn install
cd react-native-universal-monorepo && yarn
🚧 I'm working on a blog post to explain how to get to this monorepo structure from scratch.
For now, if you're interested, please check the following guides:
yarn android:metro
: Start the metro server for android/iOSyarn android:start
: Start developing the android appyarn android:studio
: Open the android app on android Studioyarn ios:metro
: Start the metro server for android/iOSyarn ios:start
: Start developing the iOS appyarn ios:xcode
: Open the iOS app on XCodeyarn macos:metro
: Start the metro server for macOSyarn macos:start
: Start developing the macOS appyarn macos:xcode
: Open the macOS app on XCodeyarn web:start
: Start developing the web appyarn web:build
: Create a production build of the web appyarn electron:start
: Start developing the electron appyarn electron:package:mac
: Package the production binary of the electron app for macOSyarn electron:package:win
: Package the production binary of the electron app for windowsyarn electron:package:linux
: Package the production binary of the electron app for linuxyarn browser-ext:start
: Start developing the browser extensionyarn browser-ext:build
: Create a production build of the browser extensionyarn windows:metro
: Start the metro server for windowsyarn windows:start
: Start developing the windows appyarn lint
: Lint each projectyarn lint:fix
: Lint + fix each projectyarn test
: Run tests of each projectyarn typecheck
: Run the TypeScript type-checking on each project
For some native (or React-Native-specific) dependencies, you'll need to nohoist
them and/or update the metro configuration to avoid collisions with multiple versions of them.
This is not an issue with the approach used in this project per se', it's a common problem with monorepos.
You can use babel-plugin-module-resolver
to dedupe these dependencies — planning to add an example soon.