package js_of_ocaml-ocamlbuild

  1. Overview
  2. Docs
An ocamlbuild plugin to compile to JavaScript using js_of_ocaml

Install

Dune Dependency

Authors

Maintainers

Sources

js_of_ocaml-ocamlbuild-5.0.tbz
sha256=aa59bcbf1ce27bcb2a3eb77a8a2c1ff17e9ddbe0f240e3a198ca1cebb0a1c07b
sha512=86f6ea777eb15ae289c2033874ecd007d3e8f861d73f4ee6fd5e95ed70b574718c3cf569aa007dc8a9ff943a441b99f51a12b8cf8999ae32a37989795d304bf5

doc/js_of_ocaml-ocamlbuild/Ocamlbuild_js_of_ocaml/index.html

Module Ocamlbuild_js_of_ocamlSource

Ocamlbuild plugin to build with js_of_ocaml

Initialize

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.

With Oasis

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

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).

Options

One can pass option to the Js_of_ocaml compiler using tags. See <<a_manual chapter="options" |Options>>.

Available tags:

  • pretty: Pretty print the generated javascript.
  • debuginfo: Output debug information.
  • noinline: Disable inlining
  • sourcemap: Generate sourcemap
  • tailcall(none): Set the tailcall optimisation (default "trampoline")
  • opt(3): Set the compilation profile (default 1)
  • debug: enables pretty, debuginfo, sourcemap

Exemples

In the _tags file:

  <myprog.js>:pretty, opt(3)

Dispatchers

Sourceval 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.

Low level functions

Sourceval oasis_support : executables:Ocamlbuild_plugin.Pathname.t list -> unit

Map each targets given as argument to ocamlbuild and replace each element that exists in ~executables by its corresponding .js target.

OCaml

Innovation. Community. Security.