Movatterモバイル変換


[0]ホーム

URL:


メインコンテンツまでスキップ
Version: 10.x

pnpmとnpmの比較

npmの平坦なツリー構造

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.

結果として、依存関係を削除して、孤立したパッケージだけを残したりしない限り、pnpmを使っていれば無関係なパッケージをプロジェクトに残してしまうことは無くなるでしょう。 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