Skip to content

Instantly share code, notes, and snippets.

@amatiasq
Last active December 16, 2015 08:09
Show Gist options
  • Save amatiasq/5403764 to your computer and use it in GitHub Desktop.
Save amatiasq/5403764 to your computer and use it in GitHub Desktop.
Testing a script to be used instead of almond
({
name: "require.optimized",
optimize: "none",
include: ["main"],
out: "out.js"
})
<!DOCTYPE html>
<html>
<head>
<script src="out.js"></script>
</head>
<body></body>
</html>
require(['moduleB'])
define(function() {
return 'hi';
});
define(function(require) {
var a = require('moduleA');
console.log(a + '!');
});
(function() {
var loaded = {};
var mods = {};
function require(a) {
return mods[a];
}
function load(name) {
if (loaded[name] !== true)
return;
mods[name] = mods[name]();
loaded[name] = true;
}
function define(name, deps, mod) {
mod = mod || deps;
if (deps instanceof Array) deps.map(load);
mods[name] = mod(require);
}
function globalRequire(arr, cbk) {
arr.map(load);
if (cbk) cbk.apply(null, arr.map(require));
}
window.define = define;
window.require = window.requirejs = globalRequire;
})();
define("require.optimized", function(){});
define('moduleA',[],function() {
return 'hi';
});
define('moduleB',['require','moduleA'],function(require) {
var a = require('moduleA');
console.log(a + '!');
});
require(['moduleB']);
define("main", function(){});
(function() {
var loaded = {};
var mods = {};
function require(a) {
return mods[a];
}
function load(name) {
if (loaded[name] !== true)
return;
mods[name] = mods[name]();
loaded[name] = true;
}
function define(name, deps, mod) {
mod = mod || deps;
if (deps instanceof Array) deps.map(load);
mods[name] = mod(require);
}
function globalRequire(arr, cbk) {
arr.map(load);
if (cbk) cbk.apply(null, arr.map(require));
}
window.define = define;
window.require = window.requirejs = globalRequire;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment