1

The js_of_ocaml documentation says about making a Node.js module:

Js.export and Js.export_all will export a value to module.exports if it exists.

What I'm confused about is the "if it exists" part. How do I make sure that the module def exists? i.e. if I'm making an OCaml library that I'd like to be able to import from JavaScript (TypeScript actually), how can I make sure that I get such a module as the output of js_of_ocaml?

jmite
  • 8,171
  • 6
  • 40
  • 81

1 Answers1

0

If module.exports exists, a value is exported as node module. And if module.exports doesn't exists (on web browser for example), a value is exported as global variable.

zakki
  • 2,283
  • 14
  • 20
  • Right, but how do I make "module.exports" exist in the generated JS code? – jmite Jun 29 '18 at 05:34
  • node.js (or other runtime) prepares "module.exports". For web browser, a module bundler like browserify, rollup or webpack is needed. – zakki Jun 29 '18 at 05:49