Introduction and installation of Node.js Package Manager yarn _node.js

Source: Internet
Author: User
Tags arch linux

Objective

Whether the two days have been quietly Yarn by the screen, Facebook recently released a new Node.js Package Manager Yarn to replace NPM. In order to keep up with the trend of Javascript, I might have tasted this claim to be fast and reliable and safe package management, so the writing will not be very detailed, more likely just for this new package management and NPM differences between. There may be some places that are not well written, if any, please correct me.

First, installation

First of course it is installed. Unlike NPM, a package manager that is picked up and installed with Nodejs, Yarn needs to install it manually. This is understandable, after all, is a new thing. But to be honest, the installation experience is not very good ... it.

Why do you say that? Because my development environment is Arch Linux, and official documents only provide the Apt-get system Linux and Yum system Linux installation mode ...

Since we are replacing NPM, there must be a platform-wide compatibility scenario, and there is a manual installation script for all distributions, so I tried this one, but there were three times without success, all sorts of problems ...

Finally found that, in fact, yarn can be directly like the loading module to use NPM installed:

NPM install-g Yarn

What would it take to replace NPM with a NPM outfit? All right, anyway, it was so loaded, so I said the installation experience is general ... Maybe it would be better for other distributions, perhaps for some Volkswagen distributions and MacOS, the installation is a command to the end of the thing.

Although I am writing this article, the Arch Linux has been installed on the way, yaourt(AUR) but through the way, but I do not think for beginners to manually install Yaourt yarn than directly loaded Nodejs and then npm install simple. Perhaps at this stage, the Arch is a niche distribution compared to what debian/ubuntu/centos.

Second, dependencies Management

The installation section ended like this. Since as a package management, you must do your duty. And then you want to try this new package management is really as amazing as it is advertised. Next, I compare yarn with NPM and CNPM in the same environment. The registry of NPM has been replaced with https://registry.npm.taobao.org due to the special environment within the wall.

Faster

Before comparing, I think this comparison is somewhat unfair to yarn, because NPM has already set up the domestic mirror image, and as soon as this article releases yarn does not have the domestic mirror, therefore does not have the special setting for yarn. I am a little concerned that this will not cause errors in the results of the test.

Yarn since it's a Facebook thing, let's try to set up the react of his family first:

First of all, of course, the protagonist yarn. Note that yarn installation relies on different ways than NPM, and you need to perform the following command to install dependencies:

Yarn Add react
# Same as NPM install react

You can see the yarn installation react used 13.3s, this speed is indeed satisfactory.

Next up is NPM. Because NPM doesn't show the command time, I pinch the stopwatch, about 45s, several times more than yarn. It seems that yarn is a bit faster than NPM, and NPM uses a domestic source.

However, the speed of the CNPM is faster, using only 4s to complete the entire installation process. But after all, CNPM is the derivative of NPM, and it's understandable. Since this thing can improve NPM's speed, who knows if there will be Cyarn? But through this test we can see that the speed of yarn compared to the original NPM is really a qualitative leap, faster is not a wave of fame.

Then I tried to install other packages, and compared them over and over again, on average, the yarn would be 3–6 times faster than NPM (this is the case with smaller packages installed).

Reliable/secure

As to whether this package management is reliable/secure, this I have not thought how to test for a while. I only know that when I use, occasionally have the chance to report some inexplicable errors, but repeated two times to execute the command, and then normal work. After all, yarn is something new and understandable. However, within this day, yarn's GitHub project homepage has won 9K Star,issues and pull request also has thousands of, visible its fiery degree, so for its prospects, I still very optimistic.

Offline mode

One of the highlights of Yarn is that it can be installed offline, of course, if you've ever installed this dependency. Yarn will cache the installed packages, and if the-offline parameter is specified at the next installation, Yarn will remove the package directly from the cache, which will greatly shorten the time of installation dependency.

Unfortunately, despite the official document I read over and over again, this feature still does not work properly in my environment. I'll find out why, and this section will be supplemented later.

But this feature is really a light, can be said to solve the npm of a short board, very lethal short board. With this feature, you can install existing dependencies in an environment where there is no network. and save the download time, greatly improve the efficiency. Imagine not having a long wait of 15 minutes to execute react-native Init later (and, of course, when Facebook replaced the React-native init installation dependency process with its own package management installation.)

Yarn.lock file

Yarn through a yarn.lock file to enable your program to gain a consistent experience on different machines. Although this explanation is very far-fetched, at least I have no machine to turn to everyone to see, already very conscience (fog). Feel this is a very high-end things, in fact, is mainly a supplement to the Package.json.

If you are interested, you can see the detailed introduction here (the need for some English better yo):

Yarn

Fast, reliable, and secure dependency management. Yarnpkg.com

Summarize

Sometimes it's when the eyes are open and a new thing just goes out when you don't know it. Today out of the yarn, tomorrow is uncertain what will appear. Thankfully, we can still catch the early bus for this new gadget.

But it has to be said that the emergence of yarn is indeed progressive, and he solved some of the problems known to NPM and expanded the new features. In this case, it is worth to contact and learn. Although it is a long time to take the place of NPM, it can be expected that its future will be bright.

The above is the entire content of this article, I hope the content of this article for everyone's study or work to bring certain help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.