ml-in-barcelona / server-reason-react

Server render Reason React components with OCaml natively
https://ml-in-barcelona.github.io/server-reason-react/local/server-reason-react/index.html
MIT License
133 stars 8 forks source link

Support assets in `mel.module` #134

Closed jchavarri closed 4 months ago

jchavarri commented 5 months ago

This PR adds initial support to compile externals like:

external img : string = "default" [@@mel.module "./image.svg"]

Into something like:

let img = "/image-DWDWZCEH.svg"

~The output file naming follows esbuild default shape and hash function. There is no option to configure anything else for now, we can slowly introduce as needed.~ Edit: the ppx now support choosing either -bundler esbuild or -bundler webpack. The default is webpack.

I decided to vendor the libraries base32 and xxhash for simplicity, to avoid forcing consumers to pin or download new packages, as they are quite small libraries and the versions that were needed are not available in opam.

jchavarri commented 5 months ago

I have updated the PR to support both Webpack and Esbuild, via a new flag -bundler that can be passed to melange.ppx.

For now the generated filenames follow the default name scheme used on each bundler case. We can add more features later on while testing, e.g. file templates like [name][hash][ext] like some bundlers do, or the ability to add prefixes to resulting filenames.

I also have left some failed attempt to produce Rspack hashes commented, as currently rspack doesn't support proper content hashes.

I decided to not include tests against the actual Webpack or Esbuild bundlers hashes because these hashes should not change over time, and it would slow down and complicate the test suite quite a bit.