<?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>DEV Community: Vince Picone</title>
    <description>The latest articles on DEV Community by Vince Picone (@vpicone).</description>
    <link>https://dev.to/vpicone</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%2F91280%2Fa9d070e7-a507-4edc-9a8d-9016c31f5274.jpeg</url>
      <title>DEV Community: Vince Picone</title>
      <link>https://dev.to/vpicone</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vpicone"/>
    <language>en</language>
    <item>
      <title>How to ship static assets with your React Native library</title>
      <dc:creator>Vince Picone</dc:creator>
      <pubDate>Sat, 11 Jul 2020 20:45:23 +0000</pubDate>
      <link>https://dev.to/vpicone/how-to-ship-static-assets-with-your-react-native-library-22pf</link>
      <guid>https://dev.to/vpicone/how-to-ship-static-assets-with-your-react-native-library-22pf</guid>
      <description>&lt;h1&gt;
  
  
  Background
&lt;/h1&gt;

&lt;p&gt;Work on React Native is moving at an incredible. Incredible, fresh features are being shipped regularly with more and more large tech companies pitching in.&lt;/p&gt;

&lt;p&gt;One issue with the speed of this development, however, is that things change pretty rapidly. You might find conflicting answers to a problem you run into and you'll need to suss out which one is the most modern/correct solution. This is the situation I found myself in when I was trying to find the best way to ship some font files (&lt;a href="https://ibm.com/plex"&gt;Plex&lt;/a&gt;) with the component library I'm working on (&lt;a href="https://www.carbondesignsystem.com"&gt;Carbon&lt;/a&gt;).&lt;/p&gt;

&lt;h1&gt;
  
  
  The Solution
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create an &lt;code&gt;assets&lt;/code&gt; (or call it whatever you like) directory with your font files/static assets the root of your project. You can also throw it under &lt;code&gt;src&lt;/code&gt; or somewhere else, you'll just need to update the path in the next step.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Also in the root of your package add a &lt;code&gt;react-native.config.js&lt;/code&gt; file with the following:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// react-native-config.js&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;dependency&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;assets&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;assets&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="c1"&gt;// or whatever your directory is&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;ol&gt;
&lt;li&gt;&lt;p&gt;After installing your package, developers will just need to run &lt;code&gt;npx react-native link my-special-package&lt;/code&gt; in the root of their project (replacing &lt;code&gt;my-special-package&lt;/code&gt; with the name of your library). Update your docs to add this step accordingly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;React native will update the corresponding native files in their projects and allow them to be referenced accordingly.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Wrap up/caveats
&lt;/h1&gt;

&lt;p&gt;This felt really clean solution and allowed me to keep working on my package. The dependent package I used was generated using &lt;code&gt;@react-native-community/cli&lt;/code&gt;, I haven't experimented with an expo package just yet.&lt;/p&gt;

&lt;p&gt;I'd love to here how other folks have dealt with this or other React Native problems.&lt;/p&gt;

&lt;h1&gt;
  
  
  Resources
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/react-native-community/bob"&gt;react-native-community/bob&lt;/a&gt;
Essential tool for packaging React Native modules for publishing&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://engineering.brigad.co/react-native-monorepos-code-sharing-f6c08172b417"&gt;React Native — Monorepos &amp;amp; Code Sharing&lt;/a&gt;
Great medium article for setting up React Native in a monorepo&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/oblador/react-native-vector-icons"&gt;react-native-vector-icons&lt;/a&gt;
Awesome library that loads assets in a variety of ways. They need to support older React Native versions, so you'll see a few different techniques employed to load their fonts.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>native</category>
      <category>fonts</category>
    </item>
  </channel>
</rss>
