Rust+wasm without npm

#1

I want to use the wasm backend for Rust with wasm-bindgen, but not use a nodejs server; I have a different server instead.

I’ve been following this guide.

I compiled by code successfully into a hello.wasm file. I ran wasm-bindgen successfully and got the postprocessed hello_bg.wasm and a hello.js file.

Now the guide tells me to use webpack to package these files into an ES6 module, and then import it as follows in a second js file:

const js = import("./hello");

js.then(js => {
  js.greet("World!");
});

All my attempts at creating this ./hello module from my existing files has failed. My browser is unable to import the "./hello" module.

How do I finish this final step without npm?

#2

This needs to be documented a lot better, but I found this in the manual, listed fairly non-obviously. https://rustwasm.github.io/wasm-bindgen/examples/no-modules.html

1 Like
#3

For anyone following along, that link already seems to be broken – I found what I believe is the same information here: https://rustwasm.github.io/wasm-bindgen/reference/deployment.html