admin管理员组

文章数量:1300085

Due the fact, that ES6-modules (JavaScript-modules) are available for testing:

I wonder, how should I minify and prepare the project release-file? Earlier, I havde bundled all JavaScript-files into the single and minified file, except situations, where I have to load the JS-file dynamically via XHR or Fetch API.

As I understand, it's rather impossible to prepare a single-minified file with the ES6-modules right now or may be, I'm just misunderstanding some ways of work.

So, are the any ways to prepare my ES6-modules into single file and how I should prepare the modern JavaScript-project in 2017 year, where JavaScript-modules will be available?

Due the fact, that ES6-modules (JavaScript-modules) are available for testing:

  • https://www.chromestatus./feature/5365692190687232
  • https://medium./dev-channel/es6-modules-in-chrome-canary-m60-ba588dfb8ab7

I wonder, how should I minify and prepare the project release-file? Earlier, I havde bundled all JavaScript-files into the single and minified file, except situations, where I have to load the JS-file dynamically via XHR or Fetch API.

As I understand, it's rather impossible to prepare a single-minified file with the ES6-modules right now or may be, I'm just misunderstanding some ways of work.

So, are the any ways to prepare my ES6-modules into single file and how I should prepare the modern JavaScript-project in 2017 year, where JavaScript-modules will be available?

Share Improve this question edited Jul 30, 2017 at 16:04 jeanfrg 2,3512 gold badges31 silver badges40 bronze badges asked Jul 30, 2017 at 14:04 user8245660user8245660 9
  • Use a bundler like webpack – Sven van de Scheur Commented Jul 30, 2017 at 14:09
  • Earlier, I have bundled all JavaScript-files into the single and minified file: why should you not be able to do so with ES2015 modules? – PeterMader Commented Jul 30, 2017 at 14:13
  • @SvenvandeScheur Does webpack work natively with the ES6-modules? Or it just translates JS-code into the ES5-scripts with the sourcemaps? If the last option is correct, then it's rather old solution for 2017 year. If web-browser has provided the new way of separating the project using the ES6-modules, why not to find the way how to use modern features in more pleasant way? PS: Also, I have used webpack 1 year ago and to be honest... It's rather ugly designed project (as for me). – user8245660 Commented Jul 30, 2017 at 14:13
  • 1 @PeterMader Maybe because, they have different scopes with import/export stuff. How would you load module A from module B, if it would a single file? – user8245660 Commented Jul 30, 2017 at 14:15
  • Webpack allows you to bundle ES6 modules with minimal configuration: E.g. ccoenraets.github.io/es6-tutorial/setup-webpack – Sven van de Scheur Commented Jul 30, 2017 at 14:17
 |  Show 4 more ments

2 Answers 2

Reset to default 1

I wonder, how should I minify and prepare the project release-file?

That is purpose of this action? Okay, minified files take fewer network traffic, and will be downloaded faster, but most NPM libraries provides minified dist-files already. And main question about bundling in one big file.

Why webpack do it? Of cource, due absence of support for ES-modules in browser by native, What's why webpack resolves import statements and round dependencies in synchronous manner*, and then substitute it to IIFE for scoping. And perform babel translation and polyfilling, yes.

But then native support of ES-modules is started, it's bee un-useful. One of main goals when exposing your web-app to production, is minify traffic volume for your server, using CDN. Now you can do it in native way, so just import ES-modules from unpkg and be happy

*If not using HMR, of course, But it's not appropriate for production mode.

Live examples here: https://jakearchibald./2017/es-modules-in-browsers/

This blog explains how you would use the ES6 module syntax and yet still bundle your code into something that the browser will understand.

The blog explains that using SystemJs as an ES6 module polyfill and Babel along with Gulp will enable you to code you modules in ES6 yet sill be able to use it today.

https://www.barbarianmeetscoding./blog/2016/02/21/start-using-es6-es2015-in-your-project-with-babel-and-gulp/

Using this guide will help you write your code in ES6 while still having a normal workflow to building, minifying and bundling your code.

Keep in mind there are a lot of tools out there that will help you achieve this but I've followed this method many times and I can vouch for its validity.

本文标签: javascriptHow do you buildbundle amp minify ES6modulesStack Overflow