Skip to content

Instantly share code, notes, and snippets.

@mythz
Created February 23, 2019 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mythz/6a4a02358e6a63e8c1820709fe28b20f to your computer and use it in GitHub Desktop.
Save mythz/6a4a02358e6a63e8c1820709fe28b20f to your computer and use it in GitHub Desktop.
Minimal AMD define()
var EXPORT = { vue: 'Vue' };
window.define = function (name, deps, f) {
var anon = typeof name != "string";
if (anon) {
f = deps;
deps = name;
}
if (typeof deps == "function") {
f = deps;
deps = [];
}
var args = [];
if (deps) for (var i=0,len=deps.length; i<len; i++) {
args[i] = require(deps[i]);
}
if (anon) {
f.apply(undefined,args);
} else {
exports[name] = f.apply(undefined,args);
if (EXPORT[name]) window[EXPORT[name]] = exports[name];
}
};
window.define.amd = { jQuery: true };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment