Library
Module
Module type
Parameter
Class
Class type
Ocamlbuild plugin to build with js_of_ocaml
Initialize the js_of_ocaml ocamlbuild plugin with the following code in myocamlbuild.ml:
let _ = Ocamlbuild_plugin.dispatch Ocamlbuild_js_of_ocaml.dispatcher
Side note: Ocamlbuild_plugin.dispatch
should be used only once. The last call will override previous ones.
If you use oasis, myocamlbuild.ml should look like:
let _ =
Ocamlbuild_plugin.dispatch
(fun hook ->
dispatch_default hook;
Ocamlbuild_js_of_ocaml.dispatcher
~oasis_executables:["src/yourprogram.byte"]
hook;
)
Build a JavaScript program myprog.js by calling the command:
ocamlbuild -use-ocamlfind -plugin-tag "package(js_of_ocaml-ocamlbuild)" myprog.js
It will first build the bytecode myprog.byte and finally produce myprog.js (in _build).
One can pass option to the Js_of_ocaml compiler using tags. See <<a_manual chapter="options" |Options>>.
Available tags:
In the _tags file:
<myprog.js>:pretty, opt(3)
val dispatcher :
?mode:[ `Default | `Legacy ] ->
?oasis_executables:Ocamlbuild_plugin.Pathname.t list ->
Ocamlbuild_plugin.hook ->
unit
The main dispatcher
?mode:`Legacy
can be used to fallback to the old way of querying findlib for javascript runtime files.
?oasis_executables
is the paths of the executables (having the .byte extension) you want to compile as a javascript executable. The former executables are still compiled.
Side note: Ocamlbuild_plugin.dispatch
should be used only once as it record only one function for an ocamlbuild module.