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:
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:
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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
] | |
} |
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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "test-project-1", | |
"dependencies": { | |
"moment": "2.8.2" | |
}, | |
"overrides": { | |
"moment": { | |
"main": [ | |
"min/moment.min.js", | |
"locale/fr.js", | |
"locale/en-au.js" | |
] | |
} | |
} | |
} |