Yarn is a new JS package management tool from Facebook, Google, Exponent and Tilde. As the official documentation states, Yarn has emerged to remedy some of the shortcomings of NPM

Installation of yarn

  • NPM install yarn -g
  • Brew Install YARN

Installation through NPM is generally not recommended. NPM installations are nondeterministic, packages are not signed, and NPM does no integrity checking beyond basic SHA1 hashing, which poses a security risk for installing system programs.

For these reasons, it is strongly recommended that you install YARN using the installation method that is most appropriate for your operating system.

The advantages of the yarn

  • Fast installation (fast server and parallel download)
  • Version of the lock
  • Caching mechanisms

Compared with NPM

  • NPM is sorted by package, that is, the queue is downloaded one by one, after one is downloaded, the other is downloaded
  • Yarn is the package to be downloaded at the same time

NPM problem

For example, if you have a project module dependency, @1.2.1 represents the version of that module. When you install A, you need to install dependencies C and D. Many dependencies do not specify A version number, and the latest version is installed by default, which causes problems: For example, when you install the module today, C and D are of the same version, and when you install the module later, the latest version of C and D will be installed. If the new version is not compatible with your project, your program may have bugs or even cannot run. This is the downside of NPM, and Yarn has introduced yarn.lock to solve this problem

When you execute YARN install, Yarn reads the file to obtain the version number of the dependency, and installs the dependency based on the version number. In this way, the dependency is locked, and you do not need to worry about the version number. To use yarn.lock in other environments, copy the yarn.lock file to the corresponding environment project and install it.

Common commands

  • Add package (updates package.json and yarn.lock) :
Yarn add [package] // Add a dependency package to the current project, which is automatically updated to package.json and yarn.lock. Yarn add [package]@[version] // Install the specified version, which is the main version. Yarn add [package]@[tag] // Install a tag (such as beta,next, or latest). Yarn add --dev/ -d // add to devDependencies yarn add --peer/ -p // add to peerDependencies yarn add --optional/ -o // Add to OptionalDependencies // Latest version in the main version of the default installation package. You can specify the version using the following commands: yarn add --exact/ -e // Exact version of the installation package. For example, yarn add [email protected] accepts version 1.9.1, but yarn add [email protected] --exact accepts only the latest version in the minor version of the 1.2.3 yarn add --tilde/ -t/installation package. For example yarn add [email protected] -- Tilde will accept 1.2.9 but not 1.3.0Copy the code

Common command NPM comparison

NPM init ---- yarn init NPM install ---- yarn NPM install [email protected] -g ---- yarn global add ---- NPM install [email protected] --save ---- yarn add [email protected] NPM install [email protected] --save-dev yarn add ---- --dev NPM uninstall xxx --save(-dev) ----yarn remove xxx npm run xxx ---- yarn run xxxxCopy the code

Refer to the reading

  • www.cnblogs.com/mumusen/p/9…

The article finally

If you think this article is helpful to you, remember to like three even oh, can also scan code to pay attention to my newly established front-end technology public number [have you front end], after all my articles will be synchronized to the public number above. In addition, I built a can help us programmers to take off the single public number, every week will push a few excellent single little sister, if you are a programmer technology is good and just single, then you can scan the following code concern [cause come you are a program ape] public number to open your single journey.