0

I am working on a project and I would like to combine everything into a single mjs file that can be distributed. I at first thought about Webpack but it seems to output to ES5 (However, I did get it to work) so I had to run without --experimental-modules. I also tried rollup, however, it again converted it back to es5.

Is there a way to have it basically just create one big mjs file? Should I just concat them all?

Jackie
  • 21,969
  • 32
  • 147
  • 289
  • 1
    I don't think rollup converts to ES5 by default. So either you configured it to do so, or you are misinterpreting the result. – Felix Kling Oct 22 '18 at 20:15
  • I don't want it in es5 I want it to stay in es6 – Jackie Oct 22 '18 at 20:18
  • Am I just thinking about it wrong or something? I tried using babel, but that just flat out concats so the imports don't get updated. Is it because ECMA6 doesn't have a default module loader so you have to use a es5 equivalent like web pack? – Jackie Oct 22 '18 at 20:34
  • *I at first thought about Webpack but it seems to output to ES5* - it doesn't. – Estus Flask Oct 22 '18 at 20:43
  • It seems to when Target is node – Jackie Oct 22 '18 at 22:18
  • And if it is using es6 not es5 why doesn't experimental-modules work and why is it using require instead of import? – Jackie Oct 22 '18 at 22:20
  • 2
    I think you've are making your question confusing by talking about ES5. It sounds like what you want is to consume module files and output module files, is that right? In which case it's not a differentiation of ES5 vs ES6, but one of Script vs Module. – loganfsmyth Oct 22 '18 at 22:21
  • 1
    Module formats is not the same as language version (yes, ES6 introduced modules, but that doesn't mean that CommonJS modules are "ES5"). You have to tell rollup (and others) in which module format you want the result to be. https://rollupjs.org/guide/en#big-list-of-options `output.format`. – Felix Kling Oct 22 '18 at 23:27
  • So let me clear some things up. From what I understand ECMA6 has modules in the spec but not a module loader. Node has a built in module loader when you use experimental modules, this includes a built in module loader (IE I don't need commonJS or AMD or UMD). However, when I run webpack it seems to repackage it using commonjs modules (by default). I am looking to just use ecma modules. That being said I did try to make a minimal project and it does "run" however the output does not appear to use ECMA6 modules. I will post gist shortly – Jackie Oct 22 '18 at 23:49
  • Ok here is the Gist and it looks like a lot of people were right it is mainly cosmetic things that were throwing me off (https://gist.github.com/jrgleason/33ddb36231448e84889fbd2b1201eb67). The fact that var isn't let, The fact it is using a variable instead of using an import (not even sure how that would work honestly but I was used to webpack wrapping). I can put the question on ice for now, until I figure out why my more complicated project was actually having a problem. On another note is it possible to not include the webpack bootstrap? – Jackie Oct 22 '18 at 23:59
  • Hack for followup to end question https://stackoverflow.com/questions/43484895/webpack-remove-webpackbootstrap-code – Jackie Oct 23 '18 at 00:05
  • There hasn't been an environment that fully supported ES6 modules for a long time, so it seems to make sense that module bundlers rewrite native modules to something that runs in current environments. With more environments supporting native modules, maybe the default output will change over time. – Felix Kling Oct 23 '18 at 20:22

0 Answers0