转载请注明出处,谢谢
yarn是什么?
yarn是由Facebook、Google、Exponent 和 Tilde 联合推出了一个新的 JS 包管理工具,yarn是为了弥补 npm 的一些缺陷而出现的
yarn和npm的主要区别介绍
-
yarn存在本地缓存,无需互联网链接就能安装本地缓存的依赖项,提供了离线模式,而这个是npm实现不了的。
-
yarn解决了由于语义版本控制而导致的npm的不确定性问题,通过安装时创建的默认文件,确保使用的库的版本相同。
-
yarn增加了一些能让开发人员并行化处理所有必需的操作,且通过添加了一些改进,使得运行速度有了显著的提升,整个安装时间也变得更少。
-
npm的输出信息比较冗长,相比之下,yarn简洁很多。默认情况下,直观且直接地打印出必要的信息。
-
yarn的语义相对于npm更加清晰
npm和yarn命令对比
| npm | yarn | 作用 |
|---|---|---|
| npm -v | yarn -v | 查看电脑所安装npm包的版本号 |
| npm i | yarn | 自动检索下载依赖包 |
| npm init | yarn init | 初始化 |
| npm init -y | yarn init -y | 默认方式初始化 |
| npm i 包名 | yarn add 包名 | 安装包 |
| npm i 包名@版本号 | yarn add 包名@版本号 | 安装指定版本的包(注意无空格) |
| npm uninstall 包名 | yarn remove 包名 | 删除包 |
| npm ls | \ | 查看本地模块 |
| npm ls -g | \ | 查看全局模块 |
| npm update 模块包名 | arn upgrade 包名 | 更新包 |
| npm search 模块包名 | \ | 搜索模块 |
| npm publish 模块包名 | \ | 发布模块 |
yarn代理地址设置
//查看代理
yarn config list
//切换源为国内淘宝镜像
yarn config set registry https://registry.npmmirror.com
npm config set registry https://registry.npmmirror.com
yarn config set registry https://registry.npm.taobao.org (旧地址 失效)
npm https认证取消
npm config set strict-ssl false//取消npm的https认证
yarn config set strict-ssl false//取消yarn的https认证
清除缓存
npm cache clean --force