实践Yarn(Yarnpkg)

介绍

Yarn(Yarnpkg), Fast, reliable, and secure dependency management.

安装

1
2
$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
1
$ sudo apt-get update && sudo apt-get install yarn

备注:貌似~/.yarn/bin需要加入环境变量PATH中,否则无法全局使用。

基本使用

Starting a new project

1
$ yarn init

Adding a dependency

1
2
3
4
5
$ yarn add [package]
$ yarn add [package]@[version]
$ yarn add [package]@[tag]
# 全局
$ yarn global add [package]

Adding a dependency to different categories of dependencies

Add to devDependencies, peerDependencies, and optionalDependencies respectively:

1
2
3
$ yarn add [package] --dev
$ yarn add [package] --peer
$ yarn add [package] --optional

Upgrading a dependency

1
2
3
$ yarn upgrade [package]
$ yarn upgrade [package]@[version]
$ yarn upgrade [package]@[tag]

Removing a dependency

1
$ yarn remove [package]

Installing all the dependencies of project

1
$ yarn

or

1
$ yarn install