Welcome Back to Monorepo Castle!
The castle is now built, and every room (project) is in place. But without the right management, things could get messy. Who will help the castle run smoothly? That’s when Lerna enters—a powerful wizard with magical commands that keep everything in order.
Lerna is your guide in the land of monorepo, making sure all the rooms (projects) are in sync, all the packages are linked, and nothing falls apart.
Meet the Magical Wizard: Lerna
Lerna isn't just any wizard—it’s a super wizard designed to make your life easier while managing multiple projects in one repo. Let’s take a peek at some of Lerna’s spells (commands):
1. lerna init – The “Let’s Build a Castle” Spell
This is where it all starts. You summon Lerna with this command, and it sets up the structure for your monorepo. It’s like laying the foundation for your castle—each room has its place.
lerna init
Then define your workspaces in package.json. With Yarn or pnpm, you can list all the packages that should be managed:
{
"private": true,
"workspaces": [
"packages/*"
]
}
This tells the package manager to treat everything inside the packages/ directory as individual sub-projects (frontend, backend, shared libraries, etc.).
2. Yarn or pnpm for Dependency Management
Previously, Lerna had lerna bootstrap to link dependencies across packages, but this has been deprecated. Instead, use Yarn or pnpm for this task. you can run any of bellow command
yarn install
pnpm install
This automatically links all the projects inside your monorepo, so they can share dependencies. It also deduplicates packages to reduce size, making the installation process faster.
3. Running Commands Across Packages
One of the most powerful features of Lerna is still intact: running scripts across multiple packages in the monorepo. If your monorepo has both a frontend and backend, for example, you can run build or test commands across both without switching directories.
Run the build script in every package:
lerna run build
Lerna will go into each package and execute the build script, which is extremely useful when you want to ensure all packages are in sync before deployment.
4. Versioning & Publishing
Lerna’s original focus remains unchanged: versioning and publishing.
Versioning: Lerna will automatically bump versions for your packages based on the changes you’ve made. This ensures that when you make updates, version numbers are consistent across the whole project.
lerna version
Publishing: When it’s time to release, you can use Lerna to publish all packages at once, or selectively, depending on your needs:
lerna publish
With Lerna by your side, managing a monorepo becomes an absolute easy. From syncing dependencies to running scripts across projects, Lerna keeps the castle organized, efficient, and fast.
Stay tuned for more wizardry as we explore other tools in this magical land of web development. ✨
till then, Happy Coding ! 🫶🏻
Top comments (3)
Hm for which version of Lerna are you writing this?
As an example
lerna bootstrap
was removed a while ago. Other commands also don't exist any more.Presumably you used AI to generate this article. Would be better to hint here... Otherwise, please check with the latest versions / verify the content.
If you're considering using a monorepo, NX Monorepo or Turborepo are excellent choices. Each has its strengths: NX offers a rich set of tools and plugins, especially useful for larger, more complex projects, while Turborepo focuses on speed and simplicity. Evaluate both to see which aligns best with your project needs!
Good one
Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more