What is the yarn, how to use the yarn installation project dependencies

A, yarn Description:

  Yarn is a substitute npm package management tool facebook release.

Two, yarn features:

1. super-fast.
Yarn caches every downloaded package, so no need to repeat the download when used again. While taking advantage of parallel downloads to maximize resource utilization, therefore installation faster.
2. super safe.
Before executing code, Yarn will each installation package integrity check by the algorithm.
3. super reliable.
Use detailed, concise and clear format file lock installation algorithm, Yarn can guarantee no difference in the different systems work.

Three, yarn installation:

Download node.js, using npm install

npm install -g yarn

View Version:

yarn --version

Yarn Taobao installation source

yarn config set registry https://registry.npm.taobao.org -g
yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass -g

Four, yarn commonly used commands:

Installation yarn
npm install -g yarn
after the installation is successful, check the version number:
yarn --version
create folders yarn
md yarn
into the yarn folder
cd yarn
initialize project
yarn init // with npm init, after the input that will be generated package. json file
yarn configuration items:
yarn config // List displays all configuration items
yarn config get // display a configuration item
yarn config delete // delete a configuration item
yarn config set [-g | --global] // set the configuration item
installation package:
the Yarn install // install package.json in all packages, and package and all its dependencies save into yarn.lock
the Yarn install --flat // installation single version of a package of
yarn install --force // forced to re-download all the packages
yarn install --production // only install dependencies in the package
yarn install --no-lockfile // not read or generate yarn.lock
the Yarn install - -pure-lockfile // does not generate yarn.lock
added package (updated package.json and yarn.lock):

yarn add [package] // add a dependency package in the current project will be automatically updated to the package.json and yarn.lock files
yarn add [package] @ [version ] // install the specified version, here it refers to the main version, if you need accurate to the small version, use the -E parameter
yarn add [package] @ [tag ] // install a tag (such as beta, next or Latest)
// do not specify the type of installation to rely dependencies in default, you also You can specify dependency types:

yarn add --dev / -D // added devDependencies
the Yarn --peer the Add / -P // added peerDependencies
the Yarn --optional the Add / -O // added optionalDependencies
// default installation package of the latest major version version, the following two commands can be specified version:

yarn add --exact / -E // accurate version of the installation package. For example yarn add [email protected] will accept version 1.9.1, but the yarn add [email protected] --exact only accept version 1.2.3
minor release yarn add --tilde / -T //'s installation package the latest version. For example yarn add [email protected] --tilde will accept 1.2.9, but does not accept 1.3.0
release package

yarn publish
remove a package
yarn remove : The removal of one package, and automatically updates package.json yarn.lock
update a dependency
yarn upgrade package for updating to the latest version based on the range specification
operation script
script attribute definition scripts in the yarn run to perform package.json
display information about a package of
yarn info A module can be used to view the latest version information
cache
the Yarn Cache
the Yarn Cache List # cached list of each package
yarn cache dir # Returns the global cache location
yarn cache clean # Clear Cache

Five, npm compared with yarn command:

For example, your project module dependency diagram is described, @ represents the version 1.2.1 of this module. When you install the A's need to rely on C and D, many rely not specify a version number, default will install the latest version, this problem occurs: for example, when installing modules C and D today is a version, and when after the C, D update, re-installing the module will install the latest version of the C and D, if the new version can not be compatible with your project, your program might a BUG, ​​can not even run. This is the npm drawbacks, and yarn in order to solve this problem yarn.lock launched a mechanism, which is yarn.lock file of the project.

We will see that this file has been dependent on module to lock the version number of all, when you execute the yarn install, yarn reads this file to obtain version-dependent, then follow the version number to install the corresponding dependent module, so dependence will be locked, and never have to worry about the version number. Others or when used under other circumstances, this yarn.lock copied to the corresponding environmental projects can be re-installed.
Note: This file is not manually modify it when you use some operation such as yarn add, yarn is automatically updated yarn.lock.

Guess you like

Origin www.cnblogs.com/jtjianfeng/p/12174982.html