Closed xtuc closed 6 years ago
@alexcrichton last i checked we were not super amped about this interface? is this what is stable? if so i can build it into wasm-pack, but i had been holding off
This is "stable" but only in a "that's how the attribute works" sense and not a "this is expected to work" sense. Imports from relative JS modules are basically not at all expected to work today, and if they do it's happenstance. In that sense I don't think this bug is actionable at the moment until there's an actual design for how relative paths and such are supposed to work.
Today the #[wasm_bindgen(module = "...")]
is basically just configuring the import module of the wasm binary itself.
gonna close this for the time being, based on @alexcrichton's comment above about the (lack of) functionality stability.
Sorry for commenting in a closed issue. I'm facing the same issue of needing to call JS function from Rust. Is there any plan for implementing a feature for this or is it ready somewhere? @alexcrichton ?
I tried to copy my js file into the pkg
folder and it kinda worked locally. Not sure if this will work when deployed to a HTTP server.
hi @shinglyu ! this is indeed a feature we intend to implement- probably in the next month or so. no worries about commenting on a closed issue!
@ashleygwilliams Thank you! If there is an issue/task for it please let me know. Maybe I can contribute to the discussion (or implementation).
@ashleygwilliams was this ever implemented, or is it still something that is intended to be implemented? I'm hoping to call into some custom JS functions from Rust and trying to figure out if I need to switch to using wasm-bindgen directly, or if I can continue using wasm-pack. thanks!
@wtfleming I believe that importing local JS files should Just Work™ now (I use it all the time in my wasm-pack projects).
@Pauan thanks for letting me know, I seem to have it working now.
I think the problem may have been that running npm init rust-webpack my-app
as documented at
https://rustwasm.github.io/docs/wasm-pack/tutorials/hybrid-applications-with-webpack/getting-started.html installed "@wasm-tool/wasm-pack-plugin": "^0.4.2",
Updating the dependency on wasm-pack-plugin to 1.1.0
seems to have it working correctly.
With
wasm-bindgen
we can depend on local JavaScript files, like the following example (from https://github.com/rustwasm/wasm-bindgen/tree/master/examples/import_js):Actual
Which results in
Module not found: Error: Can't resolve './defined-in-js' in '/wasm-tool/rust-loader/example/pkg'
.Expected
defined-in-js.js
should be moved to./pkg
.Also note that other relative URLs needs to be rewritten?