I’ve wanted to try Rust together with WebAssembly for a long time. It was something of an engineering dream – a combination of strict typing, reliable performance, and the ability to run native code right in the browser. In theory, everything looked beautiful: small size, speed, security. All this is inherently connected with Rust. So, with a few weeks to spare, I decided it was time.
I was looking for a way to combine a Rust program with a modern interface without pain, but I quickly realized that official support was centered around Webpack. And Webpack has a complicated history with me: like an ex that you don’t want to go back to. It’s cumbersome, finicky, and almost always requires customizations that are easy to get lost in. I’d already gone through all that webpack.config.js, plugins, conflicts, and magic strings once before, and I wasn’t going to go back there.
But the desire to run Rust in the browser overpowered. I bent the template with Webpack support, opened the terminal, and started typing commands on automatic. But after a couple of minutes I realized – no. Ctrl + C. That doesn’t work for me. I remembered that I had heard about Parcel and its native support for WASM. I went to the site, ran through the documentation. Everything looked fresh, simple and – importantly – no configuration files. Installed Parcel, wrote a simple HTML page, plugged in JS and – suddenly – Rust worked. Simple. No configs. It was like taking a full breath.
The first example was elementary – a Rust function summed two numbers and the result was printed in the DOM. It was nothing special, but it worked. At that moment, I felt like I had opened a portal. I compiled my Rust code into .wasm, plugged it in via Parcel, and the browser honestly executed the native code. Fast, beautiful, painless. Everything I’d been looking for for so long.
But of course, the problems soon started. As soon as it came to strings – undefined started. It turned out that Parcel is not as friendly with wasm_bindgen as I would like it to be. Even a plugin found on GitHub did not save the situation. I was rushing between issues, trying hacks, hitting the same errors again and again. It looked like Webpack was winking at me from around the corner again.
And then I found stdweb. It was older, less popular, but it worked. It provided some of the functionality I needed and allowed me to finally work with strings. I rewrote the code a bit, rebuilt the project, and – finally – Rust started returning values instead of undefined. This success was inspiring: I decided to go further and implement something a bit more interesting – a simple genetic algorithm simulator.
I built the structure in Rust, implemented the basic methods, wrote an interface in TypeScript and connected them. Almost like a microservice, only inside a browser. But again there were problems: exporting structures via stdweb turned out to be unreliable. Everything crashed on the spot. A lot of time was spent on experiments, google, despair. It seems that even stdweb was not the ideal I had hoped for.
I was almost ready to give up and go back to Webpack. I even started cloning the template. But at the last moment, already in the process, I checked the old GitHub issue – and saw a new comment. Someone posted a working example with wasm_bindgen and Parcel. A real miracle. I cloned the repository and everything worked. Simple and without any tambourine dancing. That feeling when the slipper fits Cinderella perfectly.
Excited, I added TailwindCSS, rolled up the simulation control panel, plugged in the Rust module, and the whole project was up and running. Clean, fast, secure. I compiled, tested, and rolled it out to Firebase.
To summarize, Rust and WASM together are really powerful. Especially when you find the right tool, like Parcel, which saves you from endless customization. Yes, not everything is perfect, there are rough edges, especially with autocomplete and integration, but overall it’s a buzz. A real pleasure to develop. All you need is a little persistence, a little luck and the right repository found at the right time.
If you’ve been wanting to try Rust in the browser for a while, don’t wait. It really does work.