Javascript ES - Module Script

> (World Wide) Web - (W3|WWW) > Javascript (Js|ECMAScript) > ECMAScript - Grammar Standard > Javascript ES - Module Script

1 - About

The module implementation in Ecma Script (ES2015).

An ES6 module is a Javascript file:

Everything inside a module is local to the module. To make it public, you need to export it

This feature is not implemented in any browsers natively at this time. It is implemented in many transpilers.

Modules are deferred, and only run after a document is loaded.

As a browser parses your ES6 module code, it will discover a tree of dependencies that it needs to fetch in order to execute your code. The solution is to bundle them through a builder.


3 - Management

3.1 - Processing


the contents of the module script will be evaluated.

3.2 - Declaration

The following sample shows how a script element that declare a module script

  • an external module script.
<script type="module" src="module.js"></script>
<script type="module">
  // or an inline script
  import {foo} from './bar.js';

3.3 - Dependency

All dependencies (expressed through JavaScript import statements) will be fetched.

3.4 - Aggregating modules

// import "foo" and re-export some of its exports
export {bar, bar1} from "foo";
// import "bar" and export ALL of its exports
export * from "bar";

3.5 - Integration with HTML

4 - Documentation / Reference

web/javascript/es/module/module.txt · Last modified: 2019/03/17 16:34 by gerardnico