liveBook · Manning

Module

As explained in Web Component Development with Modern Libraries and Tooling

A JavaScript module with its own scope that shares code through explicit import and export bindings.

A JavaScript module organizes code in a file and shares definitions through `export` and `import`. Definitions that are not exported stay scoped to their file, avoiding pollution of the global namespace. section 3.5 section 1.2

Loading a script as a module also changes how the browser handles it:

  • Module scripts load asynchronously, execute after HTML parsing, and run only once even if imported multiple times. section 3.5
  • They run in strict mode and enforce cross-origin request restrictions. section 3.5

Loading a web component

Use a script element with `type="module"` to include web component code. Test it from a local HTTP server; opening a local HTML file can prevent module scripts from loading. section 3.12 section 3.5

Vite is one option for local development: it provides an HTTP server, ECMAScript Module support, and hot module replacement. section 3.5

How Web Component Development with Modern Libraries and Tooling covers it

How deep it goes
Explains file scope, loading, execution, strict mode, and cross-origin restrictions.
Examples
Uses a module script to include web component code and recommends testing through a local HTTP server.
What you can do after
Configure module scripts for web component code and use Vite for local development.
How it connects
Connects ECMAScript modules with web components and Vite.

Also explained in

Compare how 44 books explain module →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Component Development with Modern Libraries and Tooling. The section links point to the parts of the book it draws on.