Skip to content

Instantly share code, notes, and snippets.

@dbashford
Last active December 26, 2015 17:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbashford/7189582 to your computer and use it in GitHub Desktop.
Save dbashford/7189582 to your computer and use it in GitHub Desktop.
mimosa-bower mimosa-config mainOverride example. The first file is the pertinent bower.json, the second is the mimosa-config bower snippet. The first comment at the bottom explains the config in detail.
{
"name": "Durandal Mimosa Skeleton",
"version": "2.0.0",
"dependencies": {
"jquery":"1.9.1",
"requirejs":"2.1.8",
"requirejs-text":"2.0.3",
"knockout.js":"2.3.0",
"bootstrap":"2.3.2",
"font-awesome":"3.2.1",
"durandal":"2.0.0"
}
}
bower:
copy:
mainOverrides:
"knockout.js":["knockout.js","knockout-2.3.0.debug.js"]
"bootstrap": [
"docs/assets/js/bootstrap.js"
"docs/assets/css/bootstrap.css"
"docs/assets/css/bootstrap-responsive.css"
]
"font-awesome": [
{ font: "../../font" }
"css/font-awesome.css"
"css/font-awesome-ie7.css"
]
"durandal": [
{
img: "../../images"
js: "durandal"
css: "durandal"
}
]
@dbashford
Copy link
Author

All files end up in vendor.javascripts (a mimosa configuration parameter) folder, that defaults to javascripts/vendor, or in vendor.stylesheets, which defaults to stylesheets/vendor.

mimosa-bower will place all javascript files inside vendor.javascripts. It will place all files that are not javascript relative to the vendor.stylesheets directory. So, for instance, .jpg and .png files would be placed relative to vendor.stylesheets.

Where files for each Bower module are placed inside, for instance, javascripts/vendor depends on the strategy being used. The default strategy is packageRoot (and this config does not modify that default) which means files are placed inside a folder named for the module. A bower package named foo would have its contents placed in a javascripts/vendor/foo folder because of strategy: 'packageRoot'.

knockout.js is just a string array. Each string is a path in the bower module. The file at that path is pulled from its location and placed inside the packageRoot. So, in the case of knockout.js, files named knockout.js and knockout-2.3.0.debug.js, located at the root of the Bower module, are placed inside a javascripts/vendor/knockout.js folder. The knockout Bower module can be found here: https://github.com/bowerjs/knockout/tree/2.3.0, and you'll see those two files are there at the root of the repository.

bootstrap is also a string array, except each string is a very specific deep path into the Bower module. The bootstrap Bower module can be found here: https://github.com/twbs/bootstrap/tree/v2.3.2. Note that link points right at the 2.3.2 tag as defined by the bower.json above.

The font-awesome section also has strings in its array. Those two strings are handled just like the knockout and bootstrap strings. The array also has an object in it. That object allows for specific placement of files and folders. In this case the font folder inside the bower module is placed, in its entirety, unedited, two directories up from stylesheets/vendor in a directory called font, which means in a font directory at the same level as stylesheets. The font-awesome bower module can be found here: https://github.com/FortAwesome/Font-Awesome/tree/v3.2.1

The durandal bower module mainOverride is just an object. Each entry in that object is a folder, and each folder is placed in its entirely, unedited, at the given location. The img folder of the module will end up in a images folder at the same level as stylesheets and javascripts. The js folder lands inside a durandal folder inside vendor/javascripts, and the css folder lands inside a durandal folder inside stylesheets/vendor.

Take a look at the finished product here: https://github.com/dbashford/Durandal-Mimosa-Node-Skeleton. All this action happens inside the watch.sourceDir, which is, by default, assets.

@Anachron
Copy link

Anachron commented Jan 5, 2014

Awesome! This helps me a lot.

@leviwheatcroft
Copy link

Some things I discovered which might help others...

The only way I could find to reliably push files from bower_components over to assets after making changes to mainOverrides was to remove the entire contents of .mimosa/bower and then run mimosa bower

If you specify a directory to include, subdirectories are not included. Manually specified subdirectories are also ignored (because they'd be flattened in the assets/vendor/package folder anyhow), so say you wanted the /less and /less/mixins dirs from bootstrap, your main override would like like this:

   'bootstrap': [
      'js',
      'less',
      { 'less/mixins': './bootstrap/mixins' }
    ],

@gihrig
Copy link

gihrig commented Feb 11, 2015

The only way I could find to reliably push files from bower_components over to assets after making changes to mainOverrides was to remove the entire contents of .mimosa/bower and then run mimosa bower

mimosa watch -C Does the trick also.

I, too, found this to be required. Is it considered a bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment