Join GitHub today
ES modules #3613
Previously: #2207, #2558, #2574, #2575, #3427. I'm making a new issue because the discussions in many of the linked issues are quite long, and because the ES modules landscape has changed quite a lot since when most of the discussion happened two years ago (in particular, all major browsers now support ES modules). Also, we should probably implement emitting ES modules at the same time as switching to ES modules for FFI, so I think all of these things should be considered together.
ES modules provide a number of benefits over CommonJS; most notably easier dead code elimination and wide browser support (see https://caniuse.com/#feat=es6-module). Having the compiler use and understand ES modules natively would mean that many workflows wouldn't require bundling at all, which would significantly speed up and simplify things, especially during development.
It should remain possible to run a PureScript-only app in modern browsers and in Node.js with just
I think the following is relatively uncontroversial, and is what we generally have settled on in the above linked issues:
There are some slightly harder questions to be resolved about how we approach FFI files still. The only part of the compiler which needs to care about the format of FFI modules is
I don't think we should have people use the
I should probably also address the question of whether the compiler should be able to produce both output modes (ESM and CommonJS) via a flag. I'd much prefer to not do that: maintaining both ESM and CommonJS output at once would be a lot more difficult, and most workflows should be able to handle ES module output from the compiler without much adjustment, and possibly without any adjustment at all, since the plan is that
I'm excited about this. Support for ES6 modules in node is still experimental but it does support the .js extension when the nearest package.json has
In addition to mangling primes we should probably mangle keywords and
@twitchard and I spent this weekend’s NYC CoHack Haskell hackathon setting up a test bench for evaluating dead code elimination (DCE) / tree shaking using webpack + PureScript. Please give it a shot: https://github.com/gasi/purescript-dce-benchmark#purescript-dead-code-elimination-proof-of-concept
We used basic TDD to see status quo and where my fork of the compiler gets us.
As many of the referenced issues point out: We are currently blocked by the lack of support for ES2015+ in
Curious to hear other people’s thoughts. Would love to move the PureScript compiler + ecosystem to ES modules