pnpm_什么是pnpm?

  • Post author:
  • Post category:其他


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