Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created January 15, 2012 12:48
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 Raynos/1615755 to your computer and use it in GitHub Desktop.
Save Raynos/1615755 to your computer and use it in GitHub Desktop.
minimal define/require boilerplate
/*
Server side tool minimises the path to file to a small string.
It then goes and recompiles every require call to that path to be that string
Hopefully closure compiler will optimize module -> m and optimise m.exports -> m.e
*/
// define
define("/path/to/file", function (require, module) {
// your code should require some other things
require("foobar");
// your code
// your code should export something
module.exports = something
}
// stash
(function (s, undefined) {
// define(key, callback)
function define(k, c) {
// module = {}
var m = {}
// callback(require, module)
c(r, m)
// stash[key] = module.exports
s[k] = m.exports;
}
// require(key)
function require(k) {
// return stash[key]
return s[k];
}
// default stash to {}
})({});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment