Movatterモバイル変換


[0]ホーム

URL:


Pular para o conteúdo principal
Versão: 10.x

pnpm vs npm

A estrutura plana do 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.

Instalação

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.

Como consequência dessa limitação, projetos não terão nenhum pacote estranho ao usarem pnpm, a não ser que removam uma dependência e deixem-na órfã. That'swhy pnpm's implementation of theprune command does not allow you to specifypackages to prune - it ALWAYS removes all extraneous and orphaned packages.

Dependências de diretório

Directory dependencies start with thefile: prefix and point to a directory inthe filesystem. Assim como o npm, pnpm cria um link simbólico para essas dependências. Ao contrário do npm, pnpm não instala as dependências do arquivo.

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