What is pnpm?

Introduction to pnpm, the reduction of npm alternatives saves you disk space

I recently wrote an article about how we have hugenode_modulesFolder, why is this not necessarily a bad thing, but it can reduce hard drive consumption, right?

Every byte saved on the disk can be used for other purposes besides library code. I had a 512GB SSD on the MacBook Pro I bought in 2010, but some brand new computers in 2019 came with a 128GB SSD. hard disk space).

In particular, one approach is to centralize library code storage in a central location and share it with all the projects you work on.

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

It is basically a substitutenpm, Which means that once you install it, you can callpnpm installDownload the project dependencies, all of which will work transparently for you.

If you have 10 projects that use the same version of React,pnpmIt will be installed once, and then the installation will be referenced first in all other projects.

This also means that compared to having to use standard download resources, the initial part of the project takes much less time.npmprogram. Even fasternpmCache package becausepnpmHard-linked to the central local repository, whilenpmCopy the package from the cache.

You installpnpmusenpmCourse

npm install -g pnpm

And then bepnpmAlternative products, you can use allnpmcommand:

pnpm install react
pnpm update react
pnpm uninstall react

and many more.

pnpmIt is especially appreciated in companies that need to maintain a large number of projects with the same dependencies.

E.gglitchIs one of them because they host huge Node.js projects.

pnpmTo them exceptnpmCommon commands, some utilities includepnpm recursiveTo run the same command on all items in the folder. For example, you can initialize 100 items stored in the current folder by runningpnpm recursive install. convenient.

If you usenpx, This is to run the utility (such ascreate-react-app, The benefits you will getpnpmby usingpnpxAttached commandpnpm:

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

Where is the package installed? In macOS,~/.pnpm-store/Folder (where~Represents your home folder). I installedlodashAs an example, this is the resulting folder structure:

➜  ~ 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 is a lot of more advanced knowledge to learn about this tool, but I hope this can help you get started.pnpm!

Should you use it for daily use? Probably not, just insistnpmUnless you have a problem that you need the tool to solve for you-lack of disk space is one of them.

Download mine for freeNode.js manual


More node tutorials: