Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure Grunt-Bower-Install path for a Component

Tags:

gruntjs

bower

How do I specify the default file to use for a bower component so that it will be injected properly by grunt-bower-install?

I am working with datejs and they have different files depending on your localization. The file I'm wanting to include is not in the root of bower_components/datejs directory so I get the error:

datejs was not injected in your file.

Please go take a look in "app/bower_components/datejs" for the file you need, then manually include it in your file.

I'm trying my hardest to avoid hardcoding datejs into my index file and don't really want to move "date-en-US.js" file into the root of the datejs directory either.

This is the structure of the datejs bower component.

bower_components
└── datejs
    └── build
        └── ...
        └── date-en-US.js
        └── ...
    └── src
    └── test

And just in case this helps, this is the .bower.json file that is located in the datejs bower component path:

{
  "name": "datejs",
  "homepage": "https://github.com/datejs/Datejs",
  "_release": "7bdddb55d6",
  "_resolution": {
    "type": "branch",
    "branch": "master",
    "commit": "7bdddb55d69719e42c358c3a2b7df706ff3090f8"
  },
  "_source": "git://github.com/datejs/Datejs.git",
  "_target": "*",
  "_originalSource": "datejs",
  "_direct": true
}
like image 248
adam8810 Avatar asked Jan 17 '26 14:01

adam8810


2 Answers

A little late to the party but you can override the main property of a repo to define whatever file you want to inject into your app. To do this you need to use the overrides property in YOUR bower.json.

Try this:

{
  "name": "name",
  "version": "x.x.x",
  "dependencies": {
    "datejs": "x.x.x"
  },
  "overrides": {
    "datejs": {
      "main": "build/date-en-US.js"
    }
  }
}
like image 82
nknj Avatar answered Jan 20 '26 04:01

nknj


I too was frustrated by this a few times. What I found in my cases was that "grunt bower-install" requires a "main" entry in the .bower.json. It's a string or array of strings that point to the relevant JS and/or CSS files that should be installed.

In your case I do not see the "main" and would suggest you create one that contains the desired datejs files. I would suggest the source files if you intend to use grunt for minification/etc. You can look at other successful components to see examples of the "main" entry.

I suspect that some components do not supply the entry because they have no single usage pattern (i.e. you can mix and match the files you require), but this is just speculation on my part.

like image 37
corporatedrone Avatar answered Jan 20 '26 04:01

corporatedrone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!