Quantcast
Channel: CodeSection,代码区,数据库(综合) - CodeSec
Viewing all articles
Browse latest Browse all 6262

Testing yarn, a fast npm for JavaScript

$
0
0

TL;DR: It’s crazy fast and you should get it asap

Hello,

Today, a group of engineers from Facebook, Google, Exponentjs and Tilde released a new tool called yarn . It’s a new tool aiming to replace npm and all the headaches introduced by this tool: slow installation…

The first step is to download the installation from the official website (I’m a windows user), or use the appropriate installation for linux or macOS.

Init a newproject

The command is like npm:

yarn init

It keeps asking you about project name, author… But after that it creates a basic package.json file, no big deal here.

Next step I tried the -y flag:

yarn init -y

It’s actually not working, just for the records.

Installing a simplepackage

Next test was installing a simple package: express.

Using npm: 11.99s

Using yang: 8.3s

Not bad. In fact, yarn cache your already downloaded packages for later use. So let’s try installing express one more time:

Using yang (2nd time): 1.33s

Well, that was fast…

Note:I know I need to run multiple times to get an average and all that… But this is just an article giving you a first glimpse and not a technical one.

In addition to this, you will have a new generated file called yarn.lock , it contains information about your installed packages and you project in general. So anyone forking your project will get the same thing inside the node_modules (wasn’t possible using npm).

Installing a complex package

Now let’s install a complex package: React native

Using npm: 334s

Using yarn: 265.93s

Note:Looks like yarn automatically detected that I don’t have a dependency (react) and downloaded it automatically, so the time can be less if it was already there.

In fact, React Native has a lot of dependencies! And the difference is just mind blowing…

That was the first time, if you ever want to install React Native from now on, all you need is:

Using yarn (2nd time): 77.18s

OK, that’s a lot of time saved.

I think I’ll use it from now on.

Thank you for reading:)


Viewing all articles
Browse latest Browse all 6262

Trending Articles