Skip to content

Should jsoo-react vendor react.js? #104

Open
@jchavarri

Description

@jchavarri

Right now, jsoo-react calls require to bring react.js libraries:

let react : react = Js_of_ocaml.Js.Unsafe.js_expr {|require("react")|}
let reactDom : reactDom = Js_of_ocaml.Js.Unsafe.js_expr {|require("react-dom")|}

This means that users of the library are forced to use some JavaScript bundler like Webpack to resolve these requires with the actual library code.

But we could instead vendor a version of React.js and connect OCaml bindings with the JavaScript library objects internally, without exposing all this connection details to end users. This is what some OCaml projects have been doing, like virtual_dom, that uses browserify to bundle the JavaScript library.

Upsides of vendoring:

  • No need to use Webpack or any bundler on client
  • More controlled environment (less chances of things going wrong as less parts required)
  • Simpler setup, templates, etc
  • Faster iteration loops

Downsides:

  • Vendoring would require to put React.js entry points (library objects) in some field under global jsoo_global_object with all the downsides that relying on globals bring.
  • It also means that there is less flexibility for users to decide which version of React.js they want to use. E.g. right now jsoo-react supports v16, but some user could start using v17 for some reason just by updating their package.json.

I guess it all comes down to how "close" to JavaScript ecosystem a project is: for projects leveraging a lot of JS related tooling, using Webpack or other bundler is not a pain (actually helps). But for projects leaning more on OCaml side, with very few JavaScript dependencies, adding bundler is actually overkill.

Any other things? What do you think?

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