You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
pnpm 全局存储的效果
1. 节省磁盘空间
2. 安装速度更快
3. 更严格的依赖管理
实现原理
📦 存储结构
🔗 硬链接(Hard Link)机制
什么是硬链接?
# 示意图 全局存储的 react 文件 ↑ ├── 项目A 的 react (硬链接) ├── 项目B 的 react (硬链接) └── 项目C 的 react (硬链接) 所有项目共享同一份物理文件,但看起来各有一份🔍 三层结构
pnpm 使用三层 node_modules 结构:
三层的作用:
node_modules/react):符号链接,你代码中import的是这层.pnpm/react@18.2.0/):扁平化依赖结构与 npm/yarn 的对比
实际效果举例
假设你的电脑上有 10 个项目都用了相同版本的常见包:
验证方式
你可以在项目中验证:
这就是 pnpm 被称为"高性能的 npm"的原因——通过巧妙的文件系统特性实现了空间和速度的双重优化!
Beta Was this translation helpful? Give feedback.
All reactions