49

I am downloading angular, angular-bootstrap and bootstrap with bower. Bootstrap has a dependency on jquery which is installed in the process. But i don't need it in my project as i am only using bootstrap's css.

So i tried to permanently remove the dependency on jquery with

bower uninstall jquery --save

It's uninstalling jquery, but the next time i make bower update, it's downloaded again.

Is there a way to tell bower to permanently skip a dependency ?

edit: I wish there was something like this:

"resolutions": {
    "jquery": "no, thanks"
}
François Romain
  • 13,617
  • 17
  • 89
  • 123

6 Answers6

72

Pull request #1394 added official support for this feature and is present in bower version 1.6.3 and later. Check your version with bower -v, and run npm install -g bower to upgrade.

For reference, please see the .bowerrc official specification document. If this doesn't work for you, please file an issue with bower because it is a bug.

We use it like this in our .bowerrc such as the following:

{
  "ignoredDependencies": [
    "bootstrap",
    "bootstrap-sass",
    "bootstrap-sass-official"
  ]
}
kross
  • 3,627
  • 2
  • 32
  • 60
  • This still isn't merged yet? – Vic Jun 05 '15 at 14:44
  • I can confirm I'm also getting this issue with the PR, so it's not even the full solution - https://github.com/bower/bower/pull/1394#issuecomment-73864285 – streetlogics Jun 09 '15 at 18:43
  • 1
    It doesn't work in bower 1.7.0, the answer from @pierrefevrier helped me http://stackoverflow.com/a/32016391/232342 – Ivan Kaplin Jan 16 '16 at 10:39
  • @IvanKaplin it is still working for me, perhaps you have a different problem. My answer is not a workaround. This is a supported feature of bower, if it isn't working I suggest you [file an issue with bower](https://github.com/bower/bower/issues) instead of downvoting this answer. – kross Jan 18 '16 at 22:42
  • https://github.com/bower/spec/blob/master/config.md#ignoreddependencies – sam Jul 28 '16 at 18:07
  • Regarding this not working in 1.7.0, I had a similar issue with it not working in 1.7.4 (IIRC, I have upgraded to 1.8.0 now). Note there was a subsequent defect surrounding this feature that went into a later release: https://github.com/bower/bower/issues/1962 – Kyle Mar 09 '17 at 17:39
25

We had a similar situation where we had Backbone depend on Underscore in its bower.json, but we're using Lo-Dash in its stead, so Bower was unnecessarily pulling down Underscore for each install. We have automated checks for 3rd party license compliance, so we didn't want anything we don't actually use.

I realize this isn't exactly what they're meant for, but Bower's install-hooks can be used to clean unneeded deps post-install (at least until Bower gets the sort of "no thanks" resolution you hinted at). In your .bowerrc:

{
    "directory": "app/bower_components",
    "scripts": {
        "postinstall": "rm -rf app/bower_components/underscore"
    }
}

It's a bit of a hack, but works.

Jarno Rantanen
  • 437
  • 4
  • 5
  • 3
    Interesting solution! But it doesn't solve the problem of using tools like wiredep without configuring it :( – stevemao Nov 20 '14 at 23:25
14

Something you can do also in your bower.json file:

{
  "dependencies": {
    ...
    "bootstrap": "^3.2.0"
  }
  "overrides": {
    "bootstrap": {
      "dependencies": []
    }
  }
}

This means: remove all boostrap's dependencies, which is what you want since jquery is the only one (you can check with bower info bootstrap)

pierrefevrier
  • 1,570
  • 4
  • 22
  • 33
5

Add it to your .gitignore if you commit your dependencies. Otherwise leave it as it makes no difference. You should just use what you need and ignore the rest.

Sindre Sorhus
  • 62,972
  • 39
  • 168
  • 232
  • 1
    I don't commit the dependencies already. so I understand it's not possible to skip it and I will leave it like this. thanks – François Romain Jan 06 '14 at 00:53
  • 1
    I don't think this is the way to go... a shrinkwrap is very necessary – stevemao Nov 20 '14 at 23:17
  • 1
    It does make a difference when you are bundling your scripts but want to leave out libraries that are loaded off a CDN. I've installed an angular library via bower that I'm bundling with my js application, but I'm serving angular itself via google CDN. Having bower ignoring this dep makes the bundling way easier. – jminuscula Feb 26 '15 at 21:50
  • It also affects users using an IDE; e.g. I don't want all the bootstrap CSS classes clouding my autocomplete. – thinice Mar 25 '15 at 02:15
  • I'm in the CDN scenario too. – sam Jul 21 '16 at 20:35
1

The above answers are correct but an additional solution is to use wiredep as explained in this answer:

grunt-bower-install: exclude certain components

After installing grunt-wiredep, you can add something similar to this to your Grunt.js to exclude jquery from being injected:

// Automatically inject Bower components into the app
wiredep: {
  options: {},
  app: {
    src: ['<%= my.app %>/index.html'],
    exclude: ['bower_components/jquery']
  }
},

Bower will still download jquery unfortunately but at least you can tell it not to be included in the HTML src.

Community
  • 1
  • 1
dustin.schultz
  • 13,076
  • 7
  • 54
  • 63
1

DISCLAIMER: This doesn't fix your particular problem, but it helped with mine, so maybe it'll help other people.

I'm using grunt-bower-task to pull the files into a lib directory. I wanted to exclude "angular" and just include "angular.js". One of my dependencies was pulling in "angular". In my bower.json I now have:

{
  "name": "myapp",
  "version": "0.0.1",
  "dependencies": {
    "angular.js": "1.3.15",
    "angular-bootstrap": "0.13.0",
    "angular-cookies": "1.3.15",
    "angular-storage": "0.5.0",
    "angular-ui-router": "0.2.15",
    "mjolnic-bootstrap-colorpicker": "2.1"
  },
  "exportsOverride": {
    "angular": {
      "dump": "*.xxx"
    },
    "angular.js": {
      "js": [ "*.js", "*.js.map" ],
      "css": "*.css"
    }
  },
  "resolutions": {
    "angular": "1.3.15"
  }
} 

In my gruntfile.js I have:

bower: {
    install: {
        options: {
            targetDir: './lib',
            layout: 'byType',
            install: true,
            cleanTargetDir: true,
            cleanBowerDir: false
        }
    }
},

This stops the "angular" files from being copied to the destination.

Steve N
  • 1,371
  • 1
  • 12
  • 18