In the world of bundlers, it is much easier to bundle a file that is a proper ES6 module than a JavaScript file that “clutters” the global scope.
It’d be amazing if I could opt-in into making Emscripten emit an ES6 module.
Currently, I am emulating that behavior in my projects by appending
export default Module;
or in the case of -s MODULARIZE=1 -s 'EXPORT_NAME="mymodule"'
export default mymodule;
to my glue code files.
There is -s EXPORT_ES6=1 which together with MODULARIZE=1 should do this, I think? (Anywhere we should add docs about it?)
Hm yes, that’s exactly the flag I needed. Apologies for not finding it myself. I wonder if it makes sense to mention this flag here.
Hmm, I'm not sure - that's about the Module object, but not about modular output. MODULARIZE isn't mentioned there, for example. I think we mention it in passing in other places. Probably we should have a new page dedicated to modular output.
FWIW I am writing on a getting started guide for web developers, where these kind of “good to know” things are gonna be mentioned. I’ll loop you in when I got a draft and we can decide if and where to put it.
Most helpful comment
FWIW I am writing on a getting started guide for web developers, where these kind of “good to know” things are gonna be mentioned. I’ll loop you in when I got a draft and we can decide if and where to put it.