2012-03-10 20:11:23 +08:00
|
|
|
// Polyfill for node.js
|
2012-03-21 19:41:03 +08:00
|
|
|
// - adds require.ensure
|
|
|
|
// - adds require.context
|
|
|
|
// call it like this:
|
|
|
|
// require = require("webpack/require-polyfill")(require.valueOf());
|
|
|
|
// This is only required when you want to use the special require.xxx methods
|
2012-03-20 02:59:38 +08:00
|
|
|
// in server-side code which should be so only in rar cases.
|
2012-03-10 20:11:23 +08:00
|
|
|
module.exports = function(req) {
|
2012-03-21 19:41:03 +08:00
|
|
|
if(!req.webpackPolyfill) {
|
|
|
|
var oldReq = req;
|
|
|
|
req = function(name) {
|
|
|
|
return oldReq(name);
|
|
|
|
};
|
|
|
|
req.__proto__ = oldReq;
|
|
|
|
req.webpackPolyfill = true;
|
|
|
|
}
|
2012-03-10 20:11:23 +08:00
|
|
|
if(!req.ensure) {
|
|
|
|
req.ensure = function(array, callback) {
|
|
|
|
callback(req);
|
|
|
|
};
|
|
|
|
}
|
2012-03-11 20:44:38 +08:00
|
|
|
if(!req.context) {
|
|
|
|
req.context = function(contextName) {
|
|
|
|
return function(name) {
|
|
|
|
return req(contextName + "/" + name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-21 19:41:03 +08:00
|
|
|
return req;
|
2012-03-10 20:11:23 +08:00
|
|
|
}
|