Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can yarn be considered a viable option as a replacement for bower and npm?

Tags:

npm

bower

yarnpkg

I should clarify that I'm not that experienced with front-end tools, so I'm sorry in advance if I'm asking something obvious and stupid.

So far I've been using bower for front-end and npm for server-side, although each of the tools mentioned has its advantages and by that I mean flat dependency management of bower (reduces load from the client) and nested dependency management of npm (helps with versioning), it has become quite cumbersome to use so many tools (webpack, browserify, etc.). I may've been using these tools the wrong way and could've used either of them with some option (not known to me) and have been only scratching the surface, I just took this answer as my rule of thumb and have been doing so ever since I've read it. It would be great if I could reduce at least these two to one.

Lately I've become curious about yarn and with all the hype around it, it seems as if it has been doing a good job and as if it will replace npm completely. As I've read the docs I've discovered the --flat option and that made me wonder if it would be possible to use it as bower replacement as well? If so, does it mean I could have either flat or nested dependency manager (by just having multiple JSON files for back- and front-end)?

I would really appreciate if someone could point me in the right direction!

like image 202
orustammanapov Avatar asked Apr 22 '17 17:04

orustammanapov


People also ask

Can Yarn and NPM be used interchangeably?

Yarn can consume the same package. json format as npm, and can install any package from the npm registry. This will lay out your node_modules folder using Yarn's resolution algorithm that is compatible with the node.

What is difference between Yarn and NPM?

The major difference between NPM and Yarn comes in terms of security performance. While NPM installs packages sequentially, Yarn performs parallel installation resulting in better speed and performance. NPM has tried to fix vulnerabilities, but still, Yarn is considered more secure than NPM.

Is Bower still relevant?

Bower has been deprecated by its creators The open source project continues to be maintained for the benefit of existing users, but this is a prime reason not to continue using the platform.

What is Bower and Yarn?

Bower and Yarn can be primarily classified as "Front End Package Manager" tools. "Package management" is the primary reason why developers consider Bower over the competitors, whereas "Incredibly fast" was stated as the key factor in picking Yarn. Bower and Yarn are both open source tools.


1 Answers

It depends on your exact use case, but... probably.

Currently, the major trend seems to be towards module bundlers such as Webpack and Browserify (and hence either npm or Yarn) and away from Bower. You can read an excellent overview of the situation at NPM vs. Bower vs. Browserify vs. Gulp vs. Grunt vs. Webpack, along with some reasons why you might want Webpack instead of Bower.

At the minute, you're probably using HTTP, where it works out faster to have one JavaScript bundle file rather than lots of source files (as would occur with Bower). That's why Webpack and Browserify are so popular (among other reasons) — they should increase performance and simplify development a lot.

Side note: HTTP/2 will diminish the value of module bundling, because multiple requests will become far less costly. See What is the value of using Webpack with HTTP/2 for a more detailed description of the issues involving HTTP/2.

If you use npm or Yarn, it shouldn't really matter if the dependencies are nested—your frontend dependencies will all be bundled anyway with Webpack/Browserify, so the main cost of using nested packages is that it takes up more space and more download time.

Since npm v3 and Yarn can do flat installs, there shouldn't be any issues with that anyway. In short: you probably can do it, and many other people are doing exactly that.

like image 51
Aurora0001 Avatar answered Sep 23 '22 14:09

Aurora0001