Skip to content

Instantly share code, notes, and snippets.

@robharper
Created July 10, 2012 13:19
Show Gist options
  • Save robharper/3083192 to your computer and use it in GitHub Desktop.
Save robharper/3083192 to your computer and use it in GitHub Desktop.
Wrapper code to expose a library module built with almond.js as a module in the global scope (with dependencies)
(function(context) {
// Almond.js here
// Library module definitions here
if (context.define && context.define.amd) {
// AMD - expose myLib to outer AMD loader
var almondDefine = define;
(function(define, almondDefine, almondRequire) {
define(["underscore", "backbone", "jquery"], function(_, Backbone, $) {
almondDefine("underscore", function() { return _; });
almondDefine("Backbone", function() { return Backbone; });
almondDefine("jquery", function() { return $; });
return almondRequire("myLib");
});
}(context.define, define, require));
} else {
// No AMD loader, expose library as object in context
// Tell almond.js where to find our three dependencies
define("underscore", function() { return context._; });
define("backbone", function() { return context.Backbone; });
define("jquery", function() { return context.jQuery; });
context.MyLib = require("myLib");
}
}(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment