Created
March 27, 2017 04:52
-
-
Save xingmarc/4467a559799efa3fa02a41d82a46102e to your computer and use it in GitHub Desktop.
How Webpack create final asset
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
// 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