<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Bruno Lemos</title>
    <description>The latest articles on Forem by Bruno Lemos (@brunolemos).</description>
    <link>https://forem.com/brunolemos</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F50599%2F0e887544-4592-4882-afde-8d3f69135cc3.jpeg</url>
      <title>Forem: Bruno Lemos</title>
      <link>https://forem.com/brunolemos</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/brunolemos"/>
    <language>en</language>
    <item>
      <title>Adding Notch support to your React Native apps: Android, iOS &amp; Web</title>
      <dc:creator>Bruno Lemos</dc:creator>
      <pubDate>Sun, 01 Sep 2019 00:48:12 +0000</pubDate>
      <link>https://forem.com/brunolemos/adding-notch-support-to-your-react-native-android-app-3ci3</link>
      <guid>https://forem.com/brunolemos/adding-notch-support-to-your-react-native-android-app-3ci3</guid>
      <description>&lt;p&gt;In this tutorial we'll learn how to properly support notches (aka “display cutout”) on Android, iOS and Web with just a few lines of code.&lt;/p&gt;

&lt;p&gt;Here's our Android Emulator showing a &lt;code&gt;Double cutout&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F43d6q5g8xat0c80mzzl0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F43d6q5g8xat0c80mzzl0.png" alt="Android Emulator with Notches at the top and bottom"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you don't have an Android device with Notch, open an Android Emulator and emulate the display cutout by going to &lt;code&gt;Android Settings &amp;gt; System &amp;gt; Advanced &amp;gt; Developer options &amp;gt; Display cutout &amp;gt; Double cutout&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can see in the screenshot above that the wallpaper shows behind the notch. That is the correct behavior and your app should do it too.&lt;/p&gt;

&lt;p&gt;But let's see what happens when we render a simple app:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fx0kes5ij335w3anar4w4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fx0kes5ij335w3anar4w4.png" alt="black-bars-around-app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By default, the app does not handle the notches. You can see in the image above that it rendered two black bars, making the screen feel smaller to the user. That is not good, let's fix that.&lt;/p&gt;

&lt;p&gt;Here the fun starts. After researching and trying different methods for hours, I found out this is what you need to add to your &lt;code&gt;MainActivity.java&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;public class MainActivity extends ReactActivity {
&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="gi"&gt;+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        if (Build.VERSION.SDK_INT &amp;gt;= Build.VERSION_CODES.P) {
+            WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
+            layoutParams.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
+            getWindow().setAttributes(layoutParams);
+            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
+        }
+
+        super.onCreate(savedInstanceState);
+    }
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code does three things: set &lt;code&gt;layoutInDisplayCutoutMode&lt;/code&gt; to &lt;code&gt;edgeInsets&lt;/code&gt; to stop showing the black bars, and set both &lt;code&gt;status&lt;/code&gt; and &lt;code&gt;navigation&lt;/code&gt; to &lt;code&gt;translucent&lt;/code&gt; to render our app behind the notch and navigation buttons.&lt;/p&gt;

&lt;p&gt;Here's the result after adding this code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcr974dpqm5zku2k7uzkd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcr974dpqm5zku2k7uzkd.png" alt="content-render-behing-notch"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes! That is an improvement. Now we use the whole screen. But you can see the text content is being hidden by the notches. &lt;/p&gt;

&lt;p&gt;React Native has a built-in component called &lt;a href="https://facebook.github.io/react-native/docs/safeareaview" rel="noopener noreferrer"&gt;SafeAreaView&lt;/a&gt;. It fixes this exact issue, but... only on iPhone X. It still doesn't have Android support.&lt;/p&gt;

&lt;p&gt;Thanks to &lt;a href="https://twitter.com/janicduplessis" rel="noopener noreferrer"&gt;@janicduplessis&lt;/a&gt;, we can use &lt;a href="https://github.com/th3rdwave/react-native-safe-area-context" rel="noopener noreferrer"&gt;react-native-safe-area-context&lt;/a&gt;, that supports all platforms we want: iOS, Android and Web!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you use Expo, this lib will be included on SDK v35&lt;/p&gt;

