Hi everyone,
I’d like to share a ppx I’ve been working on to help us build frontends with JSOO at Skolem as well as a blog post to accompany it.
ppx_expjs is a ppx that helps generate the boilerplate of exporting OCaml values (including functions) to JavaScript when using Js_of_ocaml.
Example
my_module.ml
:
let concat (s1 : string) (s2 : string) : string = s1 ^ s2
[@@expjs]
node
:
Welcome to Node.js v16.13.0.
Type ".help" for more information.
> const my_module = require("./_build/default/my_module.bc.js");
undefined
> x.concat("Hello ", "World")
"Hello World"
>
(note there is no need to use either Js.string
nor Js.to_string
)
Blog post
I’ve written a blog post that describes why one might find this ppx useful and how it works, which can be found here.
Installation
Currently there’s no official release of the ppx on OPAM, but if you would like to install it you can run
opam pin add ppx_expjs https://github.com/skolemlabs/ppx_expjs.git