ES6 module concatenation

Developing a web project in JavaScript ES6 , I am currently using Traceur to compile my modules from ES6 to ES5, thinking that in the future, when the browser supports ES6, I could skip this step of translation.

In the end, since I do not want to load several js fragments at startup, I have one file containing all my modules converted to ES5, thanks to Traceur.

But in order to confirm this choice, I was wondering if this is possible on the day when I will store the source in ES6. If I just concatenate them, the import and name conflicts will be invalid.

It seems that it was not designed for him, and for its proper combination will require an additional processing step.

How do we expect to process a single file with ES6 defined by several modules?

+8
javascript ecmascript-6
source share
3 answers

This will be resolved by linking as described here: http://www.2ality.com/2013/11/es6-modules-browsers.html in chapter 3. Thus, it is possible and confirm your approach, although I could not find implementing the appropriate compilation phase on the Internet, but this should happen when people start using ES6 modules.

+4
source share

In the near future, it will no longer be necessary to create a project with a single file thanks to HTTP/2 .

See: Why Packet Optimization No longer Concerns in HTTP / 2

+1
source share

The best solution is probably to use browserify to link your converted code into a single file. Then I use uglify or the Google Closure Compiler to minimize the file, given that it has a small overhead, considering all the import / export operations that need to be addressed.

Also, if you want to use Babel instead of Traceur, there is a Babel browser plugin to make things very easy.

0
source share

All Articles