当前位置:网站首页>为什么放弃npm转向yarn了
为什么放弃npm转向yarn了
2022-07-26 10:53:00 【唐璜Taro】
前言
yarn 和 npm都是非常优秀包管理工具,经过重新设计的npm客户端 yarn,无疑是npm plus 版本,解决了开发者使用 npm 时遇到的痛点
一、yarn是什么?
yarn 是新一代的包管理工具,该工具是由Facebook和Goole等公司在2016年联合推出 。yarn在运行速度上有显著的提升,安装时间减少少,功能上也有很多改进
二、安装步骤
1.引入库
代码如下(示例):
npm install -g yarn
2.npm弊端
- 下载速度慢: 因为npm 安装插件是从国外服务器中进行下载,远远不如国内服务器下下载快,为了解决这一痛点,淘宝团队做了国内版的 npm 叫做
cnpm,并且对 npm 做了镜像,我们只需要全局安装 cnpm ,并且registry 成 淘宝的镜像文件,这一波操作极大了解决了下载速度的问题
npm install -g cnpm --registry=https://registry.npm.taobao.org
- 同一个项目,安装的无法保持一致性。原因是因为 package.json 文件中版本号的特点导致的,下面三个版本号在安装的时候代表不同的含义。
"1.0.1" # 表示安装指定的1.0.1版本
"~1.0.1" # 表示安装1.0.X中最新的版本
"^1.0.1" # 表示安装1.X.X中最新的版本
3.yarn优点
- 底层解决下载问题速度
npm 是串行的按照队列执行每个 package,而 yarn 并行的同步执行所有任务,性能得到了极大的提升。
- 版本安装统一
yarn 中的 lock file 专门记录被安装上的模块的版本号。每次只要新增一个模块,yarn 就会更新 yarn.lock
这个文件。这么做保证了每一次拉取同一个项目依赖时,使用的都是一样的模块版本。
- 输出简洁
npm 在执行 npm install 的时候,命令行里会不断地打印出所有被安装上的依赖,大量无用冗余信息,而yarn在安装过程只会打印出必要的信息
三、yarn的命令变化
- registry 镜像
npm install -g cnpm --registry=http://registry.npm.taobao.org
yarn config set registry 'https://registry.npm.taobao.org'
- 初始化某个项目
npm init
yarn init
- 安装项目默认依赖
npm install
yarn install
- 安装第三方依赖
npm install <package>
yarn add <package>
- 移除依赖
npm uninstall <package>
yarn remove <package>
- 更新依赖
npm update <package>
yarn upgrade <package>
- 安装全局项目依赖
npm install <package>-g
yarn global add <package>
- 安装特定版本号的项目依赖
npm install <package>@1.2.33
yarn add <package>@1.2.33
- 发包/登录/登出操作
npm publish/login/logout
yarn publish/login/logout
- 运行命令
yarn run/test
总结
例如:以上就是今天要讲的内容,本文仅仅简单介绍了yarn和npm的使用命令以及yarn的优点
边栏推荐
- The assignment of member pointer defined in C structure and the use of structure pointer as member function parameter
- 1837.K进制表示下的各位数字总和
- logging基本使用
- Fragment lazy load
- Postman export import
- 企鹅龙(DRBL)无盘启动+再生龙(clonezilla)网络备份与还原系统
- Newbie sees the source code arraydeque
- mother
- SparseArray of the source code for novices
- Linkedblockingqueue of novice source code
猜你喜欢

@Notblank, @notnull, @notempty differences and uses

nmap弱点扫描结果可视化转换

C#笔记

WIRESHARK基础教程以太帧的分析。

pytest 执行规则_基本用法_常用插件_常用断言_常用参数

2021-08-12 function recursion_ Learn C language with brother Peng

344. Reverse string

ESXi6.5补丁更新

232. Implement queue with stack

SCADA and three industrial control systems PLC, DCS and FCS
随机推荐
MFC图片控件
Esxi6.5 patch update
菜鸟看源码之ArrayDeque
Logging learning final edition - configured different levels of log printing colors
mysql学习笔记
How to assemble a registry?
shell 脚本 失败自动重复执行
用两个栈实现队列
242.有效的字母异位词
Traversal recursion + iteration of binary tree
ISO 639:1988 : Code for the representation of names of languages
Sword finger offer (52): regularization expression
ThreadPoolExecutor是怎样执行任务的
MySQL quicklearn-2021-09-01
很多人都不清楚自己找的是Kanban软件还是看板软件
Fragment lazy load
232.用栈实现队列
What are the biz layer and manager layer in the company project
Drbl diskless startup + Clonezilla network backup and restore system
Bash shell学习笔记(七)