pnpm_什么是pnpm?

pnpm

I recently wrote about how we have huge node_modules folders and why this is not necessarily a bad thing, but it would be reduce that hard drive consumption, right?

我最近写了一篇关于我们如何拥有巨大的node_modules文件夹的文章,为什么这不一定是一件坏事,但是它将减少硬盘的使用量,对吗?

Every byte saved on disk can be used for something else than libraries code, I have a 512GB SSD on my MacBook Pro I bought in 2010 but some brand new computers in 2019 ship with a 128GB SSD (something went wrong with Moore’s Law when it comes to hard disk space).

磁盘上保存的每个字节都可用于库代码以外的其他用途,我在2010年购买的MacBook Pro上有512GB SSD,但2019年的某些全新计算机附带128GB SSD(摩尔定律出了问题到硬盘空间)。

In particular, one way would be to centralize the libraries code storage into a central place, and share it with all the projects you work on.

特别是,一种方法是将库代码存储集中到一个中央位置,并与您从事的所有项目共享。

This is the main value proposition of pnpm, a very cool project you can check out at https://pnpm.js.org.

这是pnpm的主要价值主张, pnpm是一个非常酷的项目,您可以在https://pnpm.js.org上查看。

It is basically a drop-in replacement for npm, which means that once you install it, you can invoke pnpm install to download a project dependencies, and all will work transparently for you.

它基本上是npm替代品,这意味着一旦安装它,就可以调用pnpm install来下载项目依赖项,所有这些将对您透明地起作用。

If you have 10 projects that use React, at the same version, pnpm will install it once, and then reference that first install across all your other projects.

如果您有10个使用React的项目,并且版本相同,则pnpm将安装一次,然后在所有其他项目中首先引用该安装。

This also means that the project initialization part takes much less time than if it had to download resources using the standard npm procedure. It’s faster even if npm cached the package, because pnpm makes a hard link to the central local repository, while npm makes a copy of the package from the cache.

这也意味着,与必须使用标准npm过程下载资源的情况相比,项目初始化部分所花费的时间要少得多。 即使npm缓存了软件包,它也更快,因为pnpm硬链接到中央本地存储库,而npm从缓存中复制了软件包。

You install pnpm using npm, of course 😁

您安装pnpm使用npm当然,😁

npm install -g pnpm

Then being pnpm a drop-in replacement, you can use all the npm commands:

然后,作为pnpm的替代产品,您可以使用所有npm命令:

pnpm install react
pnpm update react
pnpm uninstall react

and so on.

等等。

pnpm is especially appreciated in those companies where there is a need to maintain a large number of projects with the same dependencies.

pnpm在需要维护大量具有相同依赖项的项目的公司中尤其受赞赏。

For example Glitch is one of those companies, as they host a gazillion Node.js projects.

例如, Glitch是其中的一家公司,因为它们托管着庞大的Node.js项目。

pnpm gives them, in addition to the npm usual commands, some utilities including pnpm recursive, which is used to run the same command across all the projects in a folder. For example you can initialize 100 projects stored in the current folder by running pnpm recursive install. Handy.

除了npm常用命令外, pnpm为他们提供了一些实用程序,包括pnpm recursive ,这些实用程序用于在文件夹中的所有项目上运行相同的命令。 例如,您可以通过运行pnpm recursive install初始化当前文件夹中存储的100个项目。 便利。

If you use npx, which is a handy (and the recommended) way to run utilities like create-react-app, you’ll get the benefits of pnpm by using the pnpx command which comes with pnpm:

如果您使用npx ,这是一个方便的(和推荐)的方式运行像公用事业create-react-app ,你会得到的好处pnpm使用pnpx附带命令pnpm

pnpx create-react-app my-cool-new-app

Where are the packages installed? In macOS, in the ~/.pnpm-store/ folder (where ~ means your home folder). I installed lodash as an example and this was the resulting folder structure:

软件包安装在哪里? 在macOS中,在~/.pnpm-store/文件夹中(其中~表示您的主文件夹)。 我安装了lodash作为示例,这是结果文件夹结构:

➜  ~ tree .pnpm-store/
.pnpm-store/
└── 2
    ├── _locks
    ├── registry.npmjs.org
    │   └── lodash
    │       ├── 4.17.11
    │       │   ├── integrity.json
    │       │   ├── node_modules
    │       │   │   └── lodash
    │       │   │       ├── ...
    │       │   ├── package -> node_modules/lodash
    │       │   └── packed.tgz
    │       └── index.json
    └── store.json

There are many more advanced things to learn about the tool, but I hope this helps getting you started with pnpm!

关于该工具,还有许多高级知识需要学习,但是我希望这可以帮助您入门pnpm

Should you use it for a day-to-day use? Probably not, just stick to npm unless you have needs that this tool solves for you - lack of disk space being one of them.

您是否应该将其用于日常使用? 可能不是,只是坚持使用npm除非您有需要此工具为您解决的需求-缺少磁盘空间就是其中之一。

翻译自: https://flaviocopes.com/pnpm/

pnpm

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值