&lt;p&gt;If you use react-native &amp;lt; 0.60, you can apply &lt;a href="https://gist.github.com/brunolemos/ec886065b695d54ba25af7de47475c90#file-react-native-safe-area-context-0-3-5-patch" rel="noopener noreferrer"&gt;this patch&lt;/a&gt; using &lt;a href="https://github.com/ds300/patch-package" rel="noopener noreferrer"&gt;patch-package&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The api looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;safeAreaInsets&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useSafeArea&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we add the paddings to the &lt;code&gt;View&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;
  &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;paddingTop&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;safeAreaInsets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;paddingBottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;safeAreaInsets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bottom&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;paddingLeft&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;safeAreaInsets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;paddingRight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;safeAreaInsets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here's the final result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbttzd6occxsuxnz7skdd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbttzd6occxsuxnz7skdd.png" alt="text-rendered-correctly"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It works perfectly 🎉🎉🎉 &lt;br&gt;
Android is ready, now let's see how our iOS app is looking:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fiu1l559zbtxig483pf5u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fiu1l559zbtxig483pf5u.png" alt="iPhone X rendering correctly"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;iOS is already perfect as well! 🎉 &lt;br&gt;
That's 2 out of 3. How about web? Let's see:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fh3wc0zcbizv5nteeqosy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fh3wc0zcbizv5nteeqosy.png" alt="screenshot-mobile-safari-black-bars"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hum, web is still showing the black bars. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If your app doesn’t support web yet, check out my other tutorial: &lt;a href="https://dev.to/brunolemos/tutorial-100-code-sharing-between-ios-android--web-using-react-native-web-andmonorepo-4pej"&gt;How to share code between iOS, Android &amp;amp; Web using React Native, react-native-web and monorepo&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But that is easy to fix, you just need to add &lt;code&gt;viewport-fit=cover&lt;/code&gt; to your &lt;code&gt;viewport&lt;/code&gt; meta tag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gd"&gt;-&amp;lt;meta name="viewport" content="width=device-width, initial-scale=1"&amp;gt;
&lt;/span&gt;&lt;span class="gi"&gt;+&amp;lt;meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fu3cg890xnzb3grah5tpf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fu3cg890xnzb3grah5tpf.png" alt="screenshot-mobile-safari-showing-correctly"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And voilà! Our app now properly supports notches on iOS, Android and Web! And again, it was this easy thanks to the awesome  &lt;a href="https://github.com/th3rdwave/react-native-safe-area-context" rel="noopener noreferrer"&gt;react-native-safe-area-context&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here's the &lt;a href="https://gist.github.com/brunolemos/ec886065b695d54ba25af7de47475c90" rel="noopener noreferrer"&gt;gist&lt;/a&gt; with the code above, the &lt;a href="https://twitter.com/brunolemos/status/1167963091167895552?s=20" rel="noopener noreferrer"&gt;tweet&lt;/a&gt; in case you want to retweet and my Twitter account: &lt;a href="https://twitter.com/brunolemos" rel="noopener noreferrer"&gt;@brunolemos&lt;/a&gt; 💚&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>react</category>
      <category>android</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Tutorial: How to share code between iOS, Android &amp; Web using React Native, react-native-web and monorepo</title>
      <dc:creator>Bruno Lemos</dc:creator>
      <pubDate>Wed, 06 Mar 2019 18:53:37 +0000</pubDate>
      <link>https://forem.com/brunolemos/tutorial-100-code-sharing-between-ios-android--web-using-react-native-web-andmonorepo-4pej</link>
      <guid>https://forem.com/brunolemos/tutorial-100-code-sharing-between-ios-android--web-using-react-native-web-andmonorepo-4pej</guid>
      <description>&lt;p&gt;Let's make our &lt;code&gt;react-native&lt;/code&gt; app work in the browser, the right way.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This tutorial was made for &lt;code&gt;react-native &amp;lt;= 0.61&lt;/code&gt;. If you are using a newer version, I recommend that you fork this repository instead: &lt;a href="https://github.com/brunolemos/react-native-web-monorepo" rel="noopener noreferrer"&gt;brunolemos/react-native-web-monorepo&lt;/a&gt;, I am keeping it updated 🙌&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Why am I writing this?
&lt;/h2&gt;

