Jeff Storey
Jeff Storey

Reputation: 57192

grunt js installing packages

I'm building a grunt javascript project with grunt, and I have a package.json file that looks something like:

{
   ... name, author, etc here ...

   "dependencies": {
      "grunt-html":"0.2.1"
   }

 }

I can run npm install to install grunt-html and this works just fine. But when I add new dependencies, all developers on the team must know to run npm install again. Is there a way to automatically install any packages that have not yet been installed? Should I just run npm install always to ensure I'm up to date?

Upvotes: 16

Views: 16137

Answers (2)

Jesper Tejlgaard
Jesper Tejlgaard

Reputation: 827

I have not tried grunt-install-dependencies (https://github.com/ahutchings/grunt-install-dependencies), but it seems this may fullfill your needs. Just add the command install-dependencies as first task within your custom definfed grunt tasts, e.g.

grunt.registerTask('build', [ 'install-dependencies', 'useminPrepare', ... ]);

Upvotes: 1

Kyle Robinson Young
Kyle Robinson Young

Reputation: 13762

Yes npm install is the easiest way IMO. Getting everyone familiar with the other npm commands makes managing deps easier as well. Such as:

  • npm ls to list out the currently installed modules.
  • Or the --save flag ie, npm install grunt-html --save to install and insert the package and version into your package.json.
  • npm prune to remove modules not included in your package.json.

Other ways to manage dependencies are to commit the node_modules folder in your repository to avoid other devs from having to run npm install. Or for more complex projects consider using npm shrinkwrap to lock down dependencies to specific versions: npm shrinkwrap docs.

Upvotes: 26

Related Questions