gitmyhub

wasm-pack

Rust ★ 7.2k updated 8d ago

📦✨ your favorite rust -> wasm workflow tool!

wasm-pack is a command-line tool that compiles Rust code to WebAssembly and packages it as an npm-compatible module, so you can call high-performance Rust from JavaScript without manual toolchain wrangling.

RustWebAssemblyJavaScriptnpmwebpacksetup: moderatecomplexity 3/5

wasm-pack is a command-line tool that handles the workflow for compiling Rust code into WebAssembly and packaging the result for use in JavaScript projects. WebAssembly is a binary format that modern browsers and Node.js can run at near-native speed. It lets you write performance-critical code in a language like Rust and call it from JavaScript as if it were a regular package.

Without wasm-pack, getting Rust output into a JavaScript project involves several steps and tools that need to be coordinated manually. wasm-pack bundles those steps into a small set of commands. The build command compiles a Rust crate into a WebAssembly binary and wraps it with the JavaScript glue code needed to call it from a browser or Node.js. The output is a package compatible with npm and bundlers like webpack, so it slots into existing JavaScript workflows without requiring a different toolchain.

The new command generates a project from a template to help you get started quickly. The test command runs tests in a browser environment, which is useful when the code needs to behave correctly inside a web page. The pack and publish commands create a distributable tarball from your compiled package and optionally push it to the npm registry so others can install it.

Logging is available through the standard RUST_LOG environment variable, which lets you adjust the verbosity of output during builds.

The tool requires Rust version 1.30.0 or later. Installation is handled through the project's own installer script. The README is short and points to a dedicated documentation site for the quickstart guide, full command reference, and contribution instructions.

Where it fits