It’s 8102 years. Why are you still using yarn?!


Original source: yarn vs NPM

Still remember the scene when yarn first came out

It’s really fast. Every time yarn install, it will save me several minutes.

Yarn will ensure that your node_modules folder matches the node_modules folder of your colleagues. Similarly, the node_modules folder on the server is exactly the same as yours. There will be no inconsistent version of the package version, and there will be no more words on the computer.

Six months later

The new version of npm.v5 has brought speed improvement and version locking. Yes, that’s the most important reason why we just abandoned NPM to invest in yarn.

Now, many developers are muttering:Is it necessary for me to use yarn?

I think it’s time to throw into the warm embrace of NPM again!

NPM is as fast as yarn

Please check by yourself:

# Backup
mv node_modules node_modules_backup
mv package-lock.json package-lock.backup.json
mv yarn.lock yarn.backup.lock

# Test cold npm speed
time npm install

# Reset modules
rm -Rf node_modules

# Test warm npm speed
time npm install

# Test cold yarn speed
time yarn install

# Reset modules
rm -Rf node_modules

# Test warm yarn speed
time yarn install

# Reset
rm package-lock.json
rm yarn.lock

# Restore
mv node_modules_backup node_modules
mv package-lock.backup.json package-lock.json
mv yarn.backup.lock yarn.lock

I ran it three times, almost at the same speed.

Easily switch NPM version

Bob installed yarn v1.1 and Brenda installed yarn v1.2. When they add or remove dependency packages in the project, they will make yarn modify the yarn.lock file. But in the two yarn versions, the lock file is slightly different, which is not a good thing.

You can indicate in package. JSON which version of yarn your project should use.
But what if you have multiple projects, and the yarn required for each project is different?
You should use NPM to install multiple yarn versions: NPM install yarn @ 1.1 — global, NPM install yarn @ 1.2 — global. But you need to reinstall yarn every time you switch projects, which is terrible!

NPM can easily switch versions!

Using NVM or n-click to switch NPM version is so simple and convenient!
It's 8102 years. Why are you still using yarn?!

Manage your workspaces with lerna

If you are using yarn’s workspaces feature, in NPM, you can replace it with lerna, which provides all the features yarn has, but also extends some new functions: managing the workspace version, executing commands in the workspace, and publishing workspaces.

Using NPM check to upgrade interactively

The yarn upgrade interactive command is great:

It's 8102 years. Why are you still using yarn?!

NPM check can also be used in NPM to realize this function:

It's 8102 years. Why are you still using yarn?!

npm install npm-check –save-dev
Add script:

    "scripts": {
        "upgrade-interactive": "npm-check --update"

Then, NPM cannpm run upgrade-interactiveNow.

Yarn is getting complicated

Although NPM and yarn are shown in readme of many projects, they are not necessary. For example, the readme of the create react app project:

npm run build or yarn build
Builds the app for production to the build folder.

What is yarn’s role here? None.
It’s absolutely confusing for the novice. Which command should I run? What is yarn? Do I need it?

Choosing yarn means that your team will have to use yarn. JavaScript’s ecology is very complex. Do we really need to add more fuel to yarn?

I hope that the yarn team will put their outstanding work directly into NPM to make our life a little better.

Take off, NPM!

When I switch back to NPM, I find that the NPM run command has automatic completion function, which is very good! While yarn may do the same, NPM is the big brother!
NPM also has other new functions, such as NPM audit, which can scan the existing vulnerabilities in your project.

NPM is fast enough, NPM community is mature enough, and some packages give NPM more powerful vitality! Forget about yarn!

Recommended Today

Vue、Three. JS implementation panorama

1、 First, we need to create a Vue project This paper mainly records the process of building panorama in detail, so building Vue project is not described too much. 2、 Install three js npm install three –save npm install three-trackballcontrols –save npm install three-orbit-controls –save npm i three-obj-mtl-loader –save npm i three-fbx-loader –save npm i […]