Slide 14
Slide 14 text
Anatomy of a JS bundle
__r(0);
(function(global) {
const modules = Object.create(null);
global.__d = function(factory, id) {
modules[id] = {
factory,
module: {exports: {}},
loaded: false,
};
}
global.__r = function(id) {
if (!modules[id]) {
throw new Error(`Module ${id} not found`);
}
const {module, factory, loaded} = modules[id];
if (loaded) {
return module.exports;
}
modules[id].loaded = true;
factory(global, global.__r, module, module.exports);
return module.exports;
}
})(this);
__d(function(global, require, module, exports) {
const foo = require(1);
module.exports = foo;
}, 0);
__d(function(global, require, module, exports) {
module.exports = 'Hello, world';
}, 1);