BuckleScript Bundler?


#1

Just curious if there are plans or ideas to create a bundler inside of the BS ecosystem.

A good type system can make tree-shaking and other optimizations better/faster (from what I understand), so it seems like ReasonML -> BuckleScript -> Webpack leaves lots of interesting things on the table.

I don’t really have a great understanding of the toolchain or how or if something like this would work. I’m mostly just curious.


#2

BuckleScript already aggressively optimises as much as it can at the module level :slight_smile: try out some expressions in the online playground to get a feel for it.

BuckleScript currently relies on bundlers to do DCE across modules, this may change in future but I wouldn’t count on that, the current separation of responsibilities seems pretty good.

What we might see happen is the rise of native OCaml bundlers with speedy and efficient operations. Currently we have https://github.com/fastpack/fastpack and https://github.com/jaredly/pack.re so it’s early days yet.


#3

There are brief talks on a “lambda linker” for BuckleScript, but considering the priorities right now it’s deferred. While it sounds great in theory, making it work in practice is harder. You need to consider e.g. lazy loading, plugins, different modes, integration into existing toolchains, etc. Probably fine leaving it in userland for a little longer as shown above.


#4

Whole program optimisation is actually fairly difficult. There’s an entire separate ocaml compiler mode (flambda) for it.

Webpack/rollup do a pretty decent job already, from what I’ve seen, and personally I use es6-global modules so I only need to bundle for distribution and the bundle speed doesn’t impact my development.


#5

Could ypu please share your current set up with es6 global? I’m using webpack and the build speed in development is a bottleneck


#6

Sure, I’ve extracted the basics of what my project does and created a simple repo with a readme describing the main limitation I’ve found. This setup works really well for me.


#7

Thank you. I’ll look into it