Skip to content

Instantly share code, notes, and snippets.

@everilae
Created August 28, 2012 07:49
Show Gist options
  • Save everilae/3495968 to your computer and use it in GitHub Desktop.
Save everilae/3495968 to your computer and use it in GitHub Desktop.
An ugly Bootstrap AMD wrapper for Require.js optimizer
/* onBuildRead hooks before optimizations, which is what we need in order to
* fake Bootstrap having define() call
*/
onBuildRead: function (name, path, contents) {
var jqueryVar = 'jqueryModule';
var wrapperHead = "define('" + name + "', ['jquery'], ";
var wrapperTail = ");";
if (name === "bootstrap") {
console.log("Wrapping bootstrap in " + wrapperHead + "..." + wrapperTail);
/* Wrap Bootstrap in an AMD module by force */
contents = wrapperHead + new Function(jqueryVar, contents.replace(/window\.jQuery/g, jqueryVar)) + wrapperTail;
}
// Return contents, unmodified for most
return contents;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment