跳到主要内容

简介

Lerna 是针对 JavaScript/TypeScript 仓库的原创 monorepo 工具 。它已存在多年,被数以万计的项目所使用,例如 React 和 Jest。

它解决了 JavaScript/TypeScript 单一源码仓库(monorepos)的两大问题:

  • Lerna 可以针对任意数量的项目运行命令,并以最高效的方式、正确的顺序运行,还可以在分布到多台机器上。
  • Lerna 可以管理发布流程,从版本管理到发布到 NPM,它提供了多种选项,确保任何工作流程都能得到满足。

Nx(同名开源构建系统背后的公司)接管了 Lerna 的管理工作Nx 是由前谷歌员工开发的构建系统,采用了许多谷歌内部工具所使用的技术。Lerna v5 版本是新管理团队接手后的第一个版本,更新了一些过时的软件包,并开始对源码仓库本身进行一些清理。从 v6+ 版本开始,Lerna 将任务调度工作委托给 经过实战检验、业界领先的 Nx 任务运行程序,这意味着 lerna run 可以免费获得缓存和命令分布式运行所带来的好处!

为什么选择 Lerna?

  • 超快! Lerna is fast, even faster than most comparable solutions out there (see this benchmark to learn more). How? Under the hood, Lerna v6+ uses Nx to run tasks. Learn more about running tasks here.
  • Computation Caching - Lerna knows when the task you are about to run has been executed in the past. Instead of running it, Lerna will restore the files and replay the terminal output instantly. Plus, this cache can be shared with your co-workers and CI. When using Lerna, your whole organization will never have to build or test the same thing twice. Read more »
  • Configuration-Free Distributed Task Execution Lerna can distribute any command across multiple machines without any configuration, while preserving the dev ergonomics of running it on a single machine. In other words, scaling your monorepo with Lerna is as simple as enabling a boolean flag. See the examples of how enabling DTE can make you CI 20 times faster. Read more »
  • Beautiful Terminal Output Monorepos can have hundreds or thousands of projects. Printing everything on every command makes it hard to see what fails and why. Thankfully, Lerna does a much better job.
  • Powerful Graph Visualizer Lerna comes with a powerful interactive visualizer simplifying the understanding of your workspaces. Read more »
  • Publishing to NPM Lerna is the ultimate tool for publishing multiple packages to npm. Whether the packages have independent versions or not, Lerna has you covered. Read more »
  • Easy to Adopt Even with all these capabilities, Lerna is very easy to adopt. It requires close-to-zero configurations. Want to see how?