What is yarn?

Dependencies management tool npm we all know, the basic common commands we all understand, there is not much to say. We talk about direct straight to the point, npm what little problem. In fact, I spent so long how many have some mixed feelings. Npm is easy to use. But npm origin in foreign countries, domestic users will be very inconvenient to use, inconveniences that download slowly. Then we will have to replace cnpm, but cnpm can cause packet loss, downloading dependencies may cause problems, and so on and so on a number of uncertainties.

Slow download speed is one of the problems of npm problems. Another big problem is that npm in the same project for the dependencies of the installation can not maintain consistency. As an example to illustrate:

Usually present package.json file for records related to rely on our project, but the manifestation of which depend record is not uniform.

"5.0.3",
"~5.0.3",
"^5.0.3"

"5.0.3" indicates the specified version 5.0.3 installed, "- 5.0.3" indicates the latest version 5.0.X installed, the "^ 5.0.3" indicates that the latest version is installed in 5.XX.

It is unfortunate, often appear on the same project, and some colleagues after installation dependencies are OK, and some colleagues due to the installation of version inconsistencies cause bug. Because as time goes by, there are dependencies upgrades and changes. Some packages may depend little change, the basic reference dependencies does not change, but there is a number of dependencies inside its dependencies change, we can not use normal.

When installed, the package will be downloaded and installed at the same time, sometime in the middle, a package throws an error, but npm will continue to download and install the package. Because all log npm will output an error message to the terminal, about error packets are lost out in a lot of warning npm printed, and you'll never even notice the error actually occurred.

According to the above content that we spit bad, affect our mood is for two reasons:

  • npm download dependencies of network problems
  • npm version inconsistent pain points

Some say the pain points, then the deposit does not solve these pain points of presence, of course, there is on the one hand npm themselves are constantly updated, on the other hand what we say today yarn.

What is yarn

"Yarn by Facebook, Google, Exponent and Tilde jointly launched a new JS package management tool, as an official document written, yarn to make up for some shortcomings of the emergence of npm. He did not completely replace npm. Sentence words mean, npm is useful, not to say back to the yarn would not npm ~

yarn advantage

  • high speed. Fast mainly from the following two aspects:
  1. Parallel installation: npm whether or yarn during the installation package is executed, will perform a series of tasks. npm each package is executed in accordance with the queue, that is to say have to wait until after the current package installation is complete, you can continue the installation later. The Yarn is synchronized to perform all tasks, improving performance.
  2. Offline mode: If a package before between already installed, install again with yarn obtained from the cache, you do not like to download from the network as a npm.
  • Installation unified version: In order to prevent pulling to a different version, yarn have a locking file (lock file) recorded the version number of the module on the exact installation. Every time a new module, yarn is created (or updated) yarn.lock this file. Doing so ensures that each time when pulling the same project dependencies, module versions are the same use. npm In fact, there are ways to achieve everywhere packages use the same version, npm5 will generate more than a locked file, in the implementation of npm install the lock file will first be read, and read yarn.lock yarn file a reason.
  • More concise output: output npm relatively lengthy. In performing npm install, the command line will continue to print out all depend on the installation. In contrast, yarn too simple: By default, combined with the intuitive and emoji directly print out the necessary information, but also provides commands for developers to query additional installation information.
  • Multi-source registration process: all dependencies, when no matter how many times he was quoted indirectly associated with different libraries, install this package, only from a registered source to install either npm either bower, to prevent inconsistencies confusion.
  • Better semantics: yarn changed some names npm commands, such as yarn add / remove, to feel more clearly than the original npm install / uninstall.

yarn Instructions Introduction

How to install yarn?

Method One: npm install yarn -g

Method two: go to the official website to download the installation package yarn (recommended)

Official website address: https: //yarnpkg.com/zh-Hans/docs/install#windows-stable

In general, it is not recommended by npm Yarn mounted, with the package when the Node Manager Yarn based installation, the package is not signed, and the unique integrity check only basic SHA1 hashing. This is a security risk when installing system-level applications. For these reasons, highly recommended for your operating system, the most appropriate way to install Yarn

yarn common commands What? Comparison and command npm

Compared Npm default configuration, yarn won a lot of praise. Which can easily generate a file lock, dependent on the mounting is very rapid, and automatically add package.json, while installation costs and the use of the yarn is extremely small, so that the yarn become the new show.

Guess you like

Origin blog.csdn.net/weixin_40851188/article/details/91916910