Introduction and installation of node. JS Package Manager yarn

Source: Internet
Author: User

FAST, RELIABLE, and SECURE DEPENDENCY MANAGEMENT.

Just yesterday, Facebook released a new node. JS Package Manager Yarn to replace NPM . Although I am a half-bucket of water in the front, but also to keep up with Javascript this wave ( Huang) footsteps, so the following article. Probably a bit of a taste of this claim is fast and reliable and secure package management, so the content will not be written in detail, more likely just for this new package management and NPM differences to compare. There may be some places that are not well written, and if so, Huanhuan (DA) refers (a).

Installation

First of all, of course it's installed. Unlike npm 's hand-picked package manager, which is installed with Nodejs ,Yarn needs to be manually installed by itself. It's understandable, after all, it's a brand new thing. But frankly speaking, the installation experience is not very good ... it.

Why do you say that? Because my development environment is Arch linux , the official documentation only provides apt-get linux and how yum Linux is installed ...

Since the aim is to replace npm , then there must be a platform-wide compatibility program, and sure enough, there is a manual installation script for all distributions, so I tried this, but loaded three times without success, various problems ...

Finally found that yarn can be directly like a module installed in npm :

NPM install-g Yarn

Ah, huh? A thing to replace NPM , and actually have to use npm to install it? excuse me ? Well, anyway, it's like this, so I said the installation experience is like ... Maybe it might be better for the other distributions, and maybe for some VW distributions and MacOS , the installation is a command to get into the terminal.

Although as of this time I wrote this article, already had the installation method on the Arch Linux , but through the yaourt (AUR) Way, But I don't think that for a novice to manually install yaourt and then install yarn More than just install nodejs and then npm Install is simple. Maybe at this stage, Arch is a niche distribution than what debian/ubuntu/centos ...

Dependencies Management

The installation section is so over. As a package management, it is necessary to do their own duty. The next thing you want to try is whether the new package management is really as magical as it is advertised. Next i compare yarn to 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 inside the wall .

FASTER

Before comparing, I think this comparison is somewhat unfair to yarn , because npm has set a domestic mirror, and as of this article published Yarn does not have a domestic image, so there is no special setting for yarn . I'm a little worried that this will not cause errors in the results of the test.

Since Yarn is a Facebook thing, let's try to install the React of his home first:

First of all, of course, the protagonist yarn . Note that yarn installation relies on a different way than npm , and you need to execute the following command to install dependencies:

Add react
NPM Install react

You can see yarn installed React 13.3s , this speed is really satisfactory.

Next is npm . Because npm does not show command time, I pinch the stopwatch, which is about 45s , and is several times more than yarn . It seems that yarn is a bit faster than npm , and npm is a domestic source.

However, the speed of the cnpm is faster, only 4s completed the entire installation process. But after all, cnpm is a derivative product of NPM , in a sense. Since this thing can improve the speed of npm , who knows if there will be cyarn ? But through this test we can see that yarn speed compared to native npm is really a qualitative leap, FASTER is not the wave of fame.

Next I tried to install the other packages, several times compared, the average yarn will be faster than NPM 3–6 times (This is the case of installing smaller packages).

Reliable/secure

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

Offline mode

One of the highlights of Yarn is the ability to install dependencies offline, of course, if you've ever installed this dependency. Yarn caches the installed packages, and if you specify the -offline parameter at the next installation, yarn will take the package out of the cache. This will significantly shorten the time to install dependencies.

Unfortunately, despite the official documentation I have read over and over again, this feature is not working properly in my environment. I'll find out why, this paragraph will add later.

But this feature really is a bright, can be said to solve the npm A short board, very deadly short board. With such a feature, the existing dependencies can be installed in the future without the network environment. It also saves time for downloading and greatly improves efficiency. Imagine not having to wait 15 minutes for a long time to execute react-native init and not be happy (of course, when Facebook React-native init installation depends on the process for the installation of your own package management or unknown AH).

Yarn.lock file

Yarn is a yarn.lock file that allows your program to have a consistent experience on different machines. Although this explanation is very far-fetched, at least I do not have the machine turned to everyone, already very conscience (fog). It feels like this is a very high-end thing, in fact, is mainly a supplement to Package.json .

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

Yarn

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

Summary

Suddenly such as the night Breeze, thousand trees million tree pear blossom. Sometimes it is when the eyes are opened and closed, a new thing is in the open when you do not know it. Today, out of yarn, tomorrow means what will happen. Fortunately, we can still catch the early bus of this new gadget.

Remember that in recent days a high-end haven (fog) describes the experience of learning Javascript in the 2016 (see here: how It feels to learn Javascript ), indeed, this language A year's development alone is enough to choke a lot of people.

But it has to be said that yarn 's appearance is really progressive, and he has solved some of the problems that npm has known and expanded the new features. In this case, it is worth to contact and learn. Although there is a long way to go to replace npm , it can be expected that the future will be bright.

Introduction and installation of node. JS Package Manager yarn

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.