「这是我参与11月更文挑战的第2天,活动详情查看:2021最后一次更文挑战」
pnpm是什么
现代的包管理工具 pnpm( performant npm ),意思是高性能的 npm
去到官网,可以看到Benchmarks罗列出来的数据
This benchmark compares the performance of npm, pnpm, and Yarn (both regular and PnP variant). 该基准测试比较了 npm、pnpm 和 Yarn(常规和 PnP 变体)的性能。
| action | cache | lockfile | node_modules | npm | pnpm | Yarn | Yarn PnP |
|---|---|---|---|---|---|---|---|
| install | 45.5s | 15.6s | 20.7s | 26.8s | |||
| install | ✔ | ✔ | ✔ | 2.1s | 1.2s | 2.5s | n/a |
| install | ✔ | ✔ | 12.2s | 3.8s | 7.4s | 1.7s | |
| install | ✔ | 17.9s | 8.4s | 13.7s | 6.7s | ||
| install | ✔ | 30.3s | 12.6s | 13.4s | 19.4s | ||
| install | ✔ | ✔ | 2.9s | 1.7s | 7.9s | n/a | |
| install | ✔ | ✔ | 2.2s | 1.2s | 8.7s | n/a | |
| install | ✔ | 2.8s | 5.9s | 14.4s | n/a | ||
| update | n/a | n/a | n/a | 2.1s | 11.7s | 17s | 33.4s |
比 npm/yarn 快了大概两倍
怎么了解到pnpm
是这样的,在开发vue3组件库的时候,想看各种各样比较火的vue3组件库,在看到element-plus的时候,按照一般的组件库启动,都可以直接yarn 然后再 yarn dev,但是,启动element-plus的时候,遇到各种坑点
首先,是yarn的时候,直接提示我需要node大于16的版本
那就利用n下一个node大于16的版本
然后继续yarn,结果让我选择版本,我认为随便选个版本应该可以了吧
结果是什么,每个版本都不行
然后我就去看element-plus的github官网开发版本文档,看到他需要pnpm启动。这个时候,就只能去安装nnpm了
安装pnpm
没有安装node
去到官网pnpm可以看到,在不安装node下,都可以安装这个pnpm
Node.js的没有预装
在 POSIX 系统上,即使您没有安装 Node.js,您也可以使用以下脚本安装 pnpm:
curl -fsSL https://get.pnpm.io/install.sh | sh -
如果你没有安装 curl,你想使用 wget:
wget -qO- https://get.pnpm.io/install.sh | sh -
你可以使用pnpm env命令来安装 Node.js。
Node.js的预装
在 Linux 或 macOS 上:
curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm
在 Windows (PowerShell) 上:
(Invoke-WebRequest 'https://get.pnpm.io/v6.16.js' -UseBasicParsing).Content | node - add --global pnpm
安装了node
当然,我选择的是使用npm进行安装
使用NPM
npm install -g pnpm
通过NPX分辨率
npx pnpm add -g pnpm
升级pnpm
一旦安装了 pnpm,就不需要使用其他包管理器来更新它。您可以使用自身升级 pnpm,如下所示:
pnpm add -g pnpm
卸载pnpm
如果您使用独立脚本安装 pnpm(或 npx),那么您应该能够使用以下命令卸载 pnpm CLI:
pnpm rm -g pnpm
如果您使用 npm 安装 pnpm,那么您应该使用 npm 卸载 pnpm:
npm rm -g pnpm
如果你使用了pnpm去安装了一些包,那么你需要
列出所有全局包,请运行pnpm ls -g. 有两种方法可以删除全局包:
- 运行
pnpm rm -g <pkg>...列出的每个全局包。 - 运行
pnpm root -g查找全局目录的位置并手动删除。
总结
当然,对于pnpm我也只是认识基础的阶段,未来还需要更多的时间去了解。