Created
January 15, 2012 12:48
-
-
Save Raynos/1615755 to your computer and use it in GitHub Desktop.
minimal define/require boilerplate
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
/* | |
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 | |
} |
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
// 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