Skip to content

Instantly share code, notes, and snippets.

@Gerhut
Created October 12, 2015 06:57
Show Gist options
  • Select an option

  • Save Gerhut/aca65ae16163705dcc67 to your computer and use it in GitHub Desktop.

Select an option

Save Gerhut/aca65ae16163705dcc67 to your computer and use it in GitHub Desktop.
AMD to CommonJS Module
var define = function (global) {
function define(id, dependencies, factory) {
if (typeof id == 'function') { // define(factory)
factory = id
dependencies = []
} else if (typeof dependencies == 'function') { // define(?, factory)
factory = dependencies
dependencies = (typeof id == 'string') ? [] : id
}
for (var i = 0, l = dependencies.length; i < l; i++) {
dependencies[i] = require(dependencies[i])
}
module.exports = factory.apply(global, dependencies)
}
define.amd = true
return define
} (new Function('return this')())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment