1. Separate repository and monorepo tool
2 min read

This page is part of The toolkit I needed to make it all happen list - 1/7
Following up on our deep dive into exile.watch's use of Lerna, this page tackles the first crucial steps: setting up a separate repository and introducing Lerna as our monorepo tool.
Separate repository
It was fairly straightforward—I created an empty repository through GitHub's UI
Monorepo tool (Lerna)
Starting with an empty repository, the best approach was to follow the "starting from scratch" instructions from the Lerna setup guide, utilizing the npx lerna init
CLI command.
Running lerna init
got everything prepped for a true Lerna workspace.
Although I don’t remember the exact output, I initially ended up with the following lerna.json
:
// lerna.json
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "independent",
"packages": [
"packages/*"
]
}
As of March 2024, let’s break down the options and definitions in the above JSON:
$schema
This refers to JSON schemas, which help to describe your JSON data structure.
version ("fixed" mode)
.
├ package.json # "version": 0.0.0
├ lerna.json # "version": 1.2.3
└ packages
├ package_A
│ └ package.json # "version": 1.2.3
└ package_B
└ package.json # "version": 1.2.3
version ("independent" mode)
I went with independent
option.
I opted for this approach because some packages will change more often than others.
Also it wasn’t necessary to version the repository's package.json
, and doing so is generally not recommended:
.
├ package.json # "version": deleted key, "private": true
├ lerna.json # "version": "independent"
└ packages
├ package_A
│ └ package.json # "version": 1.2.3
└ package_B
└ package.json # "version": 3.2.1
packages
This is an array of globs indicating where packages can be found. By default, it’s set to ["packages/*"]
, which is how configurations for splinters, nucleus and writ are structured.
Updating package.json
to leverage NPM Workspaces
package.json
to leverage NPM WorkspacesThe last change involved updating package.json
to make the most of npm workspaces:
// package.json
{
// ...
{
"workspaces": [
"packages/*"
],
}
With our repository and Lerna setup ready, let's now focus on the second key piece: the module bundler, crucial for efficiently packaging our code.
Last updated
Was this helpful?