&lt;p&gt;Hi 👋 I'm &lt;a href="https://twitter.com/brunolemos" rel="noopener noreferrer"&gt;Bruno Lemos&lt;/a&gt;. I recently launched a project called &lt;a href="http://github.com/devhubapp/devhub" rel="noopener noreferrer"&gt;DevHub - TweetDeck for GitHub&lt;/a&gt; and one of the things that &lt;a href="https://twitter.com/brunolemos/status/1072871009651384320?s=21" rel="noopener noreferrer"&gt;caught people's attention&lt;/a&gt; was the fact that it is an app made by a single developer and available on 6 platforms: Web (react-native-web), iOS (&lt;code&gt;react native&lt;/code&gt;), Android (&lt;code&gt;react native&lt;/code&gt;), macOS, Windows and Linux (&lt;code&gt;electron&lt;/code&gt;, &lt;em&gt;for now&lt;/em&gt;), with almost 100% code sharing between them. It even shares some code with the server! This is something that would require a team of 3+ until a couple years ago.&lt;/p&gt;

&lt;p&gt;Since then, I've received dozens of tweets and private messages asking how to achieve the same and in this tutorial I'll walk you through it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's &lt;code&gt;react-native-web&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;If you are not familiar with &lt;a href="http://github.com/necolas/react-native-web" rel="noopener noreferrer"&gt;react-native-web&lt;/a&gt;, it's a lib by &lt;a href="https://twitter.com/necolas" rel="noopener noreferrer"&gt;Necolas&lt;/a&gt; (ex Twitter engineer) to make your &lt;code&gt;React Native&lt;/code&gt; code render in the browser. Roughly speaking, you will write &lt;code&gt;&amp;lt;View /&amp;gt;&lt;/code&gt; and it will render &lt;code&gt;&amp;lt;div /&amp;gt;&lt;/code&gt;, making sure all styles render the exact same thing. It does more than that, but let's keep it simple.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://mobile.twitter.com/" rel="noopener noreferrer"&gt;new Twitter&lt;/a&gt; was created using this technology and it's awesome.&lt;/p&gt;

&lt;p&gt;If you already know &lt;code&gt;react-native&lt;/code&gt;, you don't need to learn any new syntax. It's the &lt;a href="https://github.com/necolas/react-native-web#components" rel="noopener noreferrer"&gt;same API&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Starting a new &lt;code&gt;React Native&lt;/code&gt; project&lt;/li&gt;
&lt;li&gt;Turning our folder structure into a monorepo&lt;/li&gt;
&lt;li&gt;Making &lt;code&gt;react-native&lt;/code&gt; work in a monorepo&lt;/li&gt;
&lt;li&gt;Sharing code between our monorepo packages&lt;/li&gt;
&lt;li&gt;Creating a new web project using &lt;code&gt;create-react-app&lt;/code&gt; and &lt;code&gt;react-native-web&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Making &lt;code&gt;CRA&lt;/code&gt; work inside our &lt;code&gt;monorepo&lt;/code&gt; with code sharing&lt;/li&gt;
&lt;li&gt;???&lt;/li&gt;
&lt;li&gt;Profit&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step-by-step tutorial
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Starting a new &lt;code&gt;React Native&lt;/code&gt; project
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$ react-native init myprojectname&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$ cd myprojectname&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$ git init &amp;amp;&amp;amp; git add . -A &amp;amp;&amp;amp; git commit -m "Initial commit"&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: It's much easier to create a cross platform app from scratch than trying to port an existing mobile-only (or even harder: web-only) project, since they may be using lot's of platform specific dependencies.&lt;/p&gt;

&lt;p&gt;EDIT: If you use expo, it seems they will soon have &lt;a href="https://twitter.com/brunolemos/status/1105493974285017090?s=20" rel="noopener noreferrer"&gt;built in support for web&lt;/a&gt;!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Turning our folder structure into a monorepo
&lt;/h3&gt;

&lt;p&gt;Monorepo means having multiple packages in a single repository so you can easily share code between them.  It's a bit less trivial than it sounds because both &lt;code&gt;react-native&lt;/code&gt; and &lt;code&gt;create-react-app&lt;/code&gt; require some work to support monorepo projects. But hey, at least it's possible!&lt;/p&gt;

