-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support Custom JS Imports #224
Comments
This is what I would expect. |
I have been looking through the |
I'm not sure I follow -- can you explain some more? |
We could add a new case to the The behavior of this would not change This would attempt to find the file provided and append the contents of that file to the bindgen'd js file Hopefully that clears things up? |
I would expect it to be the JS bundler's job to concatenate JS modules together, rather than |
Maybe I was unclear with my initial description of the issue. Since we are targeting both Developer's of Rust libraries, like the rand crate, might need to include arbitrary bits of javascript to become compatible with Maybe, this is the wrong direction? |
Thanks for opening an issue for this, I'd meant to do so a long time ago and hadn't gotten around to it! I think there's a lot of design space here and I think it's also gonna be pretty difficult to solve all the constraints (depending on how many we'd like to bring on). I definitely think that wasm-bindgen needs a story for "hey I wrote a small snippet of JS and I'd like to include it here". I definitely agree with @fitzgen that ultimately it's gonna be the bundler's job to actually interpret a lot of the JS here and do final postprocessing for syntax and such. The main question to me is how to we actually get these files from the local filesystem and in-crate directives over to the bundler. For that I can think of:
I'm not entirely sold on any particular strategy yet, but I'd definitely love to explore this! cc @lukewagner, we've discussed this in the past as well |
I definitely like the idea of being able to include arbitrary bits of JS (written as ESMs) in the crate and the original comment is a great use case. My default assumption is that said glue wouldn't be injected into the wasm-bindgen-generated glue ESM. You'd just have either: |
I had written some posts covering this problem in a lot of detail (and offering a good solution): rustwasm/team#92 (comment) I hope they're helpful. |
By the way, the above posts are a little outdated (you should mentally replace |
Implemented in #1295! |
An issue was filed in the rand crate to add
wasm-bindgen
support.rust-random/rand#478
This is currently stalled because the maintainers there don't want to use
Math.random
the only other option would be to include the native crypto functions. The problem with this is that in the browser you would usewindow.Crypto
but in node it would berequire('crypto')
.Currently
wasm-bindgen
is usingWhen it encounters a similar problem.
One solution for this would be to allow for arbitrary JS to be included in the
wbg
js output.This would allow library developers to utilize the same tricks that
wbg
is using itself.One example of how this might look would be
I am sure there is a lot more this that what I was able to outline above, I am curious what the community things about how we might go about doing something like this?
The text was updated successfully, but these errors were encountered: