当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
让mixin为项目开发助力【及递归优化新尝试】
Thoughts on Technology Sharing
2022-08-09 Study Notes day32-IO Stream
AIRIOT答疑第8期|AIRIOT的金字塔服务体系是如何搞定客户的?
postgis空间数据导入及可视化
破解校园数字安全难点,联想推出智慧教育安全体系
800. 数组元素的目标和(双指针)
搭建自己的以图搜图系统 (一):10 行代码搞定以图搜图
websocket校验token:使用threadlocal存放和获取当前登录用户
Interview Question 04.12. Summation Path-dfs+Auxiliary Array Method
【图像分割】基于元胞自动机实现图像分割附matlab代码
003-序列图(一)
MySQL 查询出重复出现两次以上的数据 - having
C#/VB.NET 将PDF转为PDF/X-1a:2001
pip3升级到22.2.2
【FAQ】【Push Kit】 华为怎么设置角标
智能安防产品公司及产品
【图像去雾】基于颜色衰减先验的图像去雾附matlab代码
Active users of mobile banking grew rapidly in June, hitting a half-year high
【知识分享】在音视频开发领域中SEI到底是个啥?