&lt;p&gt;We'll use a feature called &lt;code&gt;Yarn Workspaces&lt;/code&gt; for that.&lt;br&gt;
Requirements: &lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt;, &lt;a href="https://yarnpkg.com/lang/en/docs/install/" rel="noopener noreferrer"&gt;Yarn&lt;/a&gt; and &lt;a href="https://facebook.github.io/react-native/docs/getting-started.html" rel="noopener noreferrer"&gt;React Native&lt;/a&gt;. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Make sure you are at the project root folder&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$ rm yarn.lock &amp;amp;&amp;amp; rm -rf node_modules&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$ mkdir -p packages/components/src packages/mobile packages/web&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Move all the files (except &lt;code&gt;.git&lt;/code&gt;) to the &lt;code&gt;packages/mobile&lt;/code&gt; folder&lt;/li&gt;
&lt;li&gt;Edit the &lt;code&gt;name&lt;/code&gt; field on &lt;code&gt;packages/mobile/package.json&lt;/code&gt; from &lt;code&gt;packagename&lt;/code&gt; to &lt;code&gt;mobile&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create this &lt;code&gt;package.json&lt;/code&gt; at the root directory to enable &lt;code&gt;Yarn Workspaces&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"myprojectname"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"private"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"workspaces"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"packages"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"packages/*"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"nohoist"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"react-native"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0.61.3"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create a &lt;code&gt;.gitignore&lt;/code&gt; at the root directory:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.DS_Store
.vscode
node_modules/
yarn-error.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$ yarn&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Making react-native work in a monorepo
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Check where &lt;code&gt;react-native&lt;/code&gt; got installed. If it was at &lt;code&gt;/node_modules/react-native&lt;/code&gt;, all right. If it was at &lt;code&gt;/packages/mobile/node_modules/react-native&lt;/code&gt;, something is wrong. Make sure you have the latest versions of &lt;code&gt;node&lt;/code&gt; and &lt;code&gt;yarn&lt;/code&gt;. Also make sure to use the exact same version of dependencies between the monorepo packages, e.g. &lt;code&gt;"react": "16.11.0"&lt;/code&gt; on both &lt;code&gt;mobile&lt;/code&gt; and &lt;code&gt;components&lt;/code&gt;, not a different version between them.&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open your favorite editor and use the &lt;code&gt;Search &amp;amp; Replace&lt;/code&gt; feature to replace all occurrences of &lt;code&gt;node_modules/react-native/&lt;/code&gt; with &lt;code&gt;../../node_modules/react-native/&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For react-native &amp;lt;= 0.59, open &lt;code&gt;packages/mobile/package.json&lt;/code&gt;. Your &lt;code&gt;start&lt;/code&gt; script currently ends in &lt;code&gt;/cli.js start&lt;/code&gt;. Append this to the end: &lt;code&gt;--projectRoot ../../&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open &lt;code&gt;packages./mobile/metro.config.js&lt;/code&gt; and set the &lt;code&gt;projectRoot&lt;/code&gt; field on it as well so it looks like this:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;projectRoot&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../../&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="na"&gt;transformer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;getTransformOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;experimentalImportSupport&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;inlineRequires&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;[Workaround] You currently need to add the &lt;code&gt;react-native&lt;/code&gt; dependency to the root &lt;code&gt;package.json&lt;/code&gt; to be able to bundle the JS:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"react-native"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0.61.3"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  iOS changes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$ open packages/mobile/ios/myprojectname.xcodeproj/&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Open &lt;code&gt;AppDelegate.m&lt;/code&gt;, find &lt;code&gt;jsBundleURLForBundleRoot:@"index"&lt;/code&gt; and replace &lt;code&gt;index&lt;/code&gt; with &lt;code&gt;packages/mobile/index&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Still inside Xcode, click on your project name on the left, and then go to &lt;code&gt;Build Phases&lt;/code&gt; &amp;gt; &lt;code&gt;Bundle React Native code and Images&lt;/code&gt;. Replace its content with this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;NODE_BINARY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;node
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;EXTRA_PACKAGER_ARGS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"--entry-file packages/mobile/index.js"&lt;/span&gt;
../../../node_modules/react-native/scripts/react-native-xcode.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$ yarn workspace mobile start&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can now run the iOS app! 💙 Choose one iPhone emulator and press the "Run" triangle button inside Xcode.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9fe1epdoqhbl680156lq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9fe1epdoqhbl680156lq.png" alt="image" width="800" height="1731"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Android changes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$ studio packages/mobile/android/&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Open &lt;code&gt;packages/mobile/android/app/build.gradle&lt;/code&gt;. Search for the text &lt;code&gt;project.ext.react = [...]&lt;/code&gt;. Edit it so it looks like this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gradle"&gt;&lt;code&gt;&lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ext&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;react&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
    &lt;span class="nl"&gt;entryFile:&lt;/span&gt; &lt;span class="s2"&gt;"packages/mobile/index.js"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;root:&lt;/span&gt; &lt;span class="s2"&gt;"../../../../"&lt;/span&gt;
