DEV Community

Cover image for I can't believe it's WebAssembly!!!!
Josh Wulf
Josh Wulf

Posted on

I can't believe it's WebAssembly!!!!

Sure, you saw the WebAssembly Package Manager on Hacker News today, but you might have missed the earth-shattering historical significance of it.

"Write once, run anywhere" for Rust apps targeting WASM is now a thing.

"But what can you do with it?" I hear you ask.

"Sure I can spin up an nginx server with it, but I can do that with Docker."

Well, the world just changed, because with the lolcat WebAssembly package you can do this:

Listen closely, young Padawan, as I show you how to make this happen.

With Wasmer you can run universal WebAssembly binaries. With the WebAssembly Package Manager you can install WebAssembly binaries from a central repository, akin to JavaScript's NPM.

And among the small number of WebAssembly packages available right now is lolcat - which gives your boring text rainbows and unicorns!

One thing to know about the wapm command from the WebAssembly Package Manager: it doesn't currently have a -g flag like npm. This means all wasm package installs are local.

There is an open feature request for it (feel free to vote with a thumbs up on it), but in the meantime you can work around it.

Here is what you do:

  1. Install the wasmer runtime (which includes the wapm package manager CLI).
  2. Make a directory ~/.wapm.
  3. Add the following to your ~/.bashrc (or ~/.zshrc for zsh) file:
function wapmg() {
    pushd ~/.wapm
    wapm install $1
    popd
}

function lolcat() {
    cat $1 | wasmer run ~/.wapm/wapm_packages/_/lolcat@0.1.2/lolcat.wasm
}
Enter fullscreen mode Exit fullscreen mode
  1. Run source ~/.bashrc (or source ~/.zshrc for zsh)
  2. Run wapmg install lolcat

Now you can use lolcat in place of the boring, old cat command, and get rainbows and unicorns in your terminal with WebAssembly.

WELCOME TO THE FUTURE!

Top comments (0)