For Rust+WASM, what alternatives are there to Webpack?

I've been using this tutorial to learn Rust+WASM:

https://rustwasm.github.io/docs/book/game-of-life/

The tutorial uses Webpack to run and bundle code, but Webpack's commitment to backwards compatibility leaves a lot to be desired. Breaking changes seem very common in the Webpack API, not just from version 4 (the version used in the tutorial) to version 5, but also within major versions themselves. Although in many cases one could just use an older version of the API, the problem with this is that in some cases these API-breaking changes come with important security updates; so, often, Webpack users have to either spend valuable time re-reading its documentation to see what's new, or accept major security flaws in their applications.

(I know the problem above is common on the web, but Webpack seems to be an especially bad offender, compared to other bundlers. Also, Webpack's documentation is often grammatically incorrect, sometimes to the point of being hard to understand. In past efforts to improve the documentation, I have proposed grammar and style changes, yet have had my edits rejected by some non-native English speakers in charge who insisted that their writings were grammatically correct, even when I showed them grammar guides saying otherwise. But, I digress.)

I would seriously appreciate any links to good tutorials on how to use Rust+WASM with bundlers other than Webpack. Or, if no such thing exists, maybe someone should make one. I think it would be good for the future of web development with Rust if an expert revised the main Rust+WASM tutorial so that it is independent of Webpack (or any bundler in particular).

I'm using Trunkrs

1 Like

The wasm-bindgen docs have a page on loading modules directly into the browser with no bundler

https://rustwasm.github.io/docs/wasm-bindgen/examples/without-a-bundler.html

1 Like

Vite is a popular replacement built on rollup that has had very simple upgrades, but it is quite opinionated and it's a pain for MPA apps.

It has some support for WASM: Features | Vite

1 Like

If learning rust/wasm, in addition to the "correct" way ie, wasm-bindgen, I suggest also learn and play a bit with the "manual" way.

I suggest reading the mozilla webasm docs. In particular the "web assembly concepts", "Loading and running web assembly", "Using the web assembly javascript api", "exported web assembly functions", "Understanding web assembly text format", and "Converting web assemble text format to wasm".
NOTE: You don't need to understand everything but should have a basic idea of what happens with webasm and how it is loaded.

And check out this simple example of loading wasm manually.

After you compile the above example, turn the wasm into wat and look at it.
Read the index.html and look at the javascript inside.

I don't do it manually. I don't even think about how it is done anymore. I use "egui" and "egui" uses trunk and trunk does whatever it does for me.

4 Likes

This article is already a bit out of date with regards to setting up Svelte, but its info on using rollup may still be relevant.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.