&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Android Studio will show a Sync Now popup. Click on it.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Open &lt;code&gt;packages/mobile/android/app/src/main/java/com/myprojectname/MainApplication.java&lt;/code&gt;. Search for the &lt;code&gt;getJSMainModuleName&lt;/code&gt; method. Replace &lt;code&gt;index&lt;/code&gt; with &lt;code&gt;packages/mobile/index&lt;/code&gt;, so it looks like this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Override&lt;/span&gt;
&lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getJSMainModuleName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"packages/mobile/index"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;If you get the &lt;code&gt;Cannot get property 'packageName' on null object&lt;/code&gt; error, try &lt;a href="https://github.com/react-native-community/cli/issues/655" rel="noopener noreferrer"&gt;disabling auto linking&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can now run the Android app! 💙 Press the "Run" green triangle button inside Android Studio and choose the emulator or device.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmmyfithtgnb8h2dbvm0b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmmyfithtgnb8h2dbvm0b.png" alt="image" width="800" height="1600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Sharing code between our monorepo packages
&lt;/h3&gt;

&lt;p&gt;We've created lots of folders in our monorepo, but only used &lt;code&gt;mobile&lt;/code&gt; so far. Let's prepare our codebase for code sharing and then move some files to the &lt;code&gt;components&lt;/code&gt; package, so it can be reused by &lt;code&gt;mobile&lt;/code&gt;, &lt;code&gt;web&lt;/code&gt; and any other platform we decide to support in the future (e.g.: &lt;code&gt;desktop&lt;/code&gt;, &lt;code&gt;server&lt;/code&gt;, etc.).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create the file &lt;code&gt;packages/components/package.json&lt;/code&gt; with the following contents:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"components"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"private"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;[optional] If you decide to support more platforms in the future, you'll do the same thing for them: Create a &lt;code&gt;packages/core/package.json&lt;/code&gt;, &lt;code&gt;packages/desktop/package.json&lt;/code&gt;, &lt;code&gt;packages/server/package.json&lt;/code&gt;, etc. The name field must be unique for each one.&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open &lt;code&gt;packages/mobile/package.json&lt;/code&gt;. Add all the monorepo packages that you are using as dependencies. In this tutorial, &lt;code&gt;mobile&lt;/code&gt; is only using the &lt;code&gt;components&lt;/code&gt; package:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"components"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Stop the react-native packager if it's running&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$ yarn&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$ mv packages/mobile/App.js packages/components/src/&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Open &lt;code&gt;packages/mobile/index.js&lt;/code&gt;. Replace &lt;code&gt;import App from './App'&lt;/code&gt; with &lt;code&gt;import App from 'components/src/App'&lt;/code&gt;. &lt;em&gt;This is the magic working right here. One package now have access to the others!&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Edit &lt;code&gt;packages/components/src/App.js&lt;/code&gt;, replace &lt;code&gt;Welcome to React Native!&lt;/code&gt; with &lt;code&gt;Welcome to React Native monorepo!&lt;/code&gt; so we know we are rendering the correct file.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$ yarn workspace mobile start&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Yay! You can now refresh the running iOS/Android apps and see our screen that's coming from our shared components package. 🎉&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$ git add . -A &amp;amp;&amp;amp; git commit -m "Monorepo"&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Web project
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: You can reuse up to 100% of the code, but that doesn't mean you should. It's recommended to have some differences between platforms to make them feel more natural to the user. To do that, you can create platform-specific files ending with &lt;code&gt;.web.js&lt;/code&gt;, &lt;code&gt;.ios.js&lt;/code&gt;, &lt;code&gt;.android.js&lt;/code&gt; or &lt;code&gt;.native.js&lt;/code&gt;. See &lt;a href="https://github.com/devhubapp/devhub/tree/v0.90.0/packages/components/src/libs/bugsnag" rel="noopener noreferrer"&gt;example&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Creating a new web project using CRA and react-native-web
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$ cd packages/&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$  npx create-react-app web&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;$ cd ./web&lt;/code&gt; &lt;em&gt;(stay inside this folder for the next steps)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;$ rm src/*&lt;/code&gt; &lt;em&gt;(or manually delete all files inside &lt;code&gt;packages/web/src&lt;/code&gt;)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Make sure the dependencies inside &lt;code&gt;package.json&lt;/code&gt; are the exact same between all monorepo packages. For example, update the "react" version to "16.9.0" (or any other version) on both &lt;code&gt;web&lt;/code&gt; and &lt;code&gt;mobile&lt;/code&gt; packages.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$ yarn add react-native-web react-art&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$ yarn add --dev babel-plugin-react-native-web&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Create the file &lt;code&gt;packages/web/src/index.js&lt;/code&gt; with the following contents:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AppRegistry&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-native&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;components/src/App&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;AppRegistry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;registerComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;myprojectname&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;AppRegistry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;runApplication&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;myprojectname&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;rootTag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note: when we import from &lt;code&gt;react-native&lt;/code&gt; inside a &lt;code&gt;create-react-app&lt;/code&gt; project, its &lt;code&gt;webpack&lt;/code&gt; config automatically &lt;a href="https://github.com/facebook/create-react-app/blob/ff19e0a6d22ba070f5b4c3b511edb4e8d4995686/packages/react-scripts/config/webpack.config.js#L274-L278" rel="noopener noreferrer"&gt;alias it to &lt;code&gt;react-native-web&lt;/code&gt;&lt;/a&gt; for us.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Create the file &lt;code&gt;packages/web/public/index.css&lt;/code&gt; with the following contents:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nf"&gt;#root&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nf"&gt;#root&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;-webkit-font-smoothing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;antialiased&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;-moz-osx-font-smoothing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grayscale&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Edit &lt;code&gt;packages/web/public/index.html&lt;/code&gt; to include our CSS before closing the &lt;code&gt;head&lt;/code&gt; tag:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;...
&lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;React App&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"%PUBLIC_URL%/index.css"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Making CRA work inside our monorepo with code sharing
&lt;/h3&gt;

&lt;p&gt;CRA doesn't build files outside the &lt;code&gt;src&lt;/code&gt; folder by default. We need to make it do it, so it can understand the code from our monorepo packages, which contains JSX and other non-pure-JS code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Stay inside &lt;code&gt;packages/web/&lt;/code&gt; for the next steps&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Create a &lt;code&gt;.env&lt;/code&gt; file (&lt;code&gt;packages/web/.env&lt;/code&gt;) with the following content:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SKIP_PREFLIGHT_CHECK=true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$ yarn add --dev react-app-rewired&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Replace the scripts inside &lt;code&gt;packages/web/package.json&lt;/code&gt; with this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"react-app-rewired start"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"react-app-rewired build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"react-app-rewired test"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"eject"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"react-app-rewired eject"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create the &lt;code&gt;packages/web/config-overrides.js&lt;/code&gt; file with the following contents:

 &lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;webpack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;webpack&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;appDirectory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;realpathSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cwd&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;resolveApp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;relativePath&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;appDirectory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;relativePath&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// our packages that will now be included in the CRA build step&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;appIncludes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="nf"&gt;resolveApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;src&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nf"&gt;resolveApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../components/src&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;override&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// allow importing from outside of src folder&lt;/span&gt;
  &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;plugins&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;plugin&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;plugin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ModuleScopePlugin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;include&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;appIncludes&lt;/span&gt;
  &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
  &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;oneOf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;include&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;appIncludes&lt;/span&gt;
  &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;oneOf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;plugins&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;babel-plugin-react-native-web&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;oneOf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rules&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;webpack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DefinePlugin&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;__DEV__&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;env&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;production&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The code above overrides some &lt;code&gt;create-react-app&lt;/code&gt;'s &lt;code&gt;webpack&lt;/code&gt; config so it includes our monorepo packages in CRA's build step&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$ git add . -A &amp;amp;&amp;amp; git commit -m "Web project"&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's it! You can now run &lt;code&gt;yarn start&lt;/code&gt; inside &lt;code&gt;packages/web&lt;/code&gt; (or &lt;code&gt;yarn workspace web start&lt;/code&gt; at the root directory) to start the web project, sharing code with our &lt;code&gt;react-native&lt;/code&gt; &lt;code&gt;mobile&lt;/code&gt; project! 🎉&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flqy3yqqkd0mefe6dky2h.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flqy3yqqkd0mefe6dky2h.jpg" alt="image" width="800" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Some gotchas
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;react-native-web&lt;/code&gt; supports most of the &lt;code&gt;react-native&lt;/code&gt; API, but a few pieces are missing like &lt;code&gt;Alert&lt;/code&gt;, &lt;code&gt;Modal&lt;/code&gt;, &lt;code&gt;RefreshControl&lt;/code&gt; and &lt;code&gt;WebView&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;If you come across a dependency that doesn't work well with the monorepo structure, you may add it to the &lt;a href="https://yarnpkg.com/blog/2018/02/15/nohoist/" rel="noopener noreferrer"&gt;nohoist&lt;/a&gt; list; But avoid that if possible, because it may cause other issues, specially with the metro bundler.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Some tips
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Navigation may be a bit of a challenge; you can use something like &lt;a href="https://github.com/react-navigation/react-navigation" rel="noopener noreferrer"&gt;react-navigation&lt;/a&gt; which recently added web support or you can try using two different navigators between and mobile, in case you want the best of both worlds by compromising some code sharing;&lt;/li&gt;
&lt;li&gt;If you plan sharing code with the server, I recommend creating a &lt;code&gt;core&lt;/code&gt; package that only contain logic and helper functions (no UI-related code);&lt;/li&gt;
&lt;li&gt;For Next.js, you can check their &lt;a href="https://github.com/zeit/next.js/tree/master/examples/with-react-native-web" rel="noopener noreferrer"&gt;official example with react-native-web&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;For native windows, you can try &lt;a href="https://github.com/Microsoft/react-native-windows" rel="noopener noreferrer"&gt;react-native-windows&lt;/a&gt;;&lt;/li&gt;
&lt;li&gt;For native macOS, you can the new Apple Project Catalyst, but support for it is not 100% there yet (&lt;a href="https://twitter.com/brunolemos/status/1185636022346043392?s=20" rel="noopener noreferrer"&gt;see my tweet&lt;/a&gt;);&lt;/li&gt;
&lt;li&gt;To install new dependencies, use the command &lt;code&gt;yarn workspace components add xxx&lt;/code&gt; from the root directory. To run a script from a package, run &lt;code&gt;yarn workspace web start&lt;/code&gt;, for example; To run a script from all packages, run &lt;code&gt;yarn workspaces run scriptname&lt;/code&gt;;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading! 💙&lt;/p&gt;

&lt;p&gt;If you like react, consider following me here on Dev.to and on &lt;a href="https://twitter.com/brunolemos" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Source code: &lt;a href="https://github.com/brunolemos/react-native-web-monorepo" rel="noopener noreferrer"&gt;react-native-web-monorepo&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;DevHub: &lt;a href="http://github.com/devhubapp/devhub" rel="noopener noreferrer"&gt;devhubapp/devhub&lt;/a&gt; (production app using this structure + Desktop + TypeScript)&lt;/li&gt;
&lt;li&gt;Twitter: &lt;a href="https://twitter.com/brunolemos" rel="noopener noreferrer"&gt;@brunolemos&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
