ocamljs-of-ocaml

How does one use dune to create a js_of_ocaml library?


I'm wondering what a dune file looks like for a library (rather than an executable) which compiles to js_of_ocaml and why is it recommended to use an executable instead?


Solution

  • You don't need to do anything particular for libraries to make them compatible with js_of_ocaml: js_of_ocaml works on the final executable bytecode, regardless of the libraries.

    That being said, if you want to use js-specific things, js_of_ocaml is also an ocaml library that you can just depends on and which will contain bindings to various javascript functions.

    (library
      (name my_library)
      (public_name my_library)
      (libraries (js_of_ocaml))
    )
    

    For building js files, you should use the executable stanza (as per the dune docs).