• Stars
    star
    1,619
  • Rank 28,903 (Top 0.6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 3 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React Native boilerplate supporting multiple platforms: Android, iOS, macOS, Windows, web, browser extensions, Electron.

React Native Universal Monorepo

An opinonated approach to supporting multiple platforms with React Native using a Yarn Workspaces monorepo.

Check out Running React Native everywhere for an in-depth guide on how and why I recommend trying out this approach if you're planning to support multiple platforms in your app.

Β 

Overview

This monorepo uses Yarn workspaces and TypeScript to support a modular React Native project.

The core idea is to isolate the JavaScript app code from the platform configurations (native code + the app bundlers like Metro and Webpack).
This isolation happens by using different workspaces: We have an app workspace for the JavaScript app code, a mobile workspace for the React Native mobile configuration, a macos workspace for the React Native macOS configuration, and so on.

We fully embrace Yarn nohoist to allow using different versions of React Native on each platform (which is recommended but not required), simplifying the adoption of new React Native updates.
Thanks nohoist, each platform workspace (mobile, macos, etc.) can depend on any React Native version, regardless of what version the other platform workspaces are using. For example, we can use [email protected] on the mobile app and [email protected] on the macOS app β€” as long as the JavaScript app code supports both versions.
This approach promotes gradual React Native updates over updates in lockstep.

For more details, check out "Running React Native everywhere: Yarn Workspaces monorepo setup".

⚠️ Please notice that I'm not saying this is the right way to do React Native monorepos. This is just an approach that I enjoy using on larger codebases :)

Supported platforms

  • Android (React Native 0.65)
  • iOS (React Native 0.65)
  • Windows (React Native 0.65)
  • MacOS (React Native 0.63)
  • Android TV (React Native 0.65)
  • tvOS (React Native 0.65)
  • Web (React Native 0.65)
  • Web - Browser Extension (React Native 0.65)
  • Web - Electron (React Native 0.65)
  • Web - Next.js (React Native 0.65)

Getting started

You can use this repo as a boilerplate, removing the workspaces of platforms that you don't need, or you can create this setup from scratch if you want to fully understand how it works.

Using this repository as a boilerplate

  1. Clone the repository: [email protected]:mmazzarolo/react-native-universal-monorepo.git
  2. Run yarn install cd react-native-universal-monorepo && yarn

Create this setup from scratch

Step by step tutorial on creating this repository from scratch:

Tutorial for the TV and Next.js platforms from @thefinnomenon:

Additional resources:

Available commands

Development and build commands:

  • yarn android:metro: Start the metro server for Android/iOS
  • yarn android:start: Start developing the Android app
  • yarn android:studio: Open the android app on Android Studio
  • yarn ios:metro: Start the metro server for Android/iOS
  • yarn ios:start: Start developing the iOS app
  • yarn ios:pods: Install iOS cocoapods dependencies
  • yarn ios:xcode: Open the iOS app on XCode
  • yarn macos:metro: Start the metro server for macOS
  • yarn macos:start: Start developing the macOS app
  • yarn macos:pods: Install macOS cocoapods dependencies
  • yarn macos:xcode: Open the macOS app on XCode
  • yarn web:start: Start developing the web app
  • yarn web:build: Create a production build of the web app
  • yarn electron:start: Start developing the Electron app
  • yarn electron:package:mac: Package the production binary of the Electron app for macOS
  • yarn electron:package:win: Package the production binary of the Electron app for windows
  • yarn electron:package:linux: Package the production binary of the Electron app for linux
  • yarn browser-ext:start: Start developing the browser extension
  • yarn browser-ext:build: Create a production build of the browser extension
  • yarn windows:metro: Start the metro server for Windows
  • yarn windows:start: Start developing the Windows app
  • yarn tv:android:metro: Start the metro server for Android TV
  • yarn tv:android:start: Start developing the Android TV app
  • yarn tv:android:studio: Open the Android TV app in Android Studio
  • yarn tv:tvos:metro: Start the metro server for tvOS
  • yarn tv:tvos:start: Start developing the tvOS app
  • yarn tv:tvos:xcode: Open the tvOS app in XCode
  • yarn tv:tvos:pods: Install tvOS cocoapods dependencies
  • yarn next:start: Start the Next.js app
  • yarn next:build: Build the Next.js app
  • yarn next:serve: Serve the Next.js app build

Other commands (we use ultra-runner to run these commands on all workspaces):

  • yarn lint: Lint each project
  • yarn lint:fix: Lint + fix each project
  • yarn test: Run tests of each project
  • yarn typecheck: Run the TypeScript type-checking on each project

Native dependencies

While working on React Native in a monorepo, you'll notice that several packages won't work correctly when hoisted β€” either because they need to be natively linked or because they end up being bundled twice, breaking the build (e.g., react, react-dom).
This is not an issue with the approach used in this project per se. It's more of a common problem with monorepos.

To fix these issues, we mark them as nohoist, so they will be installed in each package that depends on them.

In this monorepo, you can see an example of such libraries in react-native-async-storage.

In the metro bundler and Webpack configs used across the monorepo, we're using a set of build-tools to ensure nohoisted packages are resolved correctly.
So, as long as you add these libraries to the nohoist list, you should be good to go πŸ‘

Yarn Classic vs Yarn 2+

We're striving to make this setup compatible with Yarn Classic β€” but, with a few tweaks, it's compatible with Yarn 2+ as well (providing all Yarn 2+ benefits).
See #22 for more info.

Setting up Yarn 2+

  1. Run yarn set version berry at the root of project. It will create a .yarnrc.yml file.
  2. Add the following lines to .yarnrc.yml to ensure node_modules directories are all created in each workspace:
nodeLinker: node-modules
nmHoistingLimits: workspaces
  1. nmHositingLimits tells how to hoist dependencies for each workspace. By setting it to workspaces all dependencies will be installed in each workspace's node_modules rather than being hoisted to the root folder. This means you can now you can safely the noHoist section in the root's package.json.

Check out Yarn 2+'s "getting started" guide for more info.

Known issues

In some cases, Yarn Classic won't be able to resolve correctly dependencies that have a peerDependency on react-native.
See #22 for a few workarounds. A fix on the react-native-monorepo-tools repo is on the work.

Contributing

Contributions, discussions, and feedback are welcome! Please ask if there are any active plans on feature changes before submitting new PRs πŸ‘

More Repositories

1

react-native-modal-datetime-picker

A React-Native datetime-picker for Android and iOS
JavaScript
2,809
star
2

react-native-dialog

Pure JavaScript React-Native dialog
TypeScript
634
star
3

breathly-app

A tiny breath training app built with React-Native
TypeScript
477
star
4

ordinary-puzzles-app

Mobile and web puzzle game built with React-Native
TypeScript
469
star
5

react-native-login-animation-example

A React-Native login animation example
JavaScript
350
star
6

tangerine-monorepo

A "fast" TypeScript-based Node.js monorepo setup powered by esbuild & turborepo
TypeScript
265
star
7

tap-the-number

A simple React-Native game for iOS
JavaScript
157
star
8

react-native-monorepo-tools

Tools and utils to support a React Native monorepo built with Yarn Workspaces
JavaScript
115
star
9

top-github

Android app for browsing GitHub top repositories
Java
95
star
10

firebase-recyclerview

Generic Firebase recyclerview list for Android
Java
91
star
11

react-native-beacons-android

A React-Native library for detecting beacons on Android
Java
73
star
12

the-starter-app

An in-depth tutorial about building mobile apps using React-Native
TypeScript
67
star
13

eslint-plugin-react-app

ESLint configuration used by Create React App
JavaScript
51
star
14

react-native-radio-button

Just a simple radio button
JavaScript
48
star
15

just-tap

A first test drive of hooks, redux and redux-saga in React-Native!
TypeScript
39
star
16

easy-bookmarks

Bookmarks saving and sharing app for Android (with Firebase)
Java
38
star
17

create-react-app-electron-boilerplate

JavaScript
34
star
18

alfred-jira-search

An Alfred workflow to search for Jira tickets
Shell
26
star
19

jira-express

Browser extension to quickly access your Jira tickets.
TypeScript
21
star
20

react-native-starter

React-Native/Redux/Parse
JavaScript
20
star
21

url-metadata-scraper

Tiny Vercel serverless function to scrape metadata from a URL
JavaScript
15
star
22

serverino

Tiny CLI-based static server
JavaScript
13
star
23

trees-and-tents-sample

React-Native implementation of the Trees and Tents puzzle game
JavaScript
13
star
24

build-it-bigger

Udacity Android Nanodegree: Project 4
Java
12
star
25

pinboard-api-proxy

Tiny proxy server to allow all origins to fetch the Pinboard API
JavaScript
11
star
26

reason-react-material-ui-demo

A simple form built with Reason React and Material UI
Reason
8
star
27

react-native-trello-login

Use Trello's API token-based authentication in React-Native
JavaScript
8
star
28

img-resizable

Resizable polymer <img>
HTML
6
star
29

which-one

A small React + Typescript + MobX game
TypeScript
6
star
30

some-react-native-components

components components components components components components components
4
star
31

visual-ui-testing-example

Using Playwright and GitHub action to automate visual UI testing
TypeScript
4
star
32

bookmarkpack-server

NodeJS/Express/Mongoose REST API server
JavaScript
3
star
33

multi-pacman

A multiplayer pacman for Android (Libgdx + Google Play Games Services)
Java
3
star
34

bookmarkpack-client-angular

JavaScript
2
star
35

touch-delay

Fixing the small (~100ms) touch delay on mobile
JavaScript
2
star
36

breathly-website

Breathly app landing page
HTML
2
star
37

polymer-scroll-threshold

aka core-scroll-threshold for polymer 1.0
HTML
2
star
38

miniexec

Minimalist approach to running shell commands in Deno
TypeScript
1
star
39

spotify-streamer-stage-2

Udacity Android Nanodegree: Project 2
Java
1
star
40

dotfiles

Simple dotfiles
Shell
1
star
41

react-toolbox-postcss-boilerplate

A minimal boilerplate for react-toolbox + postcss
JavaScript
1
star
42

quick-reminders-cli

Tiny Deno CLI to create new reminders in the Apple's Reminders app using a natural language parser
TypeScript
1
star