Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 module concatenation

Developing a web project in JavaScript ES6, I currently use Traceur to compile my modules from ES6 to ES5, thinking that in the future, when browser will support ES6, I would be able to skip that transpilation step.

In the end, because I don't want to download several js pieces at start up, I have a single file that contains all my modules converted into ES5, thanks to Traceur.

But to validate this choice, I was wondering if this could still be possible the day I would keep the source in ES6. If I simply concatenate them, there will be invalid imports and name conflicts.

It looks like it has not been designed for it and it would require a extra processing step to merge them correctly.

How are we suppose to handle ES6 single file project defined with several modules ?

like image 425
JBE Avatar asked Nov 06 '14 23:11

JBE


2 Answers

This will be solved by bundling, as described here: http://www.2ality.com/2013/11/es6-modules-browsers.html in chapter 3. So this is possible and validate your approach, although I couldn't find an implementation of the corresponding compilation step on the web, but it should arise when people start using ES6 modules.

like image 86
jolivier Avatar answered Oct 18 '22 19:10

jolivier


In the near future, there won't be anymore the need to build single file project thanks to HTTP/2.

See: Why bundle optimizations are no longer a concern in HTTP/2

like image 30
JBE Avatar answered Oct 18 '22 18:10

JBE