Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bower override dependency

I have an application, written in Backbone with Marionette and some other dependencies, managed through bower :

{
  "name": "admin",
  "version": "0.1.1",
  "main": "public/javascripts/app.js",
  "dependencies": {
    "lodash": "~2.4.1",
    "console-polyfill": "~0.1.0",
    "jquery": "~2.1.1",
    "normalize-css": "~2.1.2",
    "marionette": "~1.7.4",
    "bootstrap": "~3.1.1",
    "font-awesome": "~4.1.0",
    "backbone-pageable": "~1.4.5",
    "moment": "~2.5.1",
    "swag": "~0.6.1",
    "jquery-form": "~3.46.0",
    "jquery-file-upload": "~9.5.7",
    "underscore.string": "~2.3.3",
    "bootstrap-switch": "~3.0.1",
    "joint": "~0.9.0"
  },
  "overrides": {
    "backbone": {
      "dependencies": {
        "lodash": "*",
        "jquery": "*"
      },
      "main": "backbone.js"
    },
    "backbone.wreqr": {
      "dependencies": {
        "backbone": "*"
      },
      "main": "lib/amd/backbone.wreqr.js"
    },
    "backbone-pageable": {
      "dependencies": {
        "backbone": "*"
      },
      "main": "lib/backbone-pageable.js"
    },
    "jquery-file-upload": {
      "dependencies": {
        "jquery": "*"
      },
      "main": [
        "js/vendor/jquery.ui.widget.js",
        "js/jquery.iframe-transport.js",
        "js/jquery.fileupload.js"
      ]
    },
    "underscore.string": {
      "dependencies": {
        "lodash": "*"
      },
      "main": "lib/underscore.string.js"
    },
    "joint": {
      "dependencies": {
        "lodash": "*"
      },
      "main": "dist/joint.clean.js"
    }
  },
  "resolutions": {
    "jquery": "~2.1.1"
  }
}

I want to add Joint.js(http://www.jointjs.com/), which depends on lodash (a replacement for underscore), but I can't figure out how to replace this in my configuration, since Marionette, Backbone, and some other libraries depend on underscore directly. So on the load underscore overrides lodash, and application can't start correctly.

like image 715
mavarazy Avatar asked Jun 15 '14 15:06

mavarazy


1 Answers

I've changed the order, and put lodash as the latest dependency, and it worked.

Also as a solution there is an option to have a bower hook, like it states in following answer https://stackoverflow.com/a/23289270/575338

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.

like image 177
mavarazy Avatar answered Oct 18 '22 15:10

mavarazy