bowerstealjs

Using StealJS to load Bower components lacking a bower.json file


I am using the StealJS + Bower integration in my application, but a couple of my Bower components (including es6-collections) do not contain a bower.json file. Because es6-collections is one of the dependencies in my project's bower.json file, StealJS tries to load the es6-collections component's bower.json file, cannot find it because it does not exist, and complains: Unable to load the bower.json for es6-collections. I tried using System.config({ path: { 'es6-collections': '...' } }) to notify StealJS of the path to the script to use when loading es6-collections, but that does not help. What can I do to get StealJS to load this component?


Solution

  • Assumptions

    So I am going to make a few assumptions:

    If these things seem mostly true-ish then you may just have to add some configuration in your bower.json file to silence the error/warning and have everything work as expected.

    Explanation:

    So because the system-bower plugin (which you are using implicitly because steal detects it is being loaded from a bower_components directory) uses the components bower.json files to determine entry points, so in this case the error/warning comes from not being able to find es6-collections bower.json file.

    Solution:

    So we just need to tell System (used by steal) where to find that module and that it can stop looking for it's bower.json file.

    We can do that by adding a "system" property to the bower.json and adding some configuration data like this...

    "system": {
      "paths": {
        "es6-collections": "bower_components/es6-collections/index.js"
      },
      "bowerIgnore": ["es6-collections"],
      "meta": {
        "es6-collections": {
          "format": "global"
        }
      }
    }
    

    For more information on all these things...

    http://stealjs.com/docs/bower.html

    https://github.com/systemjs/systemjs/wiki/Meta-Configuration

    http://stealjs.com/docs/steal.html

    Just to have a working example here https://gist.github.com/BigAB/c108bb0860c9cfee3d6a are three files you can copy-paste/clone and then do a bower install and see it working.