javascriptgruntjsbower

Difference between Grunt, NPM, and Bower (package.json vs bower.json)


When I want to add a package (and check in the dependency into git), where does it belong - into package.json or into bower.json?

From what I gather,
running bower install will fetch the package and put it in /vendor directory,
running npm install it will fetch it and put it into /node_modules directory.

This SO answer says bower is for front-end and npm is for backend stuff.
Ember-app-kit seems to adhere to this distinction from the first glance... But instructions in gruntfile for enabling some functionality give two explicit commands, so I'm totally confused here.

Intuitively I would guess that

  1. npm install --save-dev package-name would be equivalent to adding the package-name to my package.json

  2. bower install --save package-name might be the same as adding the package to my bower.json and running bower install?

If that is the case, when should I ever install packages explicitly like that without adding them to the file that manages dependencies (apart from installing command line tools globally)?


Solution

  • Update for mid 2016:

    The things are changing so fast that if it's late 2017 this answer might not be up to date anymore!

    Beginners can quickly get lost in choice of build tools and workflows, but what's most up to date in 2016 is not using Bower, Grunt or Gulp at all! With help of Webpack you can do everything directly in NPM!

    Don't get me wrong people use other workflows and I still use GULP in my legacy project(but slowly moving out of it), but this is how it's done in the best companies and developers working in this workflow make a LOT of money!

    Look at this template it's a very up-to-date setup consisting of a mixture of the best and the latest technologies: https://github.com/coryhouse/react-slingshot

    Your questions:

    When I want to add a package (and check in the dependency into git), where does it belong - into package.json or into bower.json

    If that is the case, when should I ever install packages explicitly like that without adding them to the file that manages dependencies (apart from installing command line tools globally)?

    Always. Just because of comfort. When you add a flag (--save-dev or --save) the file that manages deps (package.json) gets updated automatically. Don't waste time by editing dependencies in it manually. Shortcut for npm install --save-dev package-name is npm i -D package-name and shortcut for npm install --save package-name is npm i -S package-name