Does anyone have experience with using dune and js_of_ocaml to generate from a big OCaml codebase multiple JS libraries that can be dynamically load and bundled separately?
The problem I have is that I have a command-line application that I would like to make available on the web (semgrep), but the generated code for it is currently huge because every language supported by semgrep and their parsers are included in the code. In most cases, the user interacts with only one language at a time, so I would like to generate a parsing_go.js library, a parsing_java.js library, etc. and not require a user to load all those javascript code when he reaches my website. I would like to load this JS code on-demand, separately for each language.
Does anyone have experience with that?
I’ve looked at the dune documentation on its integration with js_of_ocaml but it does not say much.
If you are comfortable with Dune … I had a variation of the problem you have and solved it with a generated Dune include file. My problem was how to statically combine N “components” into a small number of executables, where N has to be discovered at build time. It doesn’t involve JS, but perhaps the idea translates to your problem. Which … if I were to reframe your problem … is how to statically generate N libraries, where N has to be discovered at build time.
(*) In my scenario … which is to generate an installer of components … I used ocamlfind to discover components at build time; in semgrep I think you have a JSON file you can parse.
I guess you mean https://wasi.dev/. We’re not using anything yet to generate JS.
tree-sitter indeed can generate WASM libraries for each language (I didn’t look what it’s using; maybe this wasi), but then OCaml side
we also have code that parse the output of tree-sitter (basically Concrete Syntax Trees of languages)
and this code is huge and I would like to generate different libraries for each OCaml wrappers of tree-sitter languages.