Making a node module with js_of_ocaml


Making a node module with js_of_ocaml



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?


js_of_ocaml




1 Answer
1



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.


module.exports


module.exports





Right, but how do I make "module.exports" exist in the generated JS code?
– jmite
2 days ago





node.js (or other runtime) prepares "module.exports". For web browser, a module bundler like browserify, rollup or webpack is needed.
– zakki
2 days ago






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Possible Unhandled Promise Rejection (id: 0): ReferenceError: user is not defined ReferenceError: user is not defined