user2401221
user2401221

Reputation: 519

grunt build or bower adds a useless dependency for highstocks

I'm using yeoman, grunt and bower and highstock library. When I build my app (grunt build) this generate these 3 lines

<script src="bower_components/highstock/js/highcharts.src.js"></script>
<script src="bower_components/highstock/js/highstock.src.js"></script>
<script src="bower_components/highstock/js/highcharts-more.src.js"></script>

BUT, as highstock includes high charts this line should not be there and this makes errors

<script src="bower_components/highstock/js/highcharts.src.js"></script>

the error is http://www.highcharts.com/errors/16

How to remove this line in the build ?

Thanks for your help.

Upvotes: 1

Views: 1009

Answers (1)

Stephen
Stephen

Reputation: 5770

I believe this is grunt-bower-install at work. gbi is a task that looks through the dependencies in your project's bower.json, and injects their appropriate references into your HTML. In order for it to work, each Bower package needs to specify a main property in its bower.json file.

So, the bower.json file for highcharts looks like this:

{
  "name": "highcharts",
  "version": "v3.0.10-modified",
  "main": [
    "js/highcharts.src.js",
    "js/highcharts-more.src.js",
    "js/modules/exporting.src.js"
  ],  
  "ignore": [
    "errors",
    "exporting-server",
    "gfx",
    "lib",
    "samples",
    "studies",
    "test",
    "tools",
    "utils",
    "ant",
    "build.md",
    "build.properties",
    "build.xml"
  ]
}

Because it lists 3 different files, gbi is interpreting that as "you need these three files to make this Bower package work." I have no familiarity with highcharts, but if you know that to be false-- in other words, you only need one of those files for it to work-- then it would be helpful to you and others to send a pull request correcting their bower.json file.

As far as a fix for now, you can specify an overrides property in your project's bower.json, that lists only the file you need, such as:

{
  "name": "your-project",
  "dependencies": {
    "highcharts": "~3.0.0"
  },
  "overrides": {
    "highcharts": {
      "main": "js/highcharts.src.js"
    }
  }
}

The next time you run grunt bowerInstall, it will sort itself out.

Note: Make sure you're using the latest grunt-bower-install to use the new overrides feature.

Upvotes: 4

Related Questions