<?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 Koba on Medium]]></title>
        <description><![CDATA[Stories by Koba on Medium]]></description>
        <link>https://medium.com/@kobashigawa.dev?source=rss-a68d46d98a93------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*wlZNTKWcjNf5u09L1qzkfw.jpeg</url>
            <title>Stories by Koba on Medium</title>
            <link>https://medium.com/@kobashigawa.dev?source=rss-a68d46d98a93------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 17:22:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kobashigawa.dev/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[Creating a Design System with Monorepo]]></title>
            <link>https://medium.com/loftbr/creating-a-design-system-with-monorepo-bc18e055fb3c?source=rss-a68d46d98a93------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc18e055fb3c</guid>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[loftworld]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Koba]]></dc:creator>
            <pubDate>Tue, 17 Dec 2019 19:54:42 GMT</pubDate>
            <atom:updated>2020-01-06T17:11:22.932Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e_Aq_GnUvYTFhel0tDT_OQ.jpeg" /><figcaption>A simple vision of a Design System</figcaption></figure><p>In my job, we’re creating a Design System and recently we’re trying to change our poly-repos into a Monorepo. In this article, I’ll show a few concepts about what is a Monorepo and Design System and why use both together, but the main point is how to implement in React using Lerna and Yarn.</p><h3>Design System</h3><p>First of all, the Design System concept is not absolute, it depends on who you ask.</p><blockquote>A Design System is a collection of reusable components, guided by clear standards, that can be assembled together to build any number of applications. — Design Better Invision.</blockquote><p>As a simple way to see it for developers, it’s a collection of reusable components, that could be built in any language or framework, but delivers a UI library to our other developers colleagues.</p><p>Here’s a nice <a href="https://www.designbetter.co/design-systems-handbook">link</a> to go deeper into this topic.</p><h3>So, what is Monorepo?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*e_azttoZTG53hk-VAgGPLw.jpeg" /><figcaption>Comparisons with Monolith and Multi-repo</figcaption></figure><p>The image above translates what is a Monorepo. It’s a git repository containing smaller project repositories. It facilitates the code reusability, has simplified package management (thanks to Lerna and Yarn Workspaces) and, in our specific case, could ease versioning of our DS’s packages.</p><p>I’ll not go deeper into this comparison because it has a lot of use cases to discuss. I will discuss the Design System case.</p><p>A Design System is mainly composed of:</p><ul><li>Design Tokens (foundation specs, like colors, spacing, typos)</li><li>UI Components</li><li>Documentation</li><li>Icons</li><li>Tools</li></ul><p>We’re going through the Monorepo’s path because we want to organize our packages isolated but still with scalability to maintain them tied up together.</p><h3>Let’s Code!</h3><p>Our tools for the Design System will be:</p><ul><li><a href="https://nodejs.org/en/"><strong>Node/NPM</strong></a>: our package manager.</li><li><a href="https://reactjs.org/"><strong>React</strong></a>: our framework to create the UI Library.</li><li><a href="https://storybook.js.org/"><strong>Storybook</strong></a>: a nice tool to document components.</li><li><a href="https://rollupjs.org/guide/en/"><strong>Rollup</strong></a>: a nice, simple and fast bundler.</li></ul><p>And our Monorepo will be constructed with:</p><ul><li><a href="https://yarnpkg.com/lang/en/docs/cli/workspace/"><strong>Yarn workspace</strong></a>: a feature of Yarn package manager</li><li><a href="https://github.com/lerna/lerna"><strong>Lerna</strong></a>: a Monorepo’s manager tool</li></ul><h4>1) First steps</h4><p>We will install Lerna and start the initial configuration:</p><pre>// Install lerna<br>npm install -g lerna</pre><pre>// Init git repository and move into it<br>git init design-system &amp;&amp; cd design-system</pre><pre>// Init lerna configurations<br>lerna init</pre><p>As you can see, Lerna generates some config files. You can see more about lerna.json config <a href="https://github.com/lerna/lerna#lernajson">here</a>.</p><h4>2) Create Design Tokens package</h4><p>We will create our tokens package, I’ll call it mono-ds-tokens(it will only contain a palette):</p><pre>// This command creates a package already linked with lerna<br>lerna create mono-ds-tokens</pre><p>It will make some package.json configuration questions like the author, description, etc. Just set the entry point to src/index.js .</p><p>Some files were created in our packages/mono-ds-tokens . Let&#39;s remove packages/mono-ds-tokens/lib/ folder and create our src folder with an index.js file inside.</p><p>So, let’s deliver some tokens, go to packages/mono-ds-tokens/src/index.js</p><p>Now, we have a palette and a spacing configuration!</p><p>So, let’s publish it!</p><p>We’ll use NPM Registry, so you should sign up there and do npm login in your terminal. Make sure that your package name (package.json -&gt; &quot;name&quot; property) does not already exist by checking at <a href="https://npmjs.org/%7Bpackage-name%7D">https://npmjs.org/{package-name}</a>.</p><p>With Lerna, you can publish all your packages in just one command.</p><p>So, let’s put in the terminal:</p><p>lerna publish</p><p>You will be asked about the package’s versioning. Choose what you want.</p><p>Congratulations! If all goes right, your package has been published and you can see it at https://npmjs.org/{package-name} . For more information about the publication of public packages, go <a href="https://docs.npmjs.com/creating-and-publishing-unscoped-public-packages">here</a>.</p><h4>3) UI Library</h4><p><strong>Setup</strong></p><p>Let’s create another package, I’ll call it mono-ds-components :</p><pre>// Let&#39;s create adding our tokens package as dependency<br>lerna create mono-ds-components --dependencies mono-ds-tokens</pre><p>Again, set entry point to src/index.js , remove lib/ folder and create src folder with index.js file inside.</p><p>To create a React UI component library, we’ll add some packages. For that, you can go directly in the package folder and run npm install, but I&#39;ll show lerna add <a href="https://github.com/lerna/lerna/tree/master/commands/add">command</a> (Obs: this command is not capable of adding multiple packages, see this <a href="https://github.com/lerna/lerna/issues/2004">issue</a>):</p><pre>lerna add react --scope=mono-ds-component --dev<br>lerna add rollup --scope=components --dev<br>lerna add rollup-plugin-babel@latest --scope=mono-ds-components --dev<br>lerna add @babel/core --scope=mono-ds-components --dev<br>lerna add @babel/preset-react --scope=mono-ds-components --dev</pre><p>Did you see all the repeated commands? This is one of the reasons that Monorepos includes Yarn Workspaces, so let’s include it too. Followed by this <a href="https://yarnpkg.com/blog/2017/08/02/introducing-workspaces/">guide</a>.</p><p>Install Yarn with npm install -g yarn</p><p>Add npmClient: &quot;yarn&quot; and useWorkspaces: true at lerna.json</p><p>Add workspaces property at package.json</p><p>Now, we can add all packages in one command ❤. Look at this:</p><p>yarn workspace mono-ds-components add --dev react rollup rollup-plugin-babel@latest @babel/core @babel/preset-react</p><p>We aren’t using NPM as a package manager because it hasn’t had the Workspace functionality.</p><p><strong>First component</strong></p><p>Let’s create our Button component. Note that we are using our tokens package:</p><p>packages/mono-ds-components/src/index.js</p><p>To compile this file, we’ll need to config <a href="https://babeljs.io/">Babel</a> at .babelrc:</p><p>packages/mono-ds-components/.babelrc</p><p>And our rollup configurations in rollup.config.js :</p><p>packages/mono-ds-components/rollup.config.js</p><p>Basically, it sets Babel plugin, an input file, and compiled output files.</p><p>To run rollup, add a script at package-name/package.json :</p><pre>&quot;scripts&quot;: {<br>  ...<br>  &quot;compile&quot;: &quot;rollup -c&quot;<br>}</pre><p>And run:</p><p>lerna run compile --stream</p><p><strong>NOTE: </strong>lerna run will execute compile command in all of your packages, and --stream flag only outputs the command log in the terminal. See more details <a href="https://github.com/lerna/lerna/tree/master/commands/run">here</a>.</p><h4>4) Documentation — Storybook</h4><p>Let’s create another package for documentation, I’ll call it mono-ds-docs :</p><p>lerna create mono-ds-docs --dependencies mono-ds-components</p><p>Following this <a href="https://storybook.js.org/docs/guides/guide-react/#manual-setup">guide</a>, we’ll do the Storybook’s setup:</p><pre>yarn workspace mono-ds-docs add react react-dom<br>yarn workspace mono-ds-docs add --dev @storybook/react babel-loader @babel/core</pre><p>Create a .storybook/config.js :</p><pre>import { configure } from &#39;@storybook/react&#39;;</pre><pre>configure(require.context(&#39;../src&#39;, true, /\.stories\.js$/), module);</pre><p>Add the storybook script to package-name/package.json :</p><pre>&quot;scripts&quot;: {<br>  ...<br>  &quot;storybook&quot;: &quot;start-storybook&quot;<br>}</pre><p>And finally, create our Button story at package-name/src/index.stories.js</p><p>Let’s run!</p><p>lerna run storybook --stream</p><p><em>stream: </em>output command logs in the terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*zL019gh7aLQip1KbEjQoAg.png" /><figcaption>Storybook running</figcaption></figure><h4>5) Hot Reload</h4><p>As a default, Storybook starts in watch mode but our Button isn’t compiling in watch mode, so if you change something in the Button component, it will not do the hot reload.</p><p>To do that, we need to structure our changes. Let’s add a new command in our mono-ds-docs/package.json :</p><pre>&quot;scripts&quot;: {<br>   &quot;storybook&quot;: &quot;start-storybook&quot;,<br>   &quot;docs:dev&quot;: &quot;npm run storybook&quot;<br>}</pre><p>docs:dev command only runs the script above storybook , I&#39;d recommend that you create it in order to separate commands responsibilities. In the next step, you will know why.</p><p>Now, we need to add to our mono-ds-components/package.json the rollup watch mode and docs:dev command running our watch mode:</p><pre>&quot;scripts&quot;: {<br>   &quot;compile&quot;: &quot;rollup -c&quot;,<br>   &quot;compile:watch&quot;: &quot;rollup -c -w&quot;,<br>   &quot;docs:dev&quot;: &quot;npm run compile:watch&quot;<br>},</pre><p>As I explained before, lerna run is capable to run your command in each package.</p><p>So, you can run Storybook in watch mode:</p><p>lerna run docs:dev --parallel</p><p>--parallel flag outputs each package command in your terminal disregarding concurrency, see more <a href="https://github.com/lerna/lerna/tree/master/commands/run#--parallel">here</a>.</p><p>Test it! Run this command and modify some changes in our Button component and you&#39;ll see an isolated development environment with hot reload to develop your commands and document at the same time!</p><h3>Conclusion</h3><p>Design System with Monorepo really makes sense in itself. It contextualizes all packages into one working environment that facilitates package management, runs parallel commands and versioning does well in this case.</p><p>Before I started this task I thought that it would be hard to setup all of this, but as you can see with some small configurations, it became rather trivial.</p><p>For now, I’d recommend you see the Lerna’s <a href="https://github.com/lerna/lerna/tree/master/commands">commands</a> to familiarize with the versioning and publishing.</p><p>See the final version in this <a href="https://github.com/kobajs/monorepo-ds">repository</a>.</p><p>Also, I’m creating a <a href="https://github.com/kobajs/monorepo-ds-boilerplate/tree/master/packages">boilerplate</a> with Typescript!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc18e055fb3c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/loftbr/creating-a-design-system-with-monorepo-bc18e055fb3c">Creating a Design System with Monorepo</a> was originally published in <a href="https://medium.com/loftbr">Loft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>