© Carlos Rojas 2021
C. RojasBuilding Native Web Componentshttps://doi.org/10.1007/978-1-4842-5905-4_5

5. ES Modules

Carlos Rojas1 
(1)
Medellin, Colombia
 

In this chapter, I will discuss ES Modules, another specification in the Web Components set. You will learn what ES Modules are and how to use ES Modules in web components. We will then build a new web component for our collection.

What Are ES Modules?

The ES Modules specification defines a mechanism with which to share variables and functions in our projects through different files. ES Modules are now available with ES6. Before this, if you wanted to share something, you would add it to the global context and make it available whether it was used or not. Consider the code in Listing 5-1.
var pi = 3.1415; ...

Get Building Native Web Components: Front-End Development with Polymer and Vue.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.