facebook推出的快速、可靠和安全依赖关系JavaScript包管理工具,完全有替代npm的势头。
.
特点
快速:yarn 会缓存每个已经下载了的程序包,所以它永远不需要再下载。它能使操作资源利用率的最大化,所以多次安装比以往任何时候都更快。
可靠:使用(内容)详尽的而(方法)简洁的(方式)并使用lockfile和决定性算法来安装包,yarn 可以保证只要安装运行在一个系统上,也将以完全相同的方式运行在其他系统上。yarn 能够为参与一个项目的所有用户维持相同的节点模块(node_modules)目录结构,有助于减少难以追踪的bug和在多台机器上复制。
安全:yarn 在每一个安装包代码执行前,使用校验和的方式去验证包的完整性。
.
功能
1、离线模式 Offline Mode
如果你已经安装了一个包,您可以再安装一遍(在其他地方)没有互联网连接。—相对于npm的重新在线下载方式的改进2、确定性的 Deterministic
相同的依赖相同的方式将被安装在每台机器无论安装顺序。3、网络性能 Network Performance
yarn 高效队列请求和避免请求瀑布为了最大化网络利用率。4、多路注册 Multiple Registries
不管是从npm还是Bower上安装的任何包文件,都能让工作流程是一样的。意思就是,兼容npm 和bower 上面注册表,上面的包同样可以在yarn上使用,文件的配置和npm一样,经过实践可以通用。
5、网络弹性(重载能力) Network Resilience
单个请求失败不会导致安装失败。请求失败后会重试。相对npm的返回错误问题。6、扁平化加载模式 Flat Mode
解决失配版本的依赖单一版本避免创建副本。有点像npm 3.0以上版本一下,node_moudle避免嵌套路径太深导致的相关问题。
.
安装
1、官网介绍 macOS/windows/linux/Alternatives 下的安装方法
2、npm安装方式
npm install -g yarn
.
使用方法
1、创建一个新项目,运行命令后,填写相应的信息会生成一个 文件
yarn init
2、添加、更新、删除 一个依赖包文件
#添加
yarn add [package]
yarn add [package]@[version]
yarn add [package]@[tag]
#更新
yarn upgrade [package]
yarn upgrade [package]@[version]
yarn upgrade [package]@[tag]
#删除
yarn remove [package]
3、根据 安装所有依赖方法
yarn
#或者
yarn install
4、其他使用方法和npm基本相同,如下所示
Usage: yarn install [flags]
Options:
-h, --help output usage information
-V, --version output the version number
--offline
--prefer-offline
--strict-semver
--json
--global-folder [path]
--modules-folder [path] rather than installing modules into the node_mod
ules folder relative to the cwd, output them here
--packages-root [path] rather than storing modules into a global packag
es root, store them here
--mutex [type][:specifier] use a mutex to ensure only one yarn instance is
executing
--har save HAR output of network traffic
--ignore-engines ignore engines check
--ignore-scripts
--ignore-optional
--force
--flat only allow one version of a package
--prod, --production
--no-lockfile don't read or generate a lockfile
--pure-lockfile don't generate a lockfile
-g, --global DEPRECATED
-S, --save DEPRECATED - save package to your `dependencies`
-D, --save-dev DEPRECATED - save package to your `devDependenci
es`
-P, --save-peer DEPRECATED - save package to your `peerDependenc
ies`
-O, --save-optional DEPRECATED - save package to your `optionalDepen
dencies`
-E, --save-exact DEPRECATED
-T, --save-tilde DEPRECATED
参考:
yarn官网链接
github上yarn项目链接