pnpm vs npm
npm의 flat tree#
npm maintains a flattened dependency tree as of version 3. This leads to less
disk space bloat, with a messy node_modules directory as a side effect.
On the other hand, pnpm manages node_modules by using hard linking and
symbolic linking to a global on-disk content-addressable store. This lets you get the benefits of far less disk space usage, while also keeping your
node_modules clean. There is documentation on the store layout if you wish
to learn more.
The good thing about pnpm's proper node_modules structure is that it
"helps to avoid silly bugs" by making it impossible to use modules that are not
specified in the project's package.json.
설치하기#
pnpm does not allow installation of packages without saving them to
package.json. If no parameters are passed to pnpm add, packages are saved as
regular dependencies. Like with npm, --save-dev and --save-optional can be
used to install packages as dev or optional dependencies.
이러한 제약의 결과로 dependency를 삭제하여 분리된 상태로 남겨두지 않는 한, 프로젝트에는 관련 없는 패키지는 존재하지 않을 것 입니다. That's why pnpm's implementation of the prune command does not allow you to specify packages to prune - it ALWAYS removes all extraneous and orphaned packages.
디렉토리 dependencies#
Directory dependencies start with the file: prefix and point to a directory in
the filesystem. npm처럼, pnpm도 이러한 의존성을 symlinks합니다. npm과는 달리 pnpm은 파일 dependencies를 설치하지 않습니다.
This means that if you have a package called foo (<root>/foo) that has
bar@file:../bar as a dependency, pnpm won't perform installation for
<root>/bar when you run pnpm install on foo.
If you need to run installations in several packages at the same time, for
instance in the case of a monorepo, you should look at the documentation for
pnpm -r.