Skip to content

Instantly share code, notes, and snippets.

@mythz mythz/ss-require.js
Created Feb 23, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.