Movatterモバイル変換


[0]ホーム

URL:


Перейти к основному содержимому
Версия: 10.x

pnpm vs npm

npm's flat tree

npm maintains aflattened dependency tree as of version 3. This leads to lessdisk space bloat, with a messynode_modules directory as a side effect.

On the other hand, pnpm managesnode_modules by using hard linking andsymbolic linking to a global on-disk content-addressable store. This lets you get the benefits of far less disk space usage, while also keeping yournode_modules clean. There is documentation on thestore layout if you wishto learn more.

The good thing about pnpm's propernode_modules structure is that it"helps to avoid silly bugs" by making it impossible to use modules that are notspecified in the project'spackage.json.

Установка

pnpm does not allow installation of packages without saving them topackage.json. If no parameters are passed topnpm add, packages are saved asregular dependencies. Like with npm,--save-dev and--save-optional can beused to install packages as dev or optional dependencies.

As a consequence of this limitation, projects won't have any extraneous packageswhen they use pnpm unless they remove a dependency and leave it orphaned. That'swhy pnpm's implementation of theprune command does not allow you to specifypackages to prune - it ALWAYS removes all extraneous and orphaned packages.

Каталог зависимостей

Directory dependencies start with thefile: prefix and point to a directory inthe filesystem. Как и npm, pnpm символически связывает эти зависимости. Но в отличие от npm, pnpmне выполняет установку зависимостей файлов.

This means that if you have a package calledfoo (<root>/foo) that hasbar@file:../bar as a dependency, pnpm won't perform installation for<root>/bar when you runpnpm install onfoo.

If you need to run installations in several packages at the same time, forinstance in the case of a monorepo, you should look at the documentation forpnpm -r.


[8]ページ先頭

©2009-2025 Movatter.jp