Webpack 4 Fundamentals
Why Webpack
Problems with Script Loading
There is only two ways that you can actually make JS to work in borwser.
- Adding a script tag for passing a source.
- Write your job description to HTML.
Problems:
- Doesn’t scale
- Too many scripts
每个浏览器都有不同的同时请求数量的限制(针对HTTP1.1,HTTP2等协议除外)。 - Unmaintainable scripts
- Scope
- Size
- Readability
- Fragility
- Monolith files
Solution:
IIFE(Immediately-Invoked-Function-Expression 立即执行函数)
Module(Treat Each File as IIFE)
- We can “safely” combine files without concern of scope collision!*
- Make, Grunt, Gulp, Broccoli, Brunch, StealJS