-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should jsoo-react vendor react.js? #104
Comments
Apologies in advance for the stream of thoughts below. I'm still very new to JSOO, and just throwing ideas out there in the hopes that something might stick. Feel free to ignore if it makes no sense :)
You could always just fork Not an approach I'd recommend for every binding library, but for something as fundamental as Alternatively I wonder if it's possible to inject the dependency somehow. For example, ignoring the general awkwardness and the need to completely restructure (* react.ml *)
include JsooReact.Make(struct
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")|}
end) Or maybe publish separate packages, using dune to conditionally compile it as vendored, so it could be opted into. (In Rust I'd use "features" for this, but for OCaml that would require both |
Thanks for sharing your thoughts @glennsl. I remembered now why I went for current approach using The main downside of vendoring So, I ended up going for the
Point 2 is pretty minor, but I think point 1 makes it very likely that consumers will need Webpack or some other bundler. I am happy to consider the proposal and build some proof of concept if there are specific cases out there of projects that use What do you think? |
Hmm, why would it have to process the JavaScript? And why would that be slower than
I'm not sure that's true. Although I'm not a big consumer of third-party react components myself, so who knows. It certainly wouldn't be the weirdest thing I've encountered in the JavaScript universe. But why would you package the raw source code, and require consumers to use all of your builld-time tools, rather than package the processed JavaScript? A third option might be to use |
Right now, jsoo-react calls
require
to bring react.js libraries:jsoo-react/lib/imports.ml
Lines 9 to 11 in 6f9eba0
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:
Downsides:
jsoo_global_object
with all the downsides that relying on globals bring.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?
The text was updated successfully, but these errors were encountered: