Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit f0a127d

Browse files
committed
simplify readme
1 parent 0267ef1 commit f0a127d

File tree

1 file changed

+30
-76
lines changed

1 file changed

+30
-76
lines changed

README.md

Lines changed: 30 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# ES6 Module Loader Polyfill [![Build Status][travis-image]][travis-url]
22

3-
Dynamically loads ES6 modules in browsers and [NodeJS](#nodejs-usage) supporting custom module resolution and the loading of existing module formats from ES6 modules via a hookable pipeline.
3+
Dynamically loads ES6 modules in browsers and [NodeJS](#nodejs-usage) with support for loading existing and custom module formats through loader hooks.
4+
5+
This project implements dynamic module loading through `System` exactly to the previous ES6-specified loader API at [2014-08-24 ES6 Specification Draft Rev 27, Section 15](http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#august_24_2014_draft_rev_27) and will continue to track this API as it is re-drafted as a browser specification (currently most likely to be at https://github.com/whatwg/loader).
46

57
* Provides an asynchronous loader (`System.import`) to [dynamically load ES6 modules](#basic-use).
68
* Uses [Traceur](https://github.com/google/traceur-compiler) for compiling ES6 modules and syntax into ES5 in the browser with source map support.
7-
* Fully supports [ES6 circular references and bindings](#circular-references--bindings).
9+
* Fully supports [ES6 circular references and live bindings](#circular-references--bindings).
810
* Polyfills ES6 Promises in the browser with an optionally bundled ES6 promise implementation.
911
* Supports ES6 module loading in IE8+. Other ES6 features only supported by Traceur in IE9+.
1012
* The complete combined polyfill, including ES6 promises, comes to 9KB minified and gzipped, making it suitable for production use, provided that modules are [built into ES5 making them independent of Traceur](#moving-to-production).
@@ -17,14 +19,6 @@ For an example of a universal module loader based on this polyfill for loading A
1719

1820
_The current version is tested against **[Traceur 0.0.79](https://github.com/google/traceur-compiler/tree/0.0.79)**._
1921

20-
### Background
21-
22-
The ES6 specification defines a module system in JavaScript using `import` and `export` syntax. This syntax will be supported within the `<script type="module">` tag in the browser. For dynamically loading modules, a dynamic browser module loader was initially proposed for the ES6 module specification, and is now being developed as a browser specification.
23-
24-
The proposed dynamic loader API uses a global loader at `window.System` for importing modules dynamically and allows customisation of the ES6 lookup process including loading from other module formats.
25-
26-
This project implements the dynamic module loading through `System` exactly to the previous ES6-specified API at [2014-08-24 ES6 Specification Draft Rev 27](http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#august_24_2014_draft_rev_27), Section 15, and will continue to track changes as it is re-drafted as a browser specification (currently most likely to be at https://github.com/whatwg/loader).
27-
2822
### Basic Use
2923

3024
Download both [es6-module-loader.js](https://raw.githubusercontent.com/ModuleLoader/es6-module-loader/v0.11.0/dist/es6-module-loader.js) and traceur.js into the same folder.
@@ -59,7 +53,7 @@ We can then load the module with the dynamic loader:
5953

6054
The dynamic loader returns a `Module` object, which contains getters for the named exports (in this case, `q`).
6155

62-
[Read the wiki on overview of ES6 modules and syntax](https://github.com/ModuleLoader/es6-module-loader/wiki/A-Brief-ES6-Modules-Overview).
56+
[Read an overview of ES6 modules and syntax](https://github.com/ModuleLoader/es6-module-loader/wiki/A-Brief-ES6-Modules-Overview).
6357

6458
### Custom Compilation Options
6559

@@ -71,7 +65,7 @@ System.traceurOptions.annotations = true;
7165

7266
### Module Tag
7367

74-
A simple analog to the module tag is provided with:
68+
As well as defining `window.System`, this polyfill provides support for the `<script type="module">` tag:
7569

7670
```html
7771
<script type="module">
@@ -82,11 +76,7 @@ A simple analog to the module tag is provided with:
8276
</script>
8377
```
8478

85-
Ideally this should be based on polyfilling the `<module>` tag, as `<script type="module">` is not in the spec.
86-
87-
As such this approach is not really suitable for anything more than experimentation.
88-
89-
See an overview of the specification module tag features here - https://github.com/dherman/web-modules/blob/master/explainer.md.
79+
Because it is only possible to load ES6 modules with this tag, it is not suitable for production use in this way.
9080

9181
### baseURL
9282

@@ -127,14 +117,22 @@ It is also possible to define wildcard paths rules. The most specific rule will
127117

128118
### Circular References & Bindings
129119

130-
All [AMD](http://requirejs.org/docs/api.html#circular), [CommonJS](http://nodejs.org/api/modules.html#modules_cycles), and [ES6](https://github.com/ModuleLoader/es6-module-loader#circular-references--bindings) treat circular dependencies differently.
120+
#### Zebra Striping
121+
122+
All [AMD](http://requirejs.org/docs/api.html#circular), [CommonJS](http://nodejs.org/api/modules.html#modules_cycles), and [ES6](https://github.com/ModuleLoader/es6-module-loader#circular-references--bindings) treat circular dependencies differently.
123+
Handling this problem is one of the major innovations in the loader spec, using a technique called **zebra striping**. This involves analyzing the dependency tree and forming alternate layers of ES6 / non-ES6 modules with circular references in each layer for linking.
124+
The layers are then individually linked, with the appropriate circular reference handling being done within each layer. This allows CommonJS circular references to interact with ES6 circular references. Inter-format circular references are not supported as they
125+
would be across layers.
131126

132-
Circular references and live bindings are fully supported identically to ES6 in this polyfill.
127+
This loader implementation handles zebra-striping automatically, allowing a loader like [SystemJS](https://github.com/systemjs/systemjs) to support all module formats with exact circular reference support.
128+
129+
#### ES6 Circular References &amp; Bindings
130+
131+
ES6 circular references and bindings behave in the following way:
133132

134-
That is:
135133
* Bindings are set up before module execution.
136134
* Execution is run from depth-first left to right on the module tree stopping at circular references.
137-
* Bindings are live - an adjustment to an export of one module affects all modules importing it.
135+
* Bindings are live - an adjustment to an export of one module affects all modules importing it, but it can only be modified in the defining module.
138136

139137
even.js
140138
```javascript
@@ -166,25 +164,21 @@ odd.js
166164
});
167165
```
168166

169-
When using [SystemJS](https://github.com/systemjs/systemjs) loader, AMD and CommonJS preserve their own circular reference behavior.
170-
171167
### Moving to Production
172168

173169
When in production, it is not suitable to load ES6 modules and syntax in the browser.
174170

171+
#### System.register Output
172+
175173
There is a `modules=instantiate` build output in Traceur that can be used with the ES6 Module Loader, provided it has the [System.register extension](https://github.com/systemjs/systemjs/blob/master/lib/extension-register.js)
176174
from [SystemJS](https://github.com/systemjs/systemjs).
177175

178176
The benefit of this output is that it provides full support for circular references and live module bindings.
179177

180178
This output format is explained here - https://github.com/ModuleLoader/es6-module-loader/wiki/System.register-Explained.
181179

182-
Alternatively, Traceur can also output `amd` or `cjs` as well.
183-
184180
A basic example of using this extension with a build would be the following:
185181

186-
#### Building all files into one bundle
187-
188182
1. Build all ES6 modules into ES5 System.register form:
189183

190184
```
@@ -231,6 +225,12 @@ We can also build separate files with:
231225

232226
With the above, we can load from the separate files identical to loading ES6.
233227

228+
#### Building across module formats
229+
230+
If using a loader like [SystemJS](https://github.com/systemjs/systemjs) to load different module formats, then a build can also be performed across module formats as well.
231+
232+
See [SystemJS builder](https://github.com/systemjs/builder) for this combined approach.
233+
234234
### NodeJS Usage
235235

236236
```
@@ -259,56 +259,10 @@ Running the application:
259259
NodeJS test
260260
```
261261

262-
### Tracing API
263-
264-
This is not in the specification, but is provided since it is such a natural extension of loading and not much code at all.
265-
266-
Enable tracing and start importing modules:
267-
268-
```javascript
269-
loader.trace = true;
270-
loader.execute = true; // optional, disables execution of module bodies
271-
272-
loader.import('some/module').then(function() {
273-
/*
274-
Now we have:
275-
276-
loader.loads['some/module'] == {
277-
name: 'some/module',
278-
deps: ['./unnormalized', 'deps'],
279-
depMap: {
280-
'./unnormalized': 'normalized',
281-
'deps': 'deps'
282-
},
283-
address: '/resolvedURL',
284-
metadata: { metadata object from load },
285-
source: 'translated source code string',
286-
kind: 'dynamic' (instantiated) or 'declarative' (ES6 module pipeline)
287-
}
288-
289-
With the dependency load records
290-
loader.loads['normalized']
291-
loader.loads['deps']
292-
also set.
293-
*/
294-
});
295-
```
296-
297-
Then start importing modules
298-
299-
### Extending the Loader
300-
301-
The loader in its default state provides only ES6 loading.
302-
303-
We can extend it to load AMD, CommonJS and global scripts as well as various other custom functionality through the loader hooks.
304-
305-
[Read the wiki on extending the loader here](https://github.com/ModuleLoader/es6-module-loader/wiki/Extending-the-ES6-Loader).
306-
307-
### Specification Notes
308-
309-
See the source of https://github.com/ModuleLoader/es6-module-loader/blob/master/lib/es6-module-loader.js, which contains comments detailing the exact specification notes and design decisions.
262+
### Further Documentation
310263

311-
To follow the current the specification changes, see the marked issues https://github.com/ModuleLoader/es6-module-loader/issues?labels=specification&page=1&state=open.
264+
* [Extending the loader through loader hooks](https://github.com/ModuleLoader/es6-module-loader/wiki/Extending-the-ES6-Loader)
265+
* [Tracing API](https://github.com/ModuleLoader/es6-module-loader/wiki/Tracing-API)
312266

313267
## Contributing
314268
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt](https://github.com/cowboy/grunt).

0 commit comments

Comments
 (0)