{"id":16458339,"url":"https://github.com/flexbox/react-native-universal-monorepo","last_synced_at":"2025-04-29T00:31:00.179Z","repository":{"id":41833921,"uuid":"486091527","full_name":"flexbox/react-native-universal-monorepo","owner":"flexbox","description":"Exploring monorepo with React Native / nextjs / iOS / Android / redux / native-base from @mmazzarolo","archived":false,"fork":false,"pushed_at":"2022-05-17T12:44:43.000Z","size":6049,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-12T10:44:50.712Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flexbox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-27T07:32:53.000Z","updated_at":"2023-03-08T15:39:06.000Z","dependencies_parsed_at":"2022-08-11T18:51:07.951Z","dependency_job_id":null,"html_url":"https://github.com/flexbox/react-native-universal-monorepo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flexbox%2Freact-native-universal-monorepo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flexbox%2Freact-native-universal-monorepo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flexbox%2Freact-native-universal-monorepo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flexbox%2Freact-native-universal-monorepo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flexbox","download_url":"https://codeload.github.com/flexbox/react-native-universal-monorepo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224140843,"owners_count":17262754,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T10:44:58.864Z","updated_at":"2024-11-11T16:40:37.283Z","avatar_url":"https://github.com/flexbox.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Native Universal Monorepo\n\nAn opinonated approach to supporting multiple platforms with React Native using a Yarn Workspaces monorepo.  \n\nCheck out __[Running React Native everywhere](https://mmazzarolo.com/blog/2021-09-11-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.  \n- [Overview](https://mmazzarolo.com/blog/2021-09-11-running-react-native-everywhere/)\n- [Yarn Workspaces monorepo setup](https://mmazzarolo.com/blog/2021-09-12-running-react-native-everywhere-monorepo/)\n- [Android \u0026 iOS](https://mmazzarolo.com/blog/2021-09-18-running-react-native-everywhere-mobile/)\n- [Windows \u0026 macOS](https://mmazzarolo.com/blog/2021-09-19-running-react-native-everywhere-windows-macos/)\n- [The Web](https://mmazzarolo.com/blog/2021-09-22-running-react-native-everywhere-web/)\n- [Browser Extensions \u0026 Electron](https://mmazzarolo.com/blog/2021-09-25-running-react-native-everywhere-electron-browser-ext/)\n\n\u0026nbsp;\n\n\u003cp align=\"center\" margin-bottom=\"0\"\u003e\n  \u003cimg width=\"820\" height=\"auto\" src=\"./.github/images/all-screenshot.png\"\u003e\n\u003c/p\u003e\n\n## Overview\n\nThis monorepo uses [Yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/) and [TypeScript](https://www.typescriptlang.org/) to support a modular React Native project.  \n\nThe core idea is to isolate the JavaScript app code from the platform configurations (native code + the app bundlers like Metro and Webpack).  \nThis isolation happens by using different [workspaces](https://classic.yarnpkg.com/en/docs/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.  \n\nWe fully embrace [Yarn `nohoist`](https://classic.yarnpkg.com/blog/2018/02/15/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.  \nThanks nohoist, each platform workspace (`mobile`, `macos`, etc.) can depend on any React Native version, regardless of what version the other platform workspaces are using. \nFor example, we can use `react-native@0.65` on the mobile app and `react-native@0.63` on the macOS app — as long as the JavaScript app code supports both versions.  \nThis approach promotes gradual React Native updates over updates in lockstep.  \n\nFor more details, check out [\"Running React Native everywhere: Yarn Workspaces monorepo setup\"](https://mmazzarolo.com/blog/2021-09-12-running-react-native-everywhere-monorepo/).  \n\n\u003e ⚠️ 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 :)\n\n## Supported platforms\n\n- Android (React Native 0.65)\n- iOS (React Native 0.65)\n- Windows (React Native 0.65)\n- MacOS (React Native 0.63)\n- Android TV (React Native 0.65)\n- tvOS (React Native 0.65)\n- Web (React Native 0.65)\n- Web - Browser Extension (React Native 0.65)\n- Web - Electron (React Native 0.65)\n- Web - Next.js (React Native 0.65)\n\n## Getting started\n\nYou 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. \n\n### Using this repository as a boilerplate\n\n1. Clone the repository: `git@github.com:mmazzarolo/react-native-universal-monorepo.git`\n2. Run yarn install `cd react-native-universal-monorepo \u0026\u0026 yarn` \n\n### Create this setup from scratch\n\nStep by step tutorial on creating this repository from scratch: \n\n- [Overview](https://mmazzarolo.com/blog/2021-09-11-running-react-native-everywhere/)\n- [Yarn Workspaces monorepo setup](https://mmazzarolo.com/blog/2021-09-12-running-react-native-everywhere-monorepo/)\n- [Android \u0026 iOS](https://mmazzarolo.com/blog/2021-09-18-running-react-native-everywhere-mobile/)\n- [Windows \u0026 macOS](https://mmazzarolo.com/blog/2021-09-19-running-react-native-everywhere-windows-macos/)\n- [The Web](https://mmazzarolo.com/blog/2021-09-22-running-react-native-everywhere-web/)\n- [Browser Extensions \u0026 Electron](https://mmazzarolo.com/blog/2021-09-25-running-react-native-everywhere-electron-browser-ext/)\n\nTutorial for the TV and Next.js platforms from [@thefinnomenon](https://github.com/thefinnomenon):  \n- [Adding tvOS \u0026 Android TV Support to Monorepo](https://finnternet.com/dev/blog/react-native-tv-monorepo)\n- [Next.js in React-Native Monorepo](https://finnternet.com/dev/blog/nextjs-monorepo)\n\nAdditional resources:  \n- [Run your React Native app on the web with React Native for Web\n](https://mmazzarolo.com/blog/2020-10-24-adding-react-native-web/)\n- [Building a desktop application using Electron and Create React App](https://mmazzarolo.com/blog/2021-08-12-building-an-electron-application-using-create-react-app/)\n- [Developing a browser extension with Create React App](https://mmazzarolo.com/blog/2019-10-19-browser-extension-development/)\n\n## Available commands\n\nDevelopment and build commands:\n\n- `yarn android:metro`: Start the metro server for Android/iOS\n- `yarn android:start`: Start developing the Android app\n- `yarn android:studio`: Open the android app on Android Studio\n- `yarn ios:metro`: Start the metro server for Android/iOS\n- `yarn ios:start`: Start developing the iOS app\n- `yarn ios:pods`: Install iOS cocoapods dependencies\n- `yarn ios:xcode`: Open the iOS app on XCode\n- `yarn macos:metro`: Start the metro server for macOS\n- `yarn macos:start`: Start developing the macOS app\n- `yarn macos:pods`: Install macOS cocoapods dependencies\n- `yarn macos:xcode`: Open the macOS app on XCode\n- `yarn web:start`: Start developing the web app\n- `yarn web:build`: Create a production build of the web app\n- `yarn electron:start`: Start developing the Electron app\n- `yarn electron:package:mac`: Package the production binary of the Electron app for macOS\n- `yarn electron:package:win`: Package the production binary of the Electron app for windows\n- `yarn electron:package:linux`: Package the production binary of the Electron app for linux\n- `yarn browser-ext:start`: Start developing the browser extension\n- `yarn browser-ext:build`: Create a production build of the browser extension\n- `yarn windows:metro`: Start the metro server for Windows\n- `yarn windows:start`: Start developing the Windows app\n- `yarn tv:android:metro`: Start the metro server for Android TV\n- `yarn tv:android:start`: Start developing the Android TV app\n- `yarn tv:android:studio`: Open the Android TV app in Android Studio\n- `yarn tv:tvos:metro`: Start the metro server for tvOS\n- `yarn tv:tvos:start`: Start developing the tvOS app\n- `yarn tv:tvos:xcode`: Open the tvOS app in XCode\n- `yarn tv:tvos:pods`: Install tvOS cocoapods dependencies\n- `yarn next:start`: Start the Next.js app\n- `yarn next:build`: Build the Next.js app\n- `yarn next:serve`: Serve the Next.js app build\n\nOther commands (we use [ultra-runner](https://github.com/folke/ultra-runner) to run these commands on all workspaces): \n\n- `yarn lint`: Lint each project\n- `yarn lint:fix`: Lint + fix each project\n- `yarn test`: Run tests of each project\n- `yarn typecheck`: Run the TypeScript type-checking on each project\n\n\n## Native dependencies\n\nWhile 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`).  \nThis is not an issue with the approach used in this project per se. It's more of a common problem with monorepos.  \n\nTo fix these issues, [we mark them as nohoist](https://classic.yarnpkg.com/blog/2018/02/15/nohoist/), so they will be installed in each package that depends on them.  \n\nIn this monorepo, you can see an example of such libraries in `react-native-async-storage`.  \n\nIn the metro bundler and Webpack configs used across the monorepo, [we're using a set of build-tools](https://github.com/mmazzarolo/react-native-monorepo-tools/) to ensure nohoisted packages are resolved correctly.  \nSo, as long as you add these libraries [to the `nohoist` list](https://github.com/mmazzarolo/react-native-universal-monorepo/blob/a7dcfcbe7c7df66f6d11f06dd13f51ff94b1e70c/package.json#L9-L19), you should be good to go 👍  \n\n## Yarn Classic vs Yarn 2+\n\nWe're striving to make this setup compatible with Yarn Classic — but, [with a few tweaks](https://yarnpkg.com/getting-started/migration), it's compatible with Yarn 2+ as well (providing all Yarn 2+ benefits).  \nSee [#22](https://github.com/mmazzarolo/react-native-universal-monorepo/issues/22) for more info. \n\n## Setting up Yarn 2+\n\n1. Run `yarn set version berry` at the root of project. It will create a `.yarnrc.yml` file. \n2. Add the following lines to `.yarnrc.yml` to ensure `node_modules` directories are all created in each workspace:\n```yml\nnodeLinker: node-modules\nnmHoistingLimits: workspaces\n```\n3. `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`. \n\nCheck out [Yarn 2+'s \"getting started\" guide](https://yarnpkg.com/getting-started/install) for more info.  \n\n\n## Known issues\n\nIn some cases, Yarn Classic won't be able to resolve correctly dependencies that have a `peerDependency` on `react-native`.  \nSee [#22](https://github.com/mmazzarolo/react-native-universal-monorepo/issues/22) for a few workarounds. A fix on the `react-native-monorepo-tools` repo [is on the work](https://github.com/mmazzarolo/react-native-monorepo-tools/issues/9). \n\n## Contributing\n\nContributions, discussions, and feedback are welcome! Please ask if there are any active plans on feature changes before submitting new PRs 👍\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflexbox%2Freact-native-universal-monorepo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflexbox%2Freact-native-universal-monorepo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflexbox%2Freact-native-universal-monorepo/lists"}