Skip to content

Instantly share code, notes, and snippets.

@xingmarc
Created March 27, 2017 04:52
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 xingmarc/4467a559799efa3fa02a41d82a46102e to your computer and use it in GitHub Desktop.
Save xingmarc/4467a559799efa3fa02a41d82a46102e to your computer and use it in GitHub Desktop.
How Webpack create final asset
// iife
(function(moduleArray) {
var cache = {};
function webpackRequire(index) {
if (cache[index]) {
return cache[index];
}
var module = { exports: {} };
var file = moduleArray[index];
file(module, webpackRequire);
cache[index] = module.exports;
return module.exports;
}
return webpackRequire(0);
})(
// All the dependencies here:
[
function(module, webpackRequire){
var hypotenuse = webpackRequire(1);
console.log(hypotenuse(3,4));
},
function(module, webpackRequire) {
var square = webpackRequire(2);
module.exports = function(a, b) {
return Math.sqrt(square(a) + square(b));
}
},
function(module, webpackRequire){
module.exports = function(x) {
return x * x;
}
}
]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment