Roots Discourse

Best practice when overriding main files of bower sub-dependencies


tldr; I’m asking about best practices when installing a bower dependency which brings along it’s own dependencies.

I’ve come across a bit of a problem with the Javascript bower/gulp workflow.

In my example, I installed Isotope via bower install isotope --save. Now, Isotope’s bower.json has it’s main attribute set like so: "main": "js/isotope.js" , which is not actually the packaged version. That’s easy enough to override in my main bower.json:

"overrides": {
  "isotope": {
    "main": ["./dist/isotope.pkgd.min.js"]

The problem is that Isotope brings along a whole bunch of it’s own dependencies. In my case it is:

"dependencies": {
    "get-size": "~1.2.2",
    "matches-selector": ">=1 <2",
    "outlayer": "~1.4.0",
    "masonry": "~3.3.0",
    "fizzy-ui-utils": "~1.0.1"

These all get installed by npm, and all have main files defined. So bower-main-files gets them all, gulp concatenates and minifies them all, and I get a giant Javascript file which doesn’t work at all.

Now, I’ve overridden them all specifically, which seems to work:

"overrides": {
    "isotope": {
      "main": ["./dist/isotope.pkgd.min.js"]
    "get-size": {
        "ignore": true
    "matches-selector": {
        "ignore": true
    "outlayer": {
        "ignore": true
    "masonry": {
        "ignore": true
    "fizzy-ui-utils": {
        "ignore": true

However, this feels fragile and rather arbitrary. I’m sure Isotope isn’t the only useful Bower package to bring along it’s dependencies in this way. Is there a better way of handling these instances?

Adding Infinite scroll to sage

Could probably do

"overrides": {
    "isotope": {
      "main": ["./dist/isotope.pkgd.min.js"],
      "dependencies": {}

Will look into this later

Main.js usage

I like this simplicity


@austin You can absolutely do that. I just tried and it worked perfectly. Thank you, that’s probably the simplest, most readable and best solution.


isotope’s bower package looks like it is not configured properly. Asset-builder and the gulpfile handle child dependencies just fine, but the way isotope is set up is weird. For instance jQuery is a devDependency. That makes no sense.

The fix I suggested above makes sense though. You are essentially saying “no prefer to use the packaged version which has no dependencies”.

Prolly still fix isotope’s upstream though.


Seems like the author’s philosophically opposed to using bower.json’s main in the way that Sage does.[1] I’ll make the request, but I think this may be a matter of opinion.


Adding Bower Files to Sage (8.0.0)

It seems like that thread does have an answer though. If you want to use isotope as is without overrides, the one missing part is jquery-bridget, which is used for jQuery integration.

bower install --save jquery-bridget

and make sure that bridget is being included before isotope, and it should technically work.

TBH though, the end goal is isotope.pkgd.min.js anyways, so I would also probably just include that file and exclude all deps as austin showed earlier.


I’m having the same problem as the guy in first post. When I launch bower install it downloads a lot of dependencies but I don’t need them because I load the packaged version (isotope.pkgd.js).

Adding the "dependencies": {} like said by @austin , the error gone but how can avoid to download all the dependencies?

This is my bower.json

  "name": "sage",
  "homepage": "",
  "authors": [
    "Ben Word <>"
  "license": "MIT",
  "private": true,
  "dependencies": {
    "modernizr": "2.8.2",
    "bootstrap-sass-official": "3.3.5",
    "isotope": "~2.2.1"
  "overrides": {
    "modernizr": {
      "main": "./modernizr.js"
    "bootstrap-sass-official": {
      "main": [
    "isotope": {
      "main": [
      "dependencies": {}



Just curious why downloading the dependencies is an issue for you


Who said that’s a real issue? I prefer to not download MBs of unuseful dependencies, and asking for avoid it…


What have you tried so far? Have you looked on Bower docs or repos to figure out how to accomplish what you’re wanting? This isn’t really a Sage question


Thanks jodi, I also faced this problem and you saved me.


Also encountered this problem (with flickity plugin specifically) and I couldn’t find the answer in the e-book. Could be a good idea to add this in a future edition.

Thanks for the solution, it seems to work for me as well.


I just stumbled in from the interwebs I came across @austin’s answer a year after he posted it here, and it’s so far the best answer I’ve seen to this workflow problem.

For example, here’s a bit out of my bower.json file:

     "jquery": "^3.1.0",
    "flickity": "^2.0.2",
    "masonry": "^4.1.0"
  "overrides" : {
    "masonry" : {
      "main" : ["dist/masonry.pkgd.js"],
      "dependencies" : {}
    "jquery" : {
      "main" : ["dist/jquery.min.js"],
      "dependencies" : {}
    "flickity" : {
      "main" : ["dist/flickity.pkgd.js", "dist/flickity.min.css"],
      "dependencies" : {}

… and then in my gulpfile.js

const bower  = require('main-bower-files');
gulp.task('bowerCSS', ['jekyllBuild'], function () {
  return gulp.src(bower('**/*.css'))
gulp.task('bowerJS', ['jekyllBuild'], function () {
  return gulp.src(bower('**/*.js'))
gulp.task('bowerBuild', ['bowerJS', 'bowerCSS']);

Before …


Thanks all!

Also - I’ve now just discovered the WP tools @ and I’m pretty stoked to check them out. :smiley: