Last active
April 8, 2018 02:26
-
-
Save rauschma/8063621 to your computer and use it in GitHub Desktop.
My version of the UMD pattern.
https://github.com/umdjs/umd
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
if (typeof define !== 'function') { | |
// Not AMD | |
if (typeof require === 'function') { | |
// Node.js | |
var define = function (body) { | |
module.exports = body(require); | |
}; | |
} else { | |
// Vanilla browser | |
var define = function (body) { | |
window[body.name] = body(function (id) { return window[id] }); | |
}; | |
} | |
} | |
define(function moduleId(require) { | |
var import1 = require('import1'); | |
var import2 = require('import2'); | |
function export1() { | |
... | |
} | |
function export2() { | |
... | |
} | |
function modulePrivate() { | |
... | |
} | |
return { | |
export1: export1, | |
export2: export2 | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pattern can be pruned if you don’t have any imports or if you don’t want to support vanilla browsers.