DEV Community

Cover image for Parcel and Rust: A WASM Romcom

Parcel and Rust: A WASM Romcom

Alex Eales on May 15, 2020

Web Assembly (WASM) and Rust have been growing and evolving over the last couple of years, so what’s it like to use them together? Introd...
Collapse
 
kayis profile image
K • Edited

Awesome journey and congratulations to your first post :D

I started with Rust and WebAssembly too a few weeks ago.

But I went from reading the "The wasm-bindgen Guide" to reading "Programming WebAssembly with Rust" to simply using wasm_bindgen/wasm-pack to build a library.

I saw an update of Parcel on Twitter a few days ago where they mentioned static WASM imports and .rs files, so I was intrigued.

After reading your post I was happy that I didn't start with Parcel, tho' :D

What's the story behind WASM library creation with Parcel? Or should I simply stick to wasm-pack, which seems okay-ish right now.

Collapse
 
alexeales profile image
Alex Eales

Thanks so much and glad you enjoyed the article and have been having some fun with WASM and Rust too!

The import .rs feature on Parcel is really amazing and works well for small programs where you might want to move some performant functions to Rust but I've found doesn't scale too well!

As for the Parcel vs wasm-pack I would definitely agree wasm-pack is more established and has the official backing from Rust. The reason I've been a fan of Parcel for a while now has been the 0 configuration nature which has let me get projects up and running super quickly (simple as importing a .ts file in the HTML and then TypeScript is setup for you)! This definitely has it's drawbacks and I wouldn't use Parcel on a large project yet but for little things like this and getting something off the ground I'm hardpressed to find something that beats it :)

Collapse
 
martinkavik profile image
Martin Kavík

Hi, guys Seed maintainer here.

There is a Rust-only template for Seed apps, but it shouldn't be hard to modify it if you don't want to use Seed. The heart is cargo-make - it's a very nice cross-platform task runner and it can install things like wasm-pack automatically.

I see you like Tailwind - perhaps production ready webpack & tailwind template would be interesting for you.

I'm just rewriting Seed official guides from scratch, but once ready I'll be working on a "one-command starter" for Rust apps - Seeder.

Cheers, Martin

Collapse
 
alexeales profile image
Alex Eales

Hi Martin,

I remember looking into Seed a little while ago and am thinking of exploring it further given another break from project work! Also the webpack and tailwind template would be interesting as setting up PostCSS with Parcel was another dependency I didn't want to set up.

Looking forward to seeing Seed develop and this one-command started!

Thanks for reading :)

Collapse
 
jonknapp profile image
Jonathan Knapp

Thanks for the post! I went through a similar experience getting my wasm/Rust app started; having a desire to cut back on the number of npm dependencies needed to run/build a primarily wasm application.

In the end, I went with a home-rolled setup using nginx (in Docker) and a Procfile to run cargo watch and wasm-pack. Getting the perks of hot reloading/ease of use with a Parcel/Webpack setup is the direction I would point others in though.

Interestingly, the number of dependencies that need to be installed to build a Parcel app is larger than a barebones webpack app. That led me to snowpack, but it seems to be right in the middle of a v2 transition and the docs for writing plugins are not there yet. I'm interested to see where it goes though as I'm a fan of fewer moving parts/pieces.

Collapse
 
alexeales profile image
Alex Eales

Glad you like the post! I think I was going down the same path as you with Docker at one point but hastily escaped that rabbit hole but sounds like you found a nice solution with it!

That is a interesting investigation I forgot to look into, I would expect that this is due to Parcel coming pre-bundled with a few plugins and dependencies out of the box than barebones WebPack, something for me to consider in the future!

I had never heard of snowpack before seeing this but sounds and looks really interesting I will have to give this a look for a project I'm about to start! :)

Collapse
 
jonknapp profile image
Jonathan Knapp

The code's at github.com/CoffeeAndCode/remnant-c... if you're interested, but I would not recommend it's current state. It currently lints/tests before building which is way too long to wait for new wasm builds. Also, for a better Docker solution I'd package more of the build/web server into a single Docker container for ease of installation.

I believe you're right on the install size differences. Parcel is trying to make a better dev experience which doesn't include finding an array of packages to install then digging through docs on how to use them.

Snowpack seems interesting, but make sure it fits your end goals before investing too much. It's goals are a bit different than the other packagers out there.

Thanks again!

Collapse
 
maruru profile image
Marco Alka

It's funny, how for me Parcel is the ex I cannot work with - especially because it is impossible to link a file which is not managed by Parcel, which makes 90% of my projects unbuildable with Parcel. WebPack is my packager of choice, because I can easily decide, how certain files are handled, what to exclude or how to queue certain processing steps to build exactly what I want.

Having said all that, I recently stumbled across a new bundler, which seems to be a cross-over between WebPack and Parcel. It's WebPack, but automated. And they say that it's fast. Have you ever checked out SnowPack?

Collapse
 
berkus profile image
Berkus Decker

JFYI, I made a short article on how to set it up a while ago: metta.systems/blog/building-wasm-w...

This was all I needed to start going.

Collapse
 
alexeales profile image
Alex Eales

Nice concise writeup, wish I had seen this before I went on this journey! I'll have to give this approach a go next time I have some free time to work on some WASM :)

Collapse
 
thisdotmedia_staff profile image
This Dot Media

Great read. Awesome job on your first post 😃 And this was a cool pairing, thanks for sharing your insight with all of us!

Collapse
 
alexeales profile image
Alex Eales

Thanks so much! :) Hope this helped you and would love to hear if you make anything using WASM!