Customising what gets included from bower dependencies (Brunch)

Sometimes you'll find you need to customise which files get included from a bower dependency.

For example, when using the moment.js library, you'll see (in bower_components/moment/bower.json) that by default 'moment.js' is the only file included:

{
"name": "moment",
"version": "2.8.4",
"main": "moment.js",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests",
"tasks",
"component.json",
"composer.json",
"CONTRIBUTING.md",
"ender.js",
"Gruntfile.js",
"package.js",
"package.json"
]
}
view raw gistfile1.json hosted with ❤ by GitHub
In my case, I'm using brunch to build the project and I'd prefer to include moment.min.js - plus I want to selectively pick which moment local files to include.

This turns out to be quite easy - brunch understands bower overrides, so in your projects bower.json all you have to do is include an override which tells it which files to use from your dependencies:
{
"name": "test-project-1",
"dependencies": {
"moment": "2.8.2"
},
"overrides": {
"moment": {
"main": [
"min/moment.min.js",
"locale/fr.js",
"locale/en-au.js"
]
}
}
}
view raw bower.json hosted with ❤ by GitHub

Popular posts from this blog

AspectJWeaver with JDK 7 - error - only supported at Java 5 compliance level or above

Intellij tip - Joining multiple lines into one

JUnit parameterized test with Spring autowiring AND transactions