简体   繁体   中英

Better to install underscore via NPM or Bower?

I'm building a NodeJS app and using UnderscoreJS. Would it be more applicable as a Bower or NPM installation? Is there actually any difference? I'm using it on front and back-end. What's the proper way?

It's already answered here : What is the difference between Bower and npm?

So, Here is the answer:

npm is most commonly used for managing Node.js modules, but it works for the front-end too when combined with Browserify and/or $ npm dedupe.

Bower is created solely for the front-end and is optimized with that in mind. The biggest difference is that npm does nested dependency tree (size heavy) while Bower requires a flat dependency tree (puts the burden of dependency resolution on the user).

A nested dependency tree means that your dependencies can have its own dependencies which can have their own, and so on. This is really great on the server where you don't have to care much about space and latency. It lets you not have to care about dependency conflicts as all your dependencies use eg their own version of Underscore. This obviously doesn't work that well on the front-end. Imagine a site having to download three copies of jQuery.

The reason many projects use both is that they use Bower for front-end packages and npm for developer tools like Yeoman, Grunt, Gulp, JSHint, CoffeeScript, etc.

All package managers have many downsides. You just have to pick which you can live with.

Using Bower is better. This allows you to automatically keep your dependencies up to date, plus you can add them to index automatically with grunt.

bower install underscore; grunt bowerInstall;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM