If I remember correctly the js_of_ocaml compiler (or linker, technically) does global program optimisations to remove as much dead code as possible. This means that even an incremental change needs to go over the whole project again. I don’t know whether three seconds is a reasonable time for a project of this size or not though.
This example seems to use its own dune file to invoke js_of_ocaml. Use the built-in dune support.
@vlaviron is correct however if you build with dune in dev profile, jsoo separate compilation should be enabled. This doesn’t perform whole program optimisations and should yield shorter compilation times.
time dune build
Error: The package fso does not have any user defined stanzas attached to it.
If this is intentional, add (allow_empty) to the package definition in the
dune-project file
-> required by _build/default/fso.install
-> required by alias all
-> required by alias default
real 0m1.696s
user 0m1.819s
sys 0m0.314s
For the error, I think you need a public_name and/or package in your stanza.
If you ask this question because you find that the compilation time is too long for a development workflow, you can use dune build @check (or even dune build @check -w) to check that everything typechecks, which should be much faster. But it will not give you the .js output.
1 and 2, you’re correct.
3, it’s not really tree shaking. It is concatenating all files and merging source maps if any. The next release of jsoo will be able to omit unused compilation units from libraries similar to ocamlc. (Maybe you can call that tree shaking)
Some dead code elimination happens in (2).
“Tree shaking” happens when doing whole program compilation with jsoo