ES6 and legacy module compatibility

Brian Di Palma offler at gmail.com
Thu Jul 3 01:11:02 PDT 2014


SystemJS seems the best approach at the moment.

https://github.com/systemjs/systemjs/

The ES6 module loader shouldn't have any built in knowledge of these
other specs.
It should be up to us to use loaders that are patched to understand
these legacy module systems.
Or we could compile these modules to ES6 modules and consume them with
the default loader.

Legacy module system features like "object-as-module" could also be
supported by these custom interoperability loaders.
Most likely by having them export a well known identifier (the ones
suggested were default, exports or _) or a compiler can be configured
to add a provided name.

```
import {default as Emitr} from 'emitr';
import {exports as Emitr} from 'emitr';
import {_ as Emitr} from 'emitr';
```

Note that this is what SystemJS is already doing with CommonJS
modules, using "default". So

```
import {default as Emitr} from 'emitr';
```

Works right now.

Or if you control all your legacy codebase you could just compile it
to ES6 wholesale.

B.


More information about the es-discuss mailing list