Skip to content

Loading additional js_of_ocaml-compiled js files dynamically #450

@zoggy

Description

@zoggy

Hello,

Suppose I have a program with a module offering a plugin interface (some register function).
I compile this program using js_of_ocaml and make an HTML page load this script. Fine.

Now when I compile a plugin.ml file to plugin.cmo then to plugin.js, I get this error in the browser console when it is loaded: ReferenceError: caml_get_global_data is not defined.

Are there any compilation flags to make this work ? I tried a --no-runtime with no success.

I saw there is some Dynlink support but the --file and pseudo filesystem is not very clear. I made a test: First I compile plugin.ml to plugin.cmo. Then I add a dummy.ml file with:

Dynlink.loadfile "plugin.cmo";;

I compile this file and create a plugin.js file:

ocamlfind ocamlc -c -package js_of_ocaml.ppx dummy.ml
js_of_ocaml -o plugin.js -I ./ --file=plugin.cmo dummy.cmo

Now when loading plugin.js in the test page, I get: ReferenceError: caml_fs_register.

My goal is to be able to fetch cm{o,a} or .js files from urls and load them in my js_of_ocaml-compiled application.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions