Why you should use ES modules?
Hi! My name is João Paulo.
But you can call me JP 🤙
Front end developer at Grupo Globo
One of the maintainers of Clappr
I really love Rio Carnival
"The concept of modularity is used primarily to reduce complexity by breaking a system into varying degrees of interdependence and independence across and "hide the complexity of each part behind an abstraction and interface."
Baldwin, C.Y.; Clark, K.B. (2000). "Chapter 3: What Is Modularity?" - Design Rules: The power of modularity
Modules maximize code reusability, since one module can be imported by another module.
Modules explicitly define their imports and exports. So, they can be easily composed.
Allows multiple people to work individually in on project while not bottle-necking each other. Also if one of the modules breaks, instead of replacing the whole project, you just have to replace the individual module that broke.
A benefit already linked to the use of modules is the fact that the code has a much better organization, since we can create modules with unique responsibilities.
"Tree shaking is a term commonly used within a JavaScript context to describe the removal of dead code."
MDN Web Docs Glossary: Definitions of Web-related terms - Tree shaking
The use of tree shaking is much more difficult for dynamic cases and in some cases, it becomes impraticable.
Currently, it's possible to use ES modules without any module bundler or transpiler in the majority of Browsers (!!!)
In fact, this presentation is using <script type="module">
Now, I hope you will react like this when the subject is ES modules: