-
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
Documentation: Needs full example of web-sys DOM #1034
Comments
Glad to see there are also someone that want to able to use wasm-bindgen without the need of
If you go with |
please someone do that, not everyone going after wasm is JS programmer and many of us are not web developers just because we hate JS and Node; we need to write our programs in Rust, not node. |
Do you have more details on option 1? Unable to get it working as-is. Option 2 seems messier than the JS workaround I mentioned. |
@TitanThinktank i created a pr, but it's likely to be closed. Anyway, you can grab the example from the diff, or even take it to your own repo. |
@David-OConnor thanks for the report! Can you elaborate on how (eventually when browsers support wasm-as-ES-modules this'll work more seamlessly!) |
@alexcrichton Gave it another shot just now... Working as advertised, on Chrome and FF, although not Edge! (Of note I'm now getting a MIME-type error with the webpack dev server, but the Rust HTTPS server works; related: These are the only dev servers I've ever been able to get working with WASM, due to MIME issues) I must have made a mistake or left something out on my first attempt For someone not familiar with the dets of ES modules, this quote, is a bit confusing: Lately, I've been using wasm-pack to build due to its simpler CLI, but it looks like it doesn't support --no-modules yet. (Haven't dug through the source, but it seems to mainly wrap the build and wasm-bindgen commands, so this should be straightfwd to implement). Relevant: rustwasm/wasm-pack#317 |
i am a total newbie but if this can help, https://developer.mozilla.org/en-US/docs/WebAssembly/Using_the_JavaScript_API#Some_simple_examples. if anyone can use that "fetch" to load the wasmpack generated .wasm file with it, it might make things bearable. i am asking here, so a reply regarding fetch() would be of great help. |
@David-OConnor oh ok good to know that it works! Can you gist the error message you're seeing in Edge? That sounds like a bug! @TitanThinktank we already use |
@alexcrichton |
@David-OConnor That's because wasm-bindgen uses Those APIs are supported in all major browsers except for Edge, which is why you're getting that error. So you'll need a polyfill. Perhaps wasm-bindgen should auto-include a polyfill for |
Thanks to all those who replied here, it has helped, but i am new to JS and hence web development itself though i am a old school programmer, the mention of webpack stopped me in my tracks, and meer mention of Node or npm irritates me, its my personal problem, if below two line were not there in the introduction i would had been encapsulating html through Rust objects by now, |
i have not yet seen the light of wasm-bindgen "hello world" working on my machine till now, i hope someone creates a step by step tutorial without the damn mention of Node or npm. Also judging by the comments and issues raised here, it seems things are working for other people here, this is very sad for me. is there any other IRC or forum where i can ask such questions ? |
@TitanThinktank Are you trying to call rust funcs from JS, build a webpage entirely in Rust, or something else? |
ibaryshnikov, why are you posting that link, why will anyone use a build.sh, i am learning how to do wasm, David-OConnor , it seems that --no-modules example wont work without a webserver, thats not how it should be, its a problem of ES6. And i understood that only by combining the two Script tags given here, https://rustwasm.github.io/wasm-bindgen/reference/no-esm.html |
I have not found a way to run WASM from an HTML file alone without a server; it seems as if doing so is on its way out in general. |
@TitanThinktank The #!/bin/sh
set -ex
cargo build --target wasm32-unknown-unknown
cargo run --manifest-path ../../crates/cli/Cargo.toml \
--bin wasm-bindgen -- \
--no-modules \
../../target/wasm32-unknown-unknown/debug/no_modules.wasm --out-dir .
python -m SimpleHTTPServer All it does is run some You don't need to use the
All useful WebAssembly programs need to contain JavaScript code. And so to avoid reinventing the wheel, we use standard JavaScript tools (npm, Node, and Webpack) to manage the JavaScript code. Similarly, we use standard Rust tools (Cargo) to manage the Rust code. If you wish to completely avoid npm, Node, and Webpack, the
No, it has nothing to do with ES6 (or Rust, or npm, or Node, or Webpack, or wasm-bindgen). It is a limitation in WebAssembly itself: web browsers will refuse to load a WebAssembly file which does not have a MIME type of That is why you must use a local web server to test the code. |
I did try to explain it, but I am so slow and @Paun beats me. In other words: the mentioned As you already known. The app need a local server, and the |
@limira How'd you get it working with Python's server? (Python3 command is |
I think you need this: |
@limira Thanks - after adding the first script section of that file, it now works with both Python's server, and opening the html file directly. Of note, the code in the third script section is quite different from what I'm using, which I got from a diff wasm_bindgen example.
|
Oh, I never need to open the html file directly so I totally forget that deleting |
since i dont want to waste time learning about Python server, i have nothing more to say about build.sh, instead i will put that time reading something about rust web apps which can help serve wasm files, and i bet that wont need anything about webpack. |
Usually I use https
|
By limiting wasm to server content, that wont keep nodeJS alive , but it will kill the webbrowsers for sure and my guess is that the wasm developers wont like that future for their webbrowsers. Although i will love to thrive in such a future, in fact finally web will become free from WebBrowsers as a defacto platform. |
I believe this issue is now best served by #446, so closingi n favor of that. |
The Websys section of the official guide includes how to build WASM modules, but not how you'd use in a webpage. For example, if I create an HTML file, serve it, and add
<script type="module" src="my_module.js"></script>
, I receive the error in browser console:Loading failed for the module with source “http://localhost:8000/my_module_bg”.
I've found I can get it working using Webpack 4, with a minimal package.json, webpack.config.js, and but is there a way to do this without using the Webpack and npm ecosystem, eg pure Rust?
index.html includes:
<script type="module" src="main.js"></script>
package.json:
webpack.config.js:
main.ts:
Stated another way: How can I replace the above code with this line in index.html?
<script type="module" src="my_module.js"></script>
(or .wasm, or _bg.wasm )The text was updated successfully, but these errors were encountered: