Skip to content

Instantly share code, notes, and snippets.

Created Jul 3, 2014
What would you like to do?
Gulp task to run bower install/update and remove dependencies.
var gulp = require('gulp');
var bower = require('bower');
var del = require('del');
var _ = require('lodash');
var deleteDeps = function (deps, cb) {
var path = bower.config.cwd + "/" +;
_.each(deps, function (dep) {
del(path + "/" + dep, function (e) {});
var bowerTask = function (fn, cb) {
var deps = _.chain(require(bower.config.cwd + '/bower.json').dependencies).keys().value();
var pkgs = [];
.on('log', function (o) {
if ( !== 'install') {
.on('end', function (installed) {
deleteDeps(_.difference(pkgs, deps), cb);
gulp.task('bowerInstall', function (cb) {
bowerTask('install', cb);
gulp.task('bowerUpdate', function (cb) {
bowerTask('update', cb);
Copy link

newtriks commented Jul 3, 2014

I use this task when using Restangular (not Browserify compatible) in a Browserify based project. Restangular dependencies include Angular and Lodash, I already have these via npm, so do not need the duplication.

This takes no prisoners, all dependencies of the installed packages are removed!

If I have missed a Bower configuration option that disables installing dependencies I would be keen to hear!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment