lerna_为什么lerna在开发人员中如此受欢迎

lerna

Lerna is a monorepo tool used to manage multiple projects in a single repository.

Lerna是一个monorepo工具,用于管理单个存储库中的多个项目。

Working on any complex application involves multiple repositories, and making changes to them can be difficult to track and make things complicated. That’s where Lerna comes to the rescue. One major benefit of using a monorepo is that it can share dependencies among projects.

在任何复杂的应用程序上工作都涉及多个存储库,因此对其进行更改可能很难跟踪并使它们变得复杂。 Lerna就是在那儿进行救援。 使用monorepo的一个主要好处是它可以在项目之间共享依赖项。

开发人员为什么要使用Lerna? (Why Should Developers Use Lerna?)

Lerna makes things easier for developers by managing tasks like versioning, deployment of code, dependency management between projects, and much more. It is mostly used in bigger projects, where it becomes hard to maintain all these tasks manually over time.

Lerna通过管理诸如版本控制,代码部署,项目之间的依赖管理等任务,使开发人员更轻松。 它主要用于大型项目,随着时间的推移,手动执行所有这些任务变得很困难。

(Example)

Let’s say you’re building an e-commerce application with multiple repositories containing different code bases. One contains the front-end code base for web, the other contains an API service, and another contains mobile code. Now, you would use the same tooling across all the repositories, right? By tooling, I meant using tools like eslint, prettier, babel, etc. Rather than having separate configurations for each project, we can have common configs that can be shared by all the projects.

假设您正在构建一个包含多个包含不同代码库的存储库的电子商务应用程序。 一个包含Web的前端代码库,另一个包含API服务,另一个包含移动代码。 现在,您将在所有存储库中使用相同的工具,对吗? 通过工具,我的意思是使用eslint,prettier,babel等工具。我们可以为每个项目共享通用的配置,而不是为每个项目配置单独的配置。

Also, if you use certain dependencies that are common to all these projects, you can include them once and use them globally to share them rather than including them in all the projects independently.

另外,如果您使用所有这些项目共有的某些依赖项,则可以只包含它们一次,并在全局范围内使用它们共享它们,而不必将它们独立地包含在所有项目中。

Lerna回购是什么样的? (What Does a Lerna Repo Look Like?)

Let’s take the previous example to show how the directory structure will look:

让我们以前面的示例来展示目录结构的外观:

Lerna’s folder structure.
A basic Lerna folder structure
基本的Lerna文件夹结构

Here, the root package.json file contains the common dependencies for all the projects (web, mobile). The root node_modules contains all these dependencies. The projects are listed under the packages directory. The node_modules directory within the mobile and web contains the dependencies of mobile and web projects, respectively.

在这里,根package.json文件包含所有项目(Web,移动)的公共依赖项。 根节点node_modules包含所有这些依赖项。 项目列在packages目录下。 移动设备和Web中的node_modules目录分别包含移动项目和Web项目的依赖项。

Lerna提供的核心功能 (Core Functionalities That Lerna Provides)

自举(Bootstrapping)

Lerna bootstraps all the packages in the main repo. In other words, it installs all the dependencies and links any cross-dependencies if there are any. It links all the shared dependencies by creating symlinks. If any update is done in the shared dependency, it immediately takes effect in the code using it.

Lerna在主存储库中引导所有软件包。 换句话说,它将安装所有依赖项并链接任何交叉依赖项(如果有)。 它通过创建符号链接来链接所有共享的依赖项。 如果在共享依赖项中进行了任何更新,则更新将立即在使用它的代码中生效。

出版 (Publishing)

Publishing has never been easier. All you have to do is enter a single command (lerna publish), as it prompts for a new version and updates all the packages on git and npm. You can also force-publish if you want to.

发布从未如此简单。 您所要做的就是输入一个命令( lerna publish ),因为它会提示您输入新版本并更新git和npm上的所有软件包。 如果需要,也可以强制发布。

版本控制 (Versioning)

Lerna provides the ability to check which packages have been changed since the last release. You can also check the diff for all packages or a single package since the last release.

Lerna提供了检查自上一发行版以来已更改了哪些软件包的功能。 您也可以检查自上一个发行版以来所有软件包或单个软件包的差异。

同时运行命令 (Running commands concurrently)

Instead of moving to each project and starting the server, you can write a script in the root package.json file, using the lerna run command to run the command in all the projects concurrently. This behaviour is used when you’d like to run all the servers at the same time.

您可以使用lerna run命令在所有项目中同时运行该命令,而不是移至每个项目并启动服务器,而可以在根package.json文件中编写脚本。 当您希望同时运行所有服务器时,将使用此行为。

There are several other features that Lerna provides. I’ve just covered the most basic ones. Have a look at their documentation for more information.

Lerna还提供其他一些功能。 我已经介绍了最基本的内容。 请查看他们的文档以获取更多信息。

谁使用Lerna? (Who Uses Lerna?)

A large number of top companies use Lerna for their projects. Some of the projects where Lerna is used are:

许多顶级公司在他们的项目中使用Lerna。 使用Lerna的一些项目是:

最后的想法 (Final Thoughts)

Today, Lerna is one of the most popular tools that manage multi-package repositories with git and npm/yarn. It’s no surprise that a lot of people use them in their projects, as they make things very simple.

如今,Lerna已成为使用git和npm / yarn管理多包存储库的最受欢迎的工具之一。 毫不奇怪,很多人在他们的项目中使用它们,因为它们使事情变得非常简单。

If you are building a large application and have thought about architecting it into multiple projects, then you should definitely give Lerna a try. There’s a lot more Lerna can do. A good place to start is their documentation.

如果您正在构建一个大型应用程序,并且已经考虑过将其架构到多个项目中,那么您绝对应该尝试一下Lerna。 Lerna还可以做更多的事情。 他们的文档是一个很好的起点。

Happy coding!

编码愉快!

翻译自: https://medium.com/better-programming/why-is-lerna-so-popular-among-developers-ef78d965d3ea

lerna

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值