Dancer Dancer - 1 year ago 150
Javascript Question

GRUNT - Install Grunt Packages?

Can anyone advise what I'm doing wrong here (i'm new to grunt) a colleage has supplied me with a base gruntfile setup

enter image description here

I have installed node,js, and grunt but I cant figure out how to install the various packages (uglify, concat etc) - which command should I use for this?

Answer Source

The first question you must ask yourself is, "what are the names of the grunt dependencies?"

The quick answer:

Simply execute the npm install <package-name> for each package you wish to install. For the most part, I consider the package-names to be equivalent to their github name. ( grunt-contrib-concat for example. )

npm install grunt-contrib-concat will install it, then go on to the next.

Improving Maintainability:

For optimal maintainability and cross developer/environment support you should consider using package.json to list your dependencies.

Once you have all of your dependencies listed in package.json, you can then run npm install and all of them will be installed should the need ever arise. (For development based dependency vs runtime/production based dependency management, read on!)

Best Practices:

The optimal workflow with node js is to use npm init first, so that your package.json file is created for you. then once you have a package.json, you can install each of your dependencies/devDependencies by either adding them to their respective lists in the json file or adding them to their respective lists on the fly by using npm install <package name> --save or --save dev respectivly.

NOTE: IF you are experimenting, and you'd rather NOT save a node module to your dependency list, then a simple npm install <package name> will do.

At this point, I do recommend searching for npm package.json best practices - as you will find some valuable information regarding your workflow for nodejs. Dependency management can be amazing, but only if you know how to really take advantage of the utilities provided.

Consider the following excerpt from a package.json file:

  "dependencies": {
    "backbone": "*",
    "underscore": "~*",
    "requirejs": "*"
    "jquery": "*"
  "devDependencies": {
    "grunt": "*",
    "grunt-contrib-uglify": "*",
    "grunt-contrib-concat": "*",
    "grunt-contrib-copy": "*"

The example we see is that the npm packages under dependencies will install when running npm install --production, the development packages will be installed automatically when running npm install --development,

NOTE: You can change your node environment as well which modifies the usage of a simple npm install with no flags.

For the most part, grunt is used for development, so I believe it would be more common to find anything related to grunt being in devDependencies

A sample package.json:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download