This is an monorepo for React and React Native which can be used as boilerplate. It comes with out-of-box configurations for
-
Web:
- Create React App: Use an integrated toolchain for the best user and developer experience.
- @reach/router: A small and simple router.
- react-app-rewired: Tweak the Create React App webpack config(s) without using 'eject'.
-
Native (iOS and Android):
- react-native: Create native apps for Android and iOS using React.
- react-native-splash-screen: A splash screen API for react-native which can programatically hide and show the splash screen. Works on iOS and Android.
- @react-navigation/native: A navigation framework for react-native.
- @react-navigation/stack: Stack-navigation for @react-navigation/native.
-
Shared by both:
- redux: A Predictable State Container for JS Apps.
- react-redux: Official React bindings for Redux.
- [redux-thunk]: Async action middleware for redux.
- eslint and prettier: Find and fix problems in your JavaScript code.
- husky and lint-staged: Beautify code (staged) before every commit.
- Absolute imports for react and react-native.
It has preconfigured native Google SignIn, Push Notifications for all platforms (iOS, Android, Web). Also have redux persist for saving redux state of application so that user can start where they left. See its guide here.
git clone https://github.com/Faisal-Manzer/react-and-react-native-monorepo.git --branch advanced --single-branch
# clone this repo
git clone https://github.com/Faisal-Manzer/react-and-react-native-monorepo.git
yarn install
: For installing dependencies run.
yarn pods
: If you have [xcode] and Cocapods installed (needed for iOS development) run to install iOS dependencies.
yarn clean
: Will delete all node_modules and pods and the app will be ready for any fresh install.
yarn start
: Will start Create React App's development server and react-native bundler.
yarn native
: Will manually start metro server for react-native.
yarn web
: Will manually start Create React App's development server. (NOTE: already started if you ran yarn start
).
yarn android
: For running app on android emulator or android device.
yarn ios
: For running app on iOS simulator.
yarn studio
: Will open android project in android studio.
yarn xcode
: Will open android project in android studio.
# clone the repo
git clone https://github.com/Faisal-Manzer/react-and-react-native-monorepo.git app
cd app
# install dependencies
yarn install
# install iOS dependencies
yarn pod
# manually start react-native bundeller
yarn start
# run Web/Android/iOS
yarn ios
yarn android
# Web already started with `yarn start` but you can manually start
yarn web
# open in Android Studio/XCode
yarn studio
yarn xcode
# clean and reinstall
yarn clean
yarn install
yarn pod
Your app is opening but it stuck because it is loading js bundel. Once its will load the app will start.
All shared code should reside in common
folder. Containers, hooks, actions, helper logic all can reside under common
except UI.
// common/helpers.js
export const myLogic = (someArgs) => {
// some code
}
Now in web or native file you can
import { myLogic } from 'common/helpers'
Now for importing it you can using
You can use import from common
with it's name, i.e.:
import {} from 'common/component/HelloMonorepo';
React comes out of the box imports for all subdirectories of src
.
import {} from 'components/MonorepoIntroduction';
For RN absolute import you can use directly for all subdirectories of src
.
import {} from 'components/MonorepoIntroduction';
- If there is any dependency which is isolated to web or native then there will be no issues with it. If issue comes try adding dependency to
nohoist
in respectivepackage.json
and then clean installyarn clean && yarn install && yarn pods
. - If dependency is shared with common sometimes the dependency can conflict. If issue comes first try adding dependency to
nohoist
in respectivepackage.json
and then clean installyarn clean && yarn install && yarn pods
. If the issue doesn't resolve there you should addalias
for those dependency. React redux is one example of aliased dependencies.
Open web/config-overrides.js
add alias for the dependency. Alias is resolving the path of dependency. If dependency is in nohoist
then it will be in web/node_modules
or else in root level node_modules
.
See example of react-redux
.
Open native/config-overrides.js
add alias for the dependency as extraNodeModules
. If dependency is in nohoist
then it will be in web/node_modules
or else in root level node_modules
.
See example of react-redux
. Recommended to add that dependency to nohoist
.
-
Create an icon with size 1024x1024 pixels.
-
Bake Android and iOS icons (can use makeicon) and web icons (can use favicon-generator).
-
Copy new
android
icon tonative/android/app/src/main/res/
. Replace allic_launcher.png
from respective folders. -
Also bake Round icons for android (use makeicon). Replace all
ic_launcher_round.png
from respective folders. -
Run
yarn xcode
or open correct.xcworkspace
in xcode. Go to<project>/<project>/Images.xcassets
and drag and drop all. -
Replace all web icons to
web/public/logos/
. -
For adaptive icons in Android Replace
ic_laucher_foreground.png
innative/android/app/src/main/res/
. And change it's bg color innative/android/app/src/main/res/values/ic_launcher_background.xml
# clean
yarn clean
cd packages/native
# in native directory
npx react-native-rename <newAppName> -b <bundleIdentifier>
cd -
# install depedencies
yarn install
# install ios dependencies
yarn pod
- to Fix
xcode
script innative/package.json
, Editxcode
fromopen ios/monorepo.xcworkspace
toopen ios/<newAppName>.xcworkspace
- Run
yarn xcode
- Go to project's Build Settings
- Edit bundle identifier and app name
- (In web directory)
- Open
src/public/manifest.json
- Edit
short_name
andname
- Create an splash screen banner with size 240x240 pixels for both iOS and Android and convert them to respective sizes.
- For Android:
- Replace all splash_icon in
native/android/app/src/main/res/mipmap-*/splash_icon.png
with your images. - Edit your theme color in
native/android/app/src/main/res/values/colors.xml
editprimary_dark
color code.
- Replace all splash_icon in
- For iOS:
- Open xcode
yarn xcode
. - Replace all images in
<project>/<project>/Images.xcassets/SplashScreen
. - Choose
<project>/<project>/LaunchScreen.xib
. Click anywhere in view. - Select
Attribute inspector
(icon of it is somewhat like pin). Choose your background color.
- Open xcode