Using existing ocaml packages


#1

Is there any preferred and clear way using a library written by plane OCaml published to opam?

The document of bucklescript might describes it.

But as mentioned in the issue below, the document doesn’t suggest a clear way.

My own question is Is there exist a way using OCaml library to build JavaScript code using it in some ReasonML project?


#2

If you’re in the BuckleScript ecosystem and compiling to JavaScript, there’s no simple, recommended way to use OPAM ecosystem packages. You could download the package source and try to bootstrap a new BuckleScript project inside it, but then you need to deal with transitive dependencies and possible C code.

At least the first problem though is solved by using the js_of_ocaml compiler, since that is firmly in the OPAM ecosystem and can handle transitive OPAM dependencies.


#3

Using js_of_ocaml like @yawaramin suggested is the best solution IMHO.

1 example I can think of is refmt. It’s compiled to JS with js_of_ocaml and then binded to bucklescript https://redex.github.io/package/unpublished/glennsl/bs-refmt


#4

Ah, I’d say understand, Big thanks!


#5

You can certainly install opam and use opam packages using any build system you’d like (bsb-native, jbuilder).
If you’re interested in getting opam package with an nom-like workflow I’d recommend checking out esy, both bsb-native and jbuilder work with it.

EDIT: all of this is only for native development.