Last Updated: February 25, 2016
·
1.305K
· callmephilip

using bower in grunt

After looking at several grunt tasks out there trying to accomplish package installation using bower through grunt, I realized that it was actually easier to take advantage of Bower's API wrapped in a tiny custom grunt task:

grunt.registerTask('bower', 'Install js packages listed in bower.json', 
    function() {
        var bower = require('bower');
        var done = this.async();

        bower.commands.install()
            .on('data', function(data){
                grunt.log.write(data);
            })
            .on('error', function(data){
                grunt.log.write(data);
                done(false);
            })
            .on('end', function (data) {
               done();
            });
     }
);

This uses standard .bowerrc for Bower specific settings and bower.json for the list of the dependencies to install