Packing and Publishing Using wasm-pack

Learn how to build, pack, and publish Rust applications using wasm-pack.

The most amazing (and, of course, the most important) thing for a library developer to do is to pack and publish artifacts. That’s why we spend our days and nights carefully crafting the application, publishing it to the world, receiving feedback (either positive or negative), and then consequently enhancing the application based on that.

The critical point for any project is its first release, which defines the fate of the project. Even though it’s simply an MVP, it will give the world a glimpse of what we’re working on, and it gives us a glimpse of what we have to work on in the future.

wasm-pack helps us to build, pack, and publish Rust- and WebAssembly-based projects into the npm registry. We’ve already seen how wasm-pack makes it simpler to build Rust into the WebAssembly binary along with the binding JavaScript file using wasm-bindgen underneath. Let’s further explore what we can do with its pack and publish flags.

wasm-pack provides a pack flag to pack the artifacts that were generated using the wasm-pack build command. Although it’s not necessary to use wasm-pack to build binaries, it generates all the boilerplate that we’ll need to pack the artifacts into a Node module.

Packing the bundle

In order to pack the built artifacts using wasm-pack, we have to run the following command with reference to pkg (or the directory with which we generated our build artifacts):

Get hands-on with 1200+ tech skills courses.