How to choose a JavaScript dependency framework?

How can I decide whether to use NPM or Bower to install the dependencies?

eg. What's the difference between npm install requirejs --save-dev

and bower install requirejs --save-dev

?

Is there a "best practice" or any way to choose?

Are there others I need to know about?

+3


source to share


3 answers


Use bower for front-end dependencies and NPM for server.

NPM is more focused on server-side libraries, but can be used for front-end. Bower was built for third party libraries.



In addition, NPM uses a nested dependency tree, which is much larger, while the gazebo uses a flat dependency tree.

Also, bower will force you to have only one version of the library, while NPM will allow you to have multiple versions.

+1


source


As @ seth-pollack pointed out, npm is mainly used for server side dependencies and bower for client side. But you can still use npm in front-end development for development dependencies like run-run (Grunt, Gulp, etc.), Test runners, control line, etc. Bower, on the other hand, is mostly used for the dependencies you want available in your deployed application.



+1


source


Bower is better suited for front-end packages and has AMD libraries that you will use with RequireJS, etc.

NPM, on the other hand, has many libraries that are packaged in CommonJS modules. To do this, you need to use a build tool like Browserify to make it usable in the browser.

There is no reason why you shouldn't use one or the other. You will need to choose one that does the job.

0


source







All Articles