Parcel 1.x wasm-bindgen plugin for Rust

1.3.0 · abandoned · verified Wed Apr 22

parcel-plugin-wasm.rs is a Parcel 1.x bundler plugin designed to integrate Rust projects compiled to WebAssembly (Wasm) using `wasm-bindgen`. It streamlines the development workflow by automatically compiling Rust code with `wasm-pack` when Parcel 1.x builds the project. The latest stable version available is 1.3.0. A key differentiator was its ability to provide zero-configuration Rust/Wasm compilation for Parcel projects at a time when such integration was less mature. However, it is explicitly designed for `parcel-bundler` (Parcel 1.x), which has been officially deprecated and is no longer maintained. Parcel 2.x includes its own `@parcel/transformer-rust` for native Rust/Wasm support, rendering this plugin obsolete for modern Parcel environments.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic setup for integrating a Rust project compiled to WebAssembly with Parcel 1.x using `parcel-plugin-wasm.rs`. It includes the necessary Rust, JavaScript, and `package.json` configurations to greet a user from WebAssembly.

/* file: my-crate/src/lib.rs */
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn greet(name: &str) -> String {
  format!("Hello, {}!", name)
}

/* file: src/index.js */
import { greet } from '../my-crate/Cargo.toml';

document.getElementById('app').innerHTML = `
  <h1>Rust + WebAssembly in Parcel 1.x</h1>
  <p>${greet('Parcel user')}</p>
`;

console.log('Greeting from Rust:', greet('world'));

/* file: package.json (relevant part) */
{
  "name": "my-parcel-wasm-app",
  "version": "1.0.0",
  "devDependencies": {
    "parcel-bundler": "^1.12.5",
    "parcel-plugin-wasm.rs": "^1.3.0"
  },
  "scripts": {
    "start": "parcel src/index.html",
    "build": "parcel build src/index.html"
  }
}

/* file: src/index.html */
<!DOCTYPE html>
<html>
<head>
  <title>Parcel WASM Example</title>
</head>
<body>
  <div id="app"></div>
  <script src="index.js"></script>
</body>
</html>

view raw JSON →