H
H
heIIfire2017-06-15 00:47:56
JavaScript
heIIfire, 2017-06-15 00:47:56

What is the convenience of Webpack, other than including one single file?

Started digging towards Webpack. Here I am connecting 10 different scripts in 100 pages. It will be 1000 different scripts. Webpack takes and collects them in one place. It turns out that 900 unnecessary scripts are connected in each page.
PS Sorry for my ignorance, Russian is not my native language

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Alekseev, 2017-06-24
@angelpsy

Webpack allows you to load certain code only if it is needed on the page.
Let's say you have a carousel script that is used on some pages, but not on all of them, and you don't want to load this code for all 100 pages. Webpack allows you to set a condition under which the script will be loaded, and on other pages it will not be loaded. See require.ensure.
It is possible to compile a generic file where only the code used on all pages will be... or if it is used a certain number of times. And separate files that will be connected only when necessary.
Additionally, it can clean up unused code. Those. you wrote some function, but it became unnecessary and is never called - Webpack allows you to analyze the code and remove the unused.
You can also write
if (false) {...}
And webpack will remove this code, because it will never be executed (let's say this can be used for debugging, and instead of false, use if (isDebage) {}. isDebage set from outside the script). See tree shaking.
Webpack also allows you to process both scripts (for example, using babel), as well as styles (for example, postCSS) and other resources. Among other things, it allows you to add a hash of the script to the script connection code, which allows you to reset the cache for visitors when updating the bundle.
There is also a very convenient server for development with hot reloading of modules (not just LR).
There are other goodies too.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question