$ opam install js_of_ocaml-compiler
Compiling to JS¶
Dune has full support building jsoo libraries and executables transparently. There’s no need to customize or enable anything to compile ocaml libraries/executables to JS.
To build a JS executable, just define an executable as you would normally. Consider this example:
echo 'print_endline "hello from js"' > foo.ml
With the following dune file:
(executable (name foo))
And then request the
$ dune build ./foo.bc.js $ node _build/default/foo.bc.js hello from js
Similar targets are created for libraries, but we recommend sticking to the executable targets.
executables stanzas, you can specify js_of_ocaml options
<js_of_ocaml-options> are all optional:
(flags <flags>)to specify flags passed to
js_of_ocaml. This field supports
<flags> is specified in the Ordered set language.
The default value for
(flags ...) depends on the selected build profile. The
dev (the default) will enable sourcemap and the pretty
Dune supports two modes of compilation
The separate compilation mode will be selected when the build profile is
dev, which is the default. There is currently no other way to control this