惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
WordPress大学
WordPress大学
小众软件
小众软件
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
腾讯CDC
量子位
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Google Online Security Blog
Google Online Security Blog
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
罗磊的独立博客
L
LINUX DO - 最新话题
博客园 - Franky
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
AI
AI
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
I
Intezer
S
Securelist

ByteofDev

Making Postgres 42,000x slower because I am unemployed A Quick(ish) Introduction to Tuning Postgres JavaScript numbers have an (adoption) problem My 2025 JavaScript Wishlist JavaScript Benchmarking Is a Mess Replacing Disqus Commenting A deep dive into distributed database architectures 10 ways to speed up web image loading Tailwind has a scalability problem. How can we solve that? The 6 JavaScript Projects to watch in 2023 Top 5 Alternatives to React in 2023 How to use ESM on the web and in Node.js React vs Svelte: Which is better in 2023? 10 ways to speed up JavaScript loading What is Bun, and does it live up to the hype? State of JS 2021 Results and Analysis State of the Web: React 10 ways to speed up web font loading State of the Web: Atomic CSS State of the Web: Static Site Generators State of the Web: Bundlers & Build Tools Migrating ByteofDev from SvelteKit to Astro State of the Web: Serverless Functions State of the Web: Deno Array.map() versus Array.forEach() A quick introduction to JavaScript Maps How I Built the Fastest JavaScript Data Differ State of the Web: WebAssembly When you should and shouldn't use React
Lerna vs Turborepo vs Rush: Which is better in 2023?
Jacob Jackson · 2023-02-05 · via ByteofDev

Monorepos are becoming very popular within web development, and for good reason. They offer superior ergonomics and integration compared to splitting code up into separate repositories. Some of the most popular JavaScript monorepo tools are Lerna, Turborepo, and Rush, which we will compare today. First, let’s introduce each tool.

Lerna

Created in 2016, Lerna is the most popular tool in the group. It was one of the first tools to allow JavaSript developers to link projects together and control them with central commands. For example, if you had an app with two package dependencies and wanted to build them all, you could simply run npx lerna run build and Lerna would build the dependencies and then the app with the updated dependencies.

Nowadays, Lerna is commonly used with Nx, which allows it to cache the results of tasks, meaning Lerna only has to recompile files that changed. You can even put the cache on a central server, meaning multiple machines can access the same cache remotely. Lerna is used by projects like Create React App and Nestjs and is supported by Nrwl, so it has pretty good backing.

Turborepo

Turborepo is a much newer tool, created and aquired by Vercel in 2021. However, it has already overtaken Rush in terms of NPM downloads, and it currently has about the same number of weekly downloads as Lerna. Similar to Lerna with Nx, Turborepo allows you to cache packages based on the content of the source files and dependency versions. Turborepo is also tuned to allow for multithreading or parallel build execution, where it splits tasks across different CPU cores to increase performance.

Rush

Rush is another monorepo tool created by Microsoft in 2016 for Microsoft’s SharePoint Framework, and it is designed to manage large groups of NPM packages and dependencies. Rush includes features like linked packages, incremental builds, and parallel build execution. Rush also integrates with the Rush stack, which includes tools like Heft, a build tool, and Rundown, a Node.js startup performance analysis tool.

Comparison

Now that we have introduced each of the tools, lets compare them in critical areas.

Setup

Lerna

Setting up Lerna is pretty easy. To create a new Lerna project or integrate Lerna into an existing project, run npx lerna init. This will create a packages directory, add a lerna.json file, and configure npm Workspaces to use packages (Lerna can utilize npm, Yarn, or pnpm workspaces). From there, you should be able to drop your code into packages and reference other packages there by just putting them in package.json dependencies as if they were available on the npm package registry (note that this might be slightly different for Yarn or pnpm).

Unfortunately, you need to do a bit more to set up caching. First, run npx lerna add-caching, which will guide you through a wizard that helps you tell it what tasks should be cached and what tasks depend on other tasks.

Overall, the setup experience is not terrible, but I think it could be better, especially if you are manually editing the pipeline configuration rather than using the wizard.

Turborepo

To set up Turborepo, you first need to run npx create-turbo. This command starts a scaffolding tool that will allow you to select the location and package manager you want to use. Unlike Lerna, caching is automatically enabled by default, so you don’t need to do anything with that. Turborepo also includes a default pipeline configuration, which has a syntax similar to Lerna’s if you need to edit it. If you have an existing monorepo, you can manually install Turborepo, configure the npm/pnpm/Yarn workspace (which might already be done if), and create a turbo.config.js file with the pipeline config.

Turborepo’s automatic caching makes set up simpler than with Lerna, but for existing monorepos it can be a bit more complicated and the pipeline configuration is still unnecessarily complex.

Rush

Rush is the one tool that does not integrate with npm workspaces, so setup is a bit different. First, you must install Rush by running npm install -g @microsoft/rush. Then, you will need to run rush init to scaffold a new repository. After, you might need to configure a few things in rush.json, like setting the package manager to use.

However, we still have not added any actual projects. First, you need to add the project and then, you need to add it to rush.json’s projects object. Finally, instead of installing dependencies the standard way, you have to use rush update, as Rush has its own layer over dependency management.

As you can see, Rush’s setup is significantly more complex than Lerna’s or Turborepo’s is in almost every way.

Ranking

Lerna and Turborepo are pretty close in terms of ease of setup, but I think Turborepo is still better in this regard due to caching being enabled by default. As for Rush, it is way behind both in setup. I would avoid Rush if you have to set up many projects with it.

🥇: Turborepo

🥈: Lerna

🥉: Rush

Performance

Lerna

Lerna’s performance is not that great by default, but paired with Nx, it is fast. Nx provides advanced caching to allow Lerna to be significantly faster than it would be by default. According to these benchmarks, Lerna with Nx is almost 5x faster than Turborepo. This is due to how Nx selectively restores files from cache. Nx avoids restoring every file and instead checks to see what actually needs to be restored from the cache, which reduces I/O load.

Turborepo

As previously discussed, Turborepo is quite a bit slower than Lerna with Nx. Unlike Lerna, Turborepo fully restores files from cache every time. However, Turborepo is a bit faster to boot up, and if you are not bottlenecked by storage speed, the difference between Turborepo and Lerna will be much smaller.

Rush

There is not much benchmark data on Rush’s performance. Luckily, we can take a reasonable guess using its feature set. Due to how it supports caching, it likely performs around the same as Turborepo, if not slightly faster. However, do note that you will need to use Rush’s experimental build cache in order to be competitive with Turborepo.

Ranking

Overall, Lerna paired with Nx is the fastest out of these, followed by Turborepo and then Rush. While they should all be fast enough for most projects, if you are working with a very large monorepo, Lerna might be a bit faster. Turborepo and Rush should perform around the same, but Turborepo gets second due to having full performance without having to enable experimental features (Rush’s build cache is experimental).

🥇: Lerna

🥈: Turborepo

🥉: Rush

Features

Lerna

Lerna includes a wide variety of features, ranging from remote caching to dependency graph creation. One of the most interesting features is the ability to distribute task execution, which means you can split build workloads across multiple machines, speeding up the process. Unfortunately, to do this, you need to use Nx Cloud which is a service created by Nrwl for remote caching and task distribution. Nx Cloud is free for open source projects, but can cost money if your project is closed-source. You can also run Nx Cloud locally if you are worried about privacy, but this requires you to sign up for the Nx Enterprise Package.

If you are willing to use Nx Cloud, you can get many features that are not available on other monorepo tools, but as already discussed, that does come with a cost.

Turborepo

Turborepo offers many features that are comparable with Lerna’s, but it is a bit more limited, likely because of how much newer it is. The most interesting feature is how its remote caching works. Turborepo offers free integration with Vercel’s servers, and better yet, if you are worried about putting your code on servers you do not control or otherwise want your own caching server, Vercel supports you building your own remote caching server, and there are open source implementations of the caching server already. Turborepo doesn’t support distributed task execution, but remote caches are still helpful.

Rush

Rush has a wide variety of feature, to the point where it can be a bit overwhelming. Instead of more innovative caching, a lot of Rush’s features focus more on simply managing large monorepos. A great example of this is Rush’s policies. Policies allow you to restrict certain things to make collaboration in a monorepo easier. One of the most interesting policies is the approvedPackagePolicy, which makes it easier for people to review packages added by forcing them to be added to a central configuration file. Rush also supports plugins, which allow you to share configuration across projects and extend Rush’s functionality.

Rush has a large variety of features for large teams and large monorepos, and Lerna and Turborepo cannot replicate many of them.

Ranking

Rush pulls ahead in this comparison due to the large variety of unique features it has. After that, Lerna is a bit ahead of Turborepo, but I expect Turborepo to catch up in features soon. However, Turborepo still should be commended for the simplest remote caching setup.

🥇: Rush

🥈: Lerna

🥉: Turborepo

Conclusion

CategoryLernaTurborepoRush
Setup🥈🥇🥉
Performance🥇🥈🥉
Features🥈🥉🥇

Each monorepo tool wins in one category, Lerna in performance, Turborepo in setup, and Rush in features. However, Lerna gets second in two categories, whereas Turborepo gets second in only one and Rush in none. While Lerna wins, Turborepo or Rush might still be better for your needs. If you want the best performance while being easy to use and including a wide feature set, choose Lerna. If you are using Vercel or want a modern monorepo tool that has a lot of future potential, try Turborepo. Finally, if you want the most features and/or are working in a large team, Rush might be the best choice.