简体   繁体   中英

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 ?

这将通过捆绑来解决,如此处所述: http : //www.2ality.com/2013/11/es6-modules-browsers.html第3章。因此这是可行的,并且可以验证您的方法,尽管我无法做到可以在网上找到相应编译步骤的实现,但是应该在人们开始使用ES6模块时出现。

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

The best solution is probably going to be to use browserify to bundle your transpiled code into one file. Then I'd use uglify or Google's Closure Compiler to minify the file, given there is a slight size overhead given all the imports/exports that have to be dealt with.

Also, if you're willing to use Babel instead of Traceur, there's a Babel plugin for browserify to make things really easy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM