<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Matt Black on Medium]]></title>
        <description><![CDATA[Stories by Matt Black on Medium]]></description>
        <link>https://medium.com/@MattBlackDev?source=rss-31bc14d332f4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ujXUb_CgoQcV-tdqvqyBGg.jpeg</url>
            <title>Stories by Matt Black on Medium</title>
            <link>https://medium.com/@MattBlackDev?source=rss-31bc14d332f4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 20:41:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@MattBlackDev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Zero-Config Monorepo for a React Component Library in 2019]]></title>
            <link>https://medium.com/@MattBlackDev/zero-config-monorepo-for-a-react-component-library-in-2019-dd9137bdd0a6?source=rss-31bc14d332f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd9137bdd0a6</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[rollup]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[monorepo]]></category>
            <dc:creator><![CDATA[Matt Black]]></dc:creator>
            <pubDate>Sat, 30 Mar 2019 06:58:50 GMT</pubDate>
            <atom:updated>2019-03-30T06:58:50.334Z</atom:updated>
            <content:encoded><![CDATA[<p>This article is a step-by-step guide for setting up a monorepo of independently versioned react component packages with as little configuration as I’ve found possible in the OSS ecosystem.</p><p>Recently, I began developing a set of components in <a href="https://codesandbox.io/">Codesandbox</a> using the CRA template. When it came time to package them up, I went on a quest for a setup that uses <a href="https://facebook.github.io/create-react-app/">create-react-app</a> for demoing and further development, and build/packaging tools with the least headaches.</p><p>I admit, as primarily a <a href="https://www.meteor.com/">MeteorJS</a> developer, I’ve been shielded from the abyss of build, bundling and package configuration that exists in the wild today.</p><p>I landed on the following tools:</p><ul><li><a href="https://yarnpkg.com/">Yarn</a> (<a href="https://yarnpkg.com/lang/en/docs/workspaces/">Workspaces</a>)</li><li><a href="https://lernajs.io/">Lerna</a></li><li><a href="https://github.com/developit/microbundle">Microbundle</a></li></ul><p>And I wanted a monorepo structure that looks like this:</p><pre>dope-lib/<br>  demo/<br>  packages/<br>    dope-editor/<br>    dope-visualizer/</pre><p>So, without further ado…</p><h3>The Steps</h3><p>Let’s begin by creating the repo root:</p><pre>mkdir dope-lib<br>cd dope-lib<br>yarn init -yp</pre><p>Open up the package.json file to remove main, set version to 0.0.0, add <a href="https://yarnpkg.com/lang/en/docs/workspaces/">workspaces</a>:</p><pre>{<br>  &quot;name&quot;: &quot;dope-lib&quot;,<br>  &quot;version&quot;: &quot;0.0.0&quot;,<br>  &quot;license&quot;: &quot;MIT&quot;,<br>  &quot;private&quot;: true,<br>  &quot;workspaces&quot;: [<br>    &quot;packages/*&quot;,<br>    &quot;demo&quot;<br>  ]<br>}</pre><p>Then, add lerna and microbundle as <a href="https://yarnpkg.com/en/docs/cli/add#toc-yarn-add-ignore-workspace-root-check-w">workspace dev dependencies</a> and initialize lerna:</p><pre>yarn add lerna microbundle --dev -W<br>lerna init --independent</pre><p>Lerna creates the packages folder by default and a lerna.json file. The independent flag sets the version field in lerna.json, which tells lerna to version the packages independently.</p><p>Next, modify lerna.json to integrate with yarn:</p><pre>{<br>  &quot;version&quot;: &quot;independent&quot;,<br>  &quot;npmClient&quot;: &quot;yarn&quot;,<br>  &quot;useWorkspaces&quot;: true<br>}</pre><p>If you’re following along, you’ll notice we removed the packages field. Lerna will respect the workspaces defined in package.json so we can stay DRY.</p><p>Now to get something running.</p><h3>Demo &amp; Development App</h3><pre>create-react-app demo</pre><p>If you look inside demo/node_modules you’ll notice there’s not much in there. That’s because yarn installed the dependencies in the workspace root node_modules folder to be shared by any packages that need them.</p><p>In the root package.json, add one script to rule them all:</p><pre>&quot;scripts&quot;: {<br>  &quot;start&quot;: &quot;lerna run start --parallel&quot;<br>},</pre><p>Test it out:</p><pre>yarn start</pre><p>Lerna will kick off the start script (in parallel) for every package. Kill it — and let’s create some dope component packages (use your imagination).</p><h3>Packages</h3><pre>mkdir packages/dope-editor<br>cd packages/dope-editor<br>yarn init -y<br>yarn add react --peer</pre><p>Modify dope-editor’s package.json, paying attention to the version, main, module, source and scripts fields:</p><pre>{<br>  &quot;name&quot;: &quot;dope-editor&quot;,<br>  &quot;version&quot;: &quot;0.0.0&quot;,<br>  &quot;main&quot;: &quot;dist/index.js&quot;,<br>  &quot;module&quot;: &quot;dist/index.mjs&quot;,<br>  &quot;source&quot;: &quot;src/index.js&quot;,<br>  &quot;license&quot;: &quot;MIT&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;microbundle watch --jsx React.createElement&quot;<br>  },<br>  &quot;peerDependencies&quot;: {<br>    &quot;react&quot;: &quot;^16.8.6&quot;<br>  }<br>}</pre><p>Version will be bumped by lerna on publish. Source defines the input to microbundle and the start script tells microbundle to rebuild on changes. Note, <a href="https://buble.surge.sh/guide/#jsx">the “ — jsx React.createElement” argument is for Buble</a> which currently runs under the hood. <a href="https://github.com/developit/microbundle/pull/362">Mircobundle is in the process of switching to Babel.</a></p><p>Next up, let’s add some code to src/index.js:</p><pre>import React from &#39;react&#39;</pre><pre>export default function DopeEditor() {<br>  return &lt;p&gt;The Dopest Editor You Ever Editted With&lt;/p&gt;<br>}</pre><h3>Putting it all together</h3><p>Now, we can add dope-editor as a dependency to the demo.</p><pre>cd ../../<br>lerna add dope-editor --scope demo</pre><p>Then import and use it in demo/src/App.js:</p><pre>import React from &#39;react&#39;<br>import DopeEditor from &#39;dope-editor&#39;<br>import &#39;./App.css&#39;</pre><pre>function App() {<br>  return (<br>    &lt;div <em>className</em>=&quot;App&quot;&gt;<br>      &lt;header className=&quot;App-header&quot;&gt;<br>        &lt;<em>DopeEditor</em> /&gt;<br>      &lt;/header&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><pre>export default App</pre><p>Finally, the fruits of our labor, from the workspace root:</p><pre>yarn start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mb4XtVOpEL-i4yzUH-Ok3w.png" /><figcaption>Demo App</figcaption></figure><h3>Next Steps</h3><p>See lerna’s docs for publishing to npm and keep an eye out on microbundle’s transition to babel. I believe they are working with the folks at GatsbyJS and Rollup to sort that out.</p><p>I may publish more articles involving this setup depending on how it goes for me and any future discussions. Feel free to ask questions and leave feedback.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd9137bdd0a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>