当前位置:网站首页>About npm/cnpm/npx/pnpm and yarn
About npm/cnpm/npx/pnpm and yarn
2022-08-10 19:02:00 【youhebuke225】
package.json
dependencies
- 安装在dependencies中的包,Generally, it is the package that the online project depends on
- Generally install the package inside,项目就可以正常运行了
- 通过
NODE_ENV=production npm i
来进行安装
devDependencies
- Packages required for the development environment,Generally some kits,We are all installed in it,如eslint等
- Some package escape toolkits,Usually put here,如
webpack
的loader
等
包的版本
The packages we install are generally as follows
{
...
"core-js": "3.20.3",
"css-loader": "^3.5.3",
"es6-promise": "^4.1.0",
"fast-sass-loader": "^2.0.1",
...
}
命名格式
- 如
"core-js": "3.20.3"
,After him is the version number- 3是主版本号,代表的是不兼容的 API 修改
- 20是次版本号,代表的是向下兼容的功能性新增
- 3是修订号,代表的是向下兼容的问题修正
- 此外,We will also find that in front of the version number,还有一些特殊的符号
~
Indicates when we are updating the package,Only update patch versions- 如果写入的是 〜0.13.0,则Only update patch versions:即 0.13.1 可以,但 0.14.0 不可以.
^
Indicates when we are updating the package,Update the patch version and this version- 如果写入的是 ^0.13.0,则要更新补丁版本和次版本:即 0.13.1、0.14.0、依此类推.
- 如果没有前缀,always keep this version
- 如果写入的是 0.13.0,则始终使用确切的版本.
package-lock.json
- 从npm5版本之后,就推出了
package-lock.json
package-lock.json
的优先级会高于package.json
,package-lock.json
Pins the package version of the current project- 想要更新
package-lock.json
,We just have to use commandsnpm update
- But in this case, all the dependent packages will be upgraded
- Still recommend if you need to upgrade,Just upgrade a package alone
npm
npm 是nodejsthe standard package manager,通常,The packages we installed are all therepackage.json
中体现
- 因为npmLet us compare the commonly used package management tools,So we will not introduce it in detail here
- 常用命令 点击
yarn
- yarnThe current rationpm会快一些,是因为yarnThe current installation is a side-by-side installation,而npmis a serial install
- 在缓存机制上 ,两者都差不多,都会读取本地缓存
- But in the display and design of the installation packageyarn会更友好一点
- 常用命令 点击
cnpm
- cnpm的镜像仓库在国内,也就是淘宝,我们可以全局安装
cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
- 当然我们也可以把npmThe mirror library is set to Taobao source
npm config set registry http://registry.npm.taobao.org
- 需要注意的是
cnpm
没有package-lock.json
,即我们使用cnpm
的时候,It doesn't happen automaticallypackage-lock.json
,Even if the project has itpackage-lock.json
He also doesn't care,只读取package.json
- This can lead to some unexpected thingsbug,并且有时候
cnpm
和npm
The downloaded package is incompatible - 所以,能用
npm
Just try not to use itcnpm
pnpm
简介
pnpm最大的特点就是
- 包安装速度极快
- 磁盘空间利用效率高
- 硬链接:硬连接指通过索引节点来进行连接.在Linux的文件系统中,保存在磁盘分区中的文件不管是什么类型都给它分配一个编号,称为索引节点号(Inode Index).在Linux中,多个文件名指向同一索引节点是存在的.一般这种连接就是硬连接.硬连接的作用是允许一个文件拥有多个有效路径名,这样用户就可以建立硬连接到重要文件,以防止“误删”的功能.其原因如上所述,因为对应该目录的索引节点有一个以上的连接.只删除一个连接并不影响索引节点本身和其它的连接,只有当最后一个连接被删除后,文件的数据块及目录的连接才会被释放.也就是说,文件真正删除的条件是与之相关的所有硬连接文件均被删除.
- 软连接:另外一种连接称之为符号连接,也叫软连接.软链接文件有类似于Windows的快捷方式.它实际上是一个特殊的文件.在符号连接中,文件实际上是一个文本文件,其中包含的有另一文件的位置信息.
也就是说
- 不会重复安装同一个包.使用
npm/yarn
的时候,如果100个包依赖lodash
,那么就可能安装了100次lodash
,磁盘中就有100个地方写入了这部分代码.但是pnpm
会只在一个地方写入这部分代码,It will be used directly laterhard link
- 即使一个包的不同版本,
pnpm
也会极大程度地复用之前版本的代码.举个例子,比如lodash
有 100 个文件,更新版本之后多了一个文件,那么磁盘当中并不会重新写入 101 个文件,而是保留原来的 100 个文件的hardlink
,仅仅写入那一个新增的文件.
安装
npm i pnpm -g
边栏推荐
猜你喜欢
随机推荐
常量
如何通过JMobile软件实现虹科物联网HMI/网关的报警功能?
【图像分割】基于元胞自动机实现图像分割附matlab代码
redis 事件
小分子PEG CAS:1352814-07-3生物素-PEG6-丙酸叔丁酯
servlet映射路径匹配解析
开源一夏 | mysql5.7 安装部署 -二进制安装
QoS服务质量八拥塞避免
[Go WebSocket] 你的第一个Go WebSocket服务: echo server
[教你做小游戏] 只用几行原生JS,写一个函数,播放音效、播放BGM、切换BGM
LeetCode·26.删除有序数组中的重复项·双指针
Redis命令---key篇 (超全)
服务器上行带宽和下行带宽指的是什么
7-2 乒乓人训练大师(双指针)
【深度学习前沿应用】图像风格迁移
选择是公有云还或是私有云,这很重要吗?
新建离线同步节点时选择数据去向-表时报错,数据库类型是adb pg,怎么办?
Scala中使用 Jackson API 进行JSON序列化和反序列化
VoLTE基础自学系列 | 3GPP规范解读之Rx接口(上集)
TikTok选品有什么技巧?