Hi Everyone,

I’m Shivang and recently I had a chance to experiment with a rather unique setup that allows developers to publish individual modules as subscribable packages from a single repository.

This is a good fit for publishing a component library with each component as a separate package so as to not pollute the dependency list for someone who imports this library in their project.

For e.g. Let’s say a user wants to import just a button component and not the entire UI library, the library should allow the user to add @mylibrary/button in their package.json and provide a button component.

The most reliable approach to solve the problem is using a Monorepo

What are MonoRepos? Why use them?

Splitting up large codebases into separate independently versioned packages is extremely useful for code sharing. However, making changes across many repositories brings its own set of challenges in terms of maintenance and actively updating things, and testing across repositories becomes complicated very quickly.

To solve these problems, projects can organize their codebases into multi-package repositories. Projects like  Babel,  React,  Angular,  Ember,  Meteor,  Jest, and many others develop all of their packages within a single repository.

A  MonoRepo (not a monolith) is a single repository to hold all your code and each module that needs to be published lives as a separate directory in this repository.

MonoRepos are a rising trend and are vastly used by the likes of Google and Facebook.

Doesn’t that add to a lot of complexity in workflows?

You are correct, it does add complexity in terms of managing the releases and managing dependencies for the project.

One solution that stood out to simplify workflows is using Lerna.

Wondering what is Lerna?

Lerna_ is a tool that helps us optimize workflows for a MonoRepo with Github and NPM. Not only does it allow us to handle publishing all the packages in a very simple manner but also it helps us to manage the dependencies in an efficient manner_

#javascript #monorepo #lerna #npm

Independent Subscribable Modules (Monorepo Setup) with Lerna
1.40 GEEK