Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

wasm-pack

rustwasm112.4kMIT OR Apache-2.00.13.1

๐Ÿ“ฆโœจ your favorite rust -> wasm workflow tool!

wasm, rust-wasm, registry, cli, rust, npm, package

readme

๐Ÿ“ฆโœจ wasm-pack

Your favorite Rust โ†’ Wasm workflow tool!

Build Status crates.io

Docs | Contributing | Chat

Built with ๐Ÿฆ€๐Ÿ•ธ by The Rust and WebAssembly Working Group

About

This tool seeks to be a one-stop shop for building and working with rust- generated WebAssembly that you would like to interop with JavaScript, in the browser or with Node.js. wasm-pack helps you build rust-generated WebAssembly packages that you could publish to the npm registry, or otherwise use alongside any javascript packages in workflows that you already use, such as webpack.

This project is a part of the rust-wasm group. You can find more info by visiting that repo!

demo

๐Ÿ”ฎ Prerequisites

This project requires Rust 1.30.0 or later.

โšก Quickstart Guide

Visit the quickstart guide in our documentation.

๐ŸŽ™๏ธ Commands

  • new: Generate a new RustWasm project using a template
  • build: Generate an npm wasm pkg from a rustwasm crate
  • test: Run browser tests
  • pack and publish: Create a tarball of your rustwasm pkg and/or publish to a registry

๐Ÿ“ Logging

wasm-pack uses env_logger to produce logs when wasm-pack runs.

To configure your log level, use the RUST_LOG environment variable. For example:

RUST_LOG=info wasm-pack build

๐Ÿ‘ฏ Contributing

Read our guide on getting up and running for developing wasm-pack, and check out our contribution policy.

๐Ÿคนโ€โ™€๏ธ Governance

This project is part of the rustwasm Working Group.

This project was started by ashleygwilliams and is maintained by drager and the Rust Wasm Working Group Core Team.

changelog

Changelog

๐Ÿค Unreleased

โ˜€๏ธ 0.13.1

  • โœจ Features

    • Requests using proxy settings from env - [jjyr], [pull/1438]

      This enables ureq to use proxy settings from env, it solves lots of pain in network restricted environments.

    [pull/1438]: https://github.com/rustwasm/wasm-pack/pull/1438 [jjyr]: https://github.com/jjyr

  • ๐Ÿค• Fixes

    • Update binary-install to v0.4.1 - [drager], [pull/1407]

      Release v0.4.0 of binary-install introduced a regression that caused failures on some platforms. This release fixes that regression.

    [pull/1407]: https://github.com/rustwasm/wasm-pack/pull/1407 [drager]: https://github.com/drager

    • ** Allow npm binary upgrades - [net], [pull/1439]**

      Fixes an issue where upgrading wasm-pack via NPM would not update the underlying binary. Previously, the binary was stored in the binary-install package's directory without versioning, causing version upgrades to silently fail as the old binary continued to be used. The binary is now stored in node_modules/wasm-pack/binary/, ensuring proper version updates when upgrading the package.

      Before: Upgrading from 0.12.1 to 0.13.0 would continue using the 0.12.1 binary After: Each wasm-pack version manages its own binary, enabling proper version upgrades

    [pull/1439]: https://github.com/rustwasm/wasm-pack/pull/1439 [net]: https://github.com/net

  • ๐Ÿ› ๏ธ Maintenance

    • ** Remove unmaintained dependency atty in favor of stdlib - [mariusvniekerk], [pull/1436]**

    [pull/1436]: https://github.com/rustwasm/wasm-pack/pull/1436 [mariusvniekerk]: https://github.com/mariusvniekerk

โ˜€๏ธ 0.13.0

[issue/1395]: https://github.com/rustwasm/wasm-pack/issues/1395
[pull/1396]: https://github.com/rustwasm/wasm-pack/pull/1396
[ahaoboy]: https://github.com/ahaoboy

โ˜€๏ธ 0.12.1

โ˜€๏ธ 0.12.0

๐ŸŒฆ๏ธ 0.11.1

๐ŸŒฆ๏ธ 0.11.0

๐ŸŒฆ๏ธ 0.10.3

๐ŸŒฆ๏ธ 0.10.2

๐ŸŒฆ๏ธ 0.10.1

๐ŸŒฆ๏ธ 0.10.0

โ˜๏ธ 0.9.1

๐ŸŒฅ๏ธ 0.9.0

๐Ÿ› ๏ธ 0.8.1

  • ๐Ÿค• Fixes

    • Check for "rustup" rather than ".rustup" when checking for wasm32 - [drager], [issue/613][pull/616]

      When we introduced support for non-rustup setups we did a check if the user was using rustup or not. However, this check was too constrained and only covered the most common cases, but it did not work for Docker setups.

      This PR addresses that and it now covers Docker setups as well! When doing this fix we also found two other small issues which this PR also addresses. The first is that we did not print the helpful error message when the wasm32 target was not found and the other one was that it linked to the wrong section of the documentation.

      [issue/613]: https://github.com/rustwasm/wasm-pack/issues/613 [pull/616]: https://github.com/rustwasm/wasm-pack/pull/616

๐ŸŒค๏ธ 0.8.0

  • โœจ Features

    • Give user's ability to customize generated filenames with --out-name flag - [ibaryshnikov], [issue/596] [pull/599]

      When running wasm-pack build, several files are generated. These files are named based on the name of the crate, as per your Cargo.toml file. Sometimes- that's not the name you'd like your files to have!

      You can now specify a custom name for the generated files using a new flag, --out-name. Given a project called dom, here's a comparison of the default and custom generated filenames:

        wasm-pack build
        # will produce files
        # dom.d.ts  dom.js  dom_bg.d.ts  dom_bg.wasm  package.json  README.md
      
         wasm-pack build --out-name index
        # will produce files
        # index.d.ts  index.js  index_bg.d.ts  index_bg.wasm  package.json  README.md

      [ibaryshnikov]: https://github.com/ibaryshnikov [issue/596]: https://github.com/rustwasm/wasm-pack/issues/596 [pull/599]: https://github.com/rustwasm/wasm-pack/pull/599

  • ๐Ÿค• Fixes

    • Fix panics in build mode --no-install - [alexcrichton], [pull/598]

      This commit fixes the wasm-pack build --mode no-install command from unconditionally panicking as well as --mode force. These steps were calling an unwrap() on an internal Option<T> which was supposed to be set during step_install_wasm_bindgen, but that step wasn't run in these modes. The mode configuration of steps has been refactored slightly to ensure that more steps are shared between these modes to reduce duplication.

      [pull/598]: https://github.com/rustwasm/wasm-pack/pull/598

    • Print unexpected panics to standard error - [drager], [issue/562] [pull/601]

      Unexpected panics are unfortunate but they're currently covered up and written out to an auxiliary file. This makes panics in CI difficult to debug, especially at a glance, as CI builders are likely not uploading those files.

      This PR will print to standard error for unexpected panics and then let human_panic handle panics, just like before.

      [issue/562]: https://github.com/rustwasm/wasm-pack/issues/562 [pull/601]: https://github.com/rustwasm/wasm-pack/pull/601

    • Improve error message when wasm32-unknown-unknown is missing - [drager], [issue/579] [pull/602]

      For folks with non-rustup environments (which we only started supporting in 0.7.0!), we were giving a missing target error that was not helpful!

      We've updated the error message to include more information, and we've added some documentation to help explain how you can remedy the error by manually installing the target on your specific rust setup- including the fact that it may not be possible to add the target to some setups.

      Check out the docs here.

      [issue/579]: https://github.com/rustwasm/wasm-pack/issues/579 [pull/602]: https://github.com/rustwasm/wasm-pack/pull/602

  • ๐Ÿ“– Documentation

  • ๐Ÿ› ๏ธ Maintenance

    • Move binary-install to its own repo - [drager], [issue/500] [pull/600]

      binary-install is a crate that holds the abstractions for how wasm-pack downloads and caches pre-built binaries for the tools it wraps. It was originally part of the wasm-pack code, then moved into a workspace as an independent crate. Now that we believe it's stable, we've moved it into its own repo!

      [issue/500]: https://github.com/rustwasm/wasm-pack/issues/500 [pull/600]: https://github.com/rustwasm/wasm-pack/pull/600

๐ŸŒค๏ธ 0.7.0

  • โœจ Features

    • Non rustup environment support - [drager], [pull/552]

      Before now, wasm-pack had a hard requirement that rustup had to be in the PATH. While most Rust users use rustup there are variety reasons to have an environment that doesn't use rustup. With this PR, we'll now support folks who are using a non-rustup environment!

    [pull/552]: https://github.com/rustwasm/wasm-pack/pull/552

    • Improved CLI Output - [alexcrichton], [pull/547]

      It's hard to decide if this is a fix or a feature, but let's keep it positive! This PR moves wasm-pack's CLI output strategy closer to the desired standard we have for 1.0. This is important as it fixes many small bugs that are distributed across a diveristy of terminals and difficult to test for locally.

      This strategy was first introduced as a mini RFC in [issue/298], and then was discussed in a session at the Rust All Hands (notes).

      You'll notice that the spinner is gone- we eventually want to have one, but we'd like one that doesn't cause bugs! If you have feedback about terminal support or an output bug, please [file an issue]! We want to hear from you!

      Check out the new output in the README demo- or update your wasm-pack and take it for a spin!

    [file an issue]: https://github.com/rustwasm/wasm-pack/issues/new/choose [pull/547]: https://github.com/rustwasm/wasm-pack/pull/547 [issue/298]: https://github.com/rustwasm/wasm-pack/issues/298

    • Add support for --target web - [alexcrichton], [pull/567]

      Recently, wasm-bindgen add a new target- web. This new target is similar to the no-modules target, in that it is designed to generate code that should be loaded directly in a browser, without the need of a bundler. As opposed to the no-modules target, which produces an IIFE (Immediately Invoked Function Expression), this target produces code that is an ES6 module.

      You can use this target by running:

      wasm-pack build --target web

      Learn more about how to use this target by checking out the docs!

    [pull/567]: https://github.com/rustwasm/wasm-pack/pull/567

    • Support passing arbitrary arguments to cargo test via wasm-pack test - [chinedufn], [issue/525] [pull/530]

      wasm-pack test is an awesome command that wraps cargo test in a way that helps provide you some nice out of the box configuration and setup. However, you may find yourself wanting to leverage the full funcationality of cargo test by passing arguments that haven't been re-exported by the wasm-pack test interface.

      For example, if you have a large test suite, it can be nice to simply run one test, or a subset of your tests. cargo test supports this, however up until now, the wasm-pack test interface did not!

      wasm-pack test now accepts passing and arbitrary set of arguments that it will forward along to its cargo test call by allowing users to use -- after any wasm-pack test arguments, followed by the set of arguments you'd like to pass to cargo test.

      For example:

      # Anything after `--` gets passed to the `cargo test`
      wasm-pack test --firefox --headless -- --package my-workspace-crate my_test_name --color=always

      This will just run the my_test_name test and will output using color!

      See the test docs here!

    [chinedufn]: https://github.com/chinedufn [issue/525]: https://github.com/rustwasm/wasm-pack/issues/525 [pull/530]: https://github.com/rustwasm/wasm-pack/pull/530

    • Support homepage field of Cargo.toml and package.json - [rhysd], [pull/531]

      Both Cargo.toml and package.json support a homepage field that allow you to specify a website for your project. We didn't support it previously (purely an accidental omission) - but now we do!

    [pull/531]: https://github.com/rustwasm/wasm-pack/pull/531

    • Support license-file field in Cargo.toml - [rhysd], [pull/527]

      Sometimes, you want to provide a custom license, or specific license file that doesn't map to SPDX standard licenses. In Rust/Cargo, you accomplish this by omitting the license field and including a license-file field instead. You can read more about this in the [cargo manifest documentation].

      In an npm package, this translates to "license": "SEE LICENSE IN <filename>" in your package.json. You can read more about this in the [npm package.json documentation].

      We previously only supported using SPDX standard licenses, by only supporting the "license" key in your Cargo.toml- but now we'll allow you to leverage the license-file key as well, and will translate it correctly into your package.json!

    [cargo manifest documentation]: https://doc.rust-lang.org/cargo/reference/manifest.html [npm package.json documentation]: https://docs.npmjs.com/files/package.json#license [rhysd]: https://github.com/rhysd [pull/527]: https://github.com/rustwasm/wasm-pack/pull/527

  • ๐Ÿค• Fixes

    • wasm-pack-init (1).exe should work - ashleygwilliams, [issue/518] [pull/550]

      Several users noted that when downloading a new version of wasm-pack their browser named the executable file wasm-pack-init (1).exe. When named this way, the file didn't show the init instructions on execution. This happened because the installation logic was requiring an exact match on filename. We've loosened that restriction so that the filename must start with wasm-pack-init and will still execute files with these additional, extraneous charaters in the filename. Thanks so much to [Mblkolo] and [danwilhelm] for filing the issue and the excellent discussion!

    [issue/518]: https://github.com/rustwasm/wasm-pack/issues/518 [pull/550]: https://github.com/rustwasm/wasm-pack/pull/550 [Mblkolo]: https://github.com/Mblkolo

    • Fix chromedriver error and message on Windows for wasm-pack test - [jscheffner], [issue/535] [pull/537]

      When running wasm-pack test on a 64-bit Windows machine, users would receive an error: geckodriver binaries are unavailable for this target. This error message had two issues- firstly, it accidentally said "geckodriver" instead of "chromedriver", secondly, it threw an error instead of using the available 32-bit chromedriver distribution. Chromedriver does not do a specific disribution for Windows 64-bit!

      We've fixed the error message and have also ensured that 64-bit Windows users won't encounter an error, and will appropriately fallback to the 32-bit Windows chromedriver.

    [jscheffner]: https://github.com/jscheffner [issue/535]: https://github.com/rustwasm/wasm-pack/issues/535 [pull/537]: https://github.com/rustwasm/wasm-pack/pull/537

    • Correct look up location for wasm-bindgen when it's installed via cargo install - [fitzgen], [pull/504]

      Sometimes, when a wasm-bindgen binary is not available, or if wasm-pack is being run on an architecture that wasm-bindgen doesn't produce binaries for, instead of downloading a pre-built binary, wasm-pack will install wasm-bindgen using cargo install. This is a great and flexible back up!

      However, due to the last release's recent refactor to use a global cache, we overlooked the cargo install case and did not look for wasm-bindgen in the appropriate location. As a result, this led to a bug where wasm-pack would panic.

      We've fixed the lookup for the cargo install'd wasm-bindgen by moving the cargo-install'd version to global cache location for wasm-pack once it's successfully built. We also eliminated the panic in favor of propagating an error. Thanks for your bug reports and sorry about the mistake!

    [pull/504]: https://github.com/rustwasm/wasm-pack/pull/504

    • Only print cargo test output the once - [fitzgen], [issue/511] [pull/521]

      Due to some technical debt and churn in the part of the codebase that handles output, we were accidentally printing the output of cargo test twice. Now we ensure that we print it only one time!

    [issue/511]: https://github.com/rustwasm/wasm-pack/issues/511 [pull/521]: https://github.com/rustwasm/wasm-pack/pull/521

  • ๐Ÿ› ๏ธ Maintenance

    • Fix clippy warnings - [mstallmo], [issue/477] [pull/478]

      [clippy] is an awesome utilty that helps lint your Rust code for common optimizations and idioms. at the beginning of wasm-pack development, clippy had not yet stablized, but it has since 1.0'd and it was high time we leveraged it in wasm-pack. We still aren't completely fixed, but we're working on it, and we've already dervived a ton of value from the tool!

    [clippy]: https://github.com/rust-lang/rust-clippy [issue/477]: https://github.com/rustwasm/wasm-pack/issues/477 [pull/478]: https://github.com/rustwasm/wasm-pack/pull/478

    • Run clippy check on Travis - [drager], [pull/502]

      Now that wasm-pack has been clippified- we want to keep it that way! Now in addition to cargo fmt and cargo test, we'll also run cargo clippy on all incoming PRs!

    [pull/502]: https://github.com/rustwasm/wasm-pack/pull/502

    • Port tests to use assert-cmd - [fitzgen], [pull/522]

      [assert_cmd] is a great utility for testing CLI applications that is supported by the [CLI WG]. wasm-pack development began before this library existed- so we were using a much less pleasant and efficient strategy to test the CLI functionality of wasm-pack. Now we've ported over to using this great library!

    [CLI WG]: https://www.rust-lang.org/what/cli [assert_cmd]: https://crates.io/crates/assert_cmd [pull/522]: https://github.com/rustwasm/wasm-pack/pull/522

    • Add initial tests for binary-install crate - [drager], [pull/517]

      In the last release, we separated some of our binary install logic into a new crate, binary-install. However, that's about all we did... move the logic! In an effort to move the crate into true open source status, [drager] has done some excellent work adding tests to the crate. This was trickier than it looked and involved creating a test server! Thanks for all the efforts [drager], and the great review work [fitzgen] and [lfairy]!

    [pull/517]: https://github.com/rustwasm/wasm-pack/pull/517 [lfairy]: https://github.com/lfairy

    • Update tests wasm-bindgen version - [huangjj27], [issue/519] [issue/417] [pull/526]

      Our tests use fixtures that reference wasm-bindgen often, but the versions were not consistent or up to date. As a result, the test suite leverage many version of wasm-bindgen which meant that they took a while to run as they couldn't use the cached version of wasm-bindgen because the cached versions we slightly different! Now they are up to date and consistent so the tests can perform better!

    [pull/526]: https://github.com/rustwasm/wasm-pack/pull/526 [issue/519]: https://github.com/rustwasm/wasm-pack/issues/519 [issue/417]: https://github.com/rustwasm/wasm-pack/issues/417

  • ๐Ÿ“– Documentation

    • Flag gh-pages docs as unpublished - [alexcrichton] [pull/565]

      Recently, [DebugSteven] made a PR to merge all the documentation for the rustwasm toolchain into a [single location]. This is going to make discovering and using tools from the entire organization easier for new and seasoned folks alike. This also has the feature of displaying documentation that is related to the current published version of each tool- unlike before, where the only accessible documentation was for the tools at current master (which may or may not be currently published!)

      If you like reading the current master's documentation- fear not, each tool will still publish the documentation generated from the master branch on their individual gh-pages ([See wasm-pack's master docs here]). To avoid confusion, we've added a flash message that let's you know which documentation you are reading- and provides a link to documentation of the published version- just in case that's what you're looking for!

    [DebugSteve]: https://github.com/DebugSteven [single location]: https://rustwasm.github.io/docs.html [See wasm-pack's master docs here]: https://rustwasm.github.io/wasm-pack/book/ [pull/565]: https://github.com/rustwasm/wasm-pack/pull/565

    • Add new QuickStart guide for "Hybrid Applications with Webpack" - [DebugSteven] [pull/536]

      Since wasm-pack was first published, we've focused on a workflow where a user writes a library and then publishes it to npm, where anyone can use it like any npm package in their JavaScript or Node.js application.

      Shortly after wasm-pack appeared, some RustWASM teammates created a template for a similar workflow- building a RustWASM package alongside an application. They did this by leveraging Webpack plugins, and it's a really lovely user experience!

      [This template] hasn't gotten as much attention because we've lacked a quickstart guide for folks to discover and follow- now we've got one!

      Check out the guide here!

    [This temaplte]: https://github.com/rustwasm/rust-webpack-template [DebugSteven]: https://github.com/DebugSteven [pull/536]: https://github.com/rustwasm/wasm-pack/pull/536

    • Add wee_alloc deepdive - [surma], [pull/542]

      wee_alloc is a useful utility that deserved more attention and explanation than our previous docs addressed. This was partially because the wasm-pack template has an explanatory comment that helps explain its use. However, for folks who don't use the template, wee_alloc is something important to know about- so now we have given it its own section!

      Check out the deepdive here!

    [surma]: https://github.com/surma [pull/542]: https://github.com/rustwasm/wasm-pack/pull/542

    • Update prerequisite documentation - [alexcrichton], [pull/569]

      Many folks are using wasm-pack without publishing to npm- as a result, we've updated the documentation to clearly indicate that npm is an optional requirement, only required for specific targets and workflows. Additionally, since the 2018 Edition landed, nightly Rust is no longer a requirement. We've removed those instructions and have consolidated the documentation so it is shorter and more efficient at getting you started!

    [pull/569]: https://github.com/rustwasm/wasm-pack/pull/569

    • Clarify what kind of account login adds - [killercup], [pull/539]

      Previously, when view --help, the command description for login showed: ๐Ÿ‘ค Add a registry user account! This could be confusing for folks, so now it's been updated to read: ๐Ÿ‘ค Add an npm registry user account!, which is much clearer!

    [killercup]: https://github.com/killercup [pull/539]: https://github.com/rustwasm/wasm-pack/pull/539

    • Wasm is a contraction, not an acronym - [fitzgen], [pull/555]

      Ever wonder how you're actually supposed to refer to WebAssembly in short-form? WASM? wasm? For the pedants out there, the correct usage is "Wasm" because Wasm is a contraction of the words Web and Assembly. We've updated our doucmentation to consistently refer to WebAssembly as Wasm in the shortform.

      The more you know!

    [pull/555]: https://github.com/rustwasm/wasm-pack/pull/555

    • Fix links and Rust highlightning - [drager], [issue/513] [pull/514] [pull/516]

      We had some broken links and missing Rust syntax highlighting in a few sections of the docs. This fixes that!

    [issue/513]: https://github.com/rustwasm/wasm-pack/issues/513 [pull/514]: https://github.com/rustwasm/wasm-pack/pull/514 [pull/516]: https://github.com/rustwasm/wasm-pack/pull/516

๐ŸŒ… 0.6.0

  • โœจ Features

    • Add three build profiles and infrastructure for their toml config - [fitzgen], [issue/153] [issue/160] [pull/440]

      When originally conceived, wasm-pack was exclusively a packaging and publishing tool, which naively assumed that the crate author would simply run wasm-pack when they were ready to publish a wasm package. As a result, wasm-pack always ran cargo build in --release mode. Since then, wasm-pack has grown into an integrated build tool used at all stages of development, from idea conception to publishing, and as such has developed new needs.

      In previous releases, we've supported a flag called --debug which will run cargo build in dev mode, which trades faster compilation speed for a lack of optimizations. We've renamed this flag to --dev to match cargo and added an additional flag, representing a third, intermediary, build profile, called --profiling which is useful for investigating performance issues. You can see all three flags and their uses in the table below:

      | Profile | Debug Assertions | Debug Info | Optimizations | Notes | |---------------|------------------|------------|---------------|---------------------------------------| | --dev | Yes | Yes | No | Useful for development and debugging. | | --profiling | No | Yes | Yes | Useful when profiling and investigating performance issues. | | --release | No | No | Yes | Useful for shipping to production. |

      The meaning of these flags will evolve as the platform grows, and always be tied to the behavior of these flags in cargo. You can learn more about these in the [cargo profile documentation].

      This PR also introduces a way to configure wasm-pack in your Cargo.toml file that we intend to use much more in the future. As a largely convention-based tool, wasm-pack will never require that you configure it manually, however, as our community and their projects mature alongside the tool, it became clear that allowing folks the ability to drop down and configure things was something we needed to do to meet their needs.

      Currently, you can only configure things related to the above-mentioned build profiles. To learn more, [check out the documentation][profile-config-docs]. It leverages the package.metadata.wasm-pack key in your Cargo.toml, and looks like this:

      # Cargo.toml
      
      [package.metadata.wasm-pack.profile.dev.wasm-bindgen]
      # Should we enable wasm-bindgen's debug assertions in its generated JS glue?
      debug-js-glue = true
      # Should wasm-bindgen demangle the symbols in the "name" custom section?
      demangle-name-section = true
      # Should we emit the DWARF debug info custom sections?
      dwarf-debug-info = false

      As always- there are defaults for you to use, but if you love to configure (or have a project that requires it), get excited, as your options have grown now and will continue to!

    [profile-config-docs]: https://rustwasm.github.io/wasm-pack/book/cargo-toml-configuration.html [cargo profile documentation]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-profile-sections [issue/153]: https://github.com/rustwasm/wasm-pack/issues/153 [issue/160]: https://github.com/rustwasm/wasm-pack/issues/160 [pull/440]: https://github.com/rustwasm/wasm-pack/pull/440

    • DEPRECATION: Rename --debug to --dev to match cargo - [fitzgen], [pull/439]

      See the discussion of the build profiles feature above. This is a strict renaming of the previous --debug flag, which will now warn as deprecated.

    [pull/439]: https://github.com/rustwasm/wasm-pack/pull/439

    • Add an option to pass an arbitrary set of arguments to cargo build - [torkve], [issue/455] [pull/461]

      As an integrated build tool, wasm-pack orchestrates many secondary command line tools to build your package in a single command. Notably, one of these tools is cargo. cargo has a wide array of features and flags, and we couldn't reasonably expect to implement them all as first class features of wasm-pack. As a result, we've created the option to allow users to pass an arbitrary number of additional flags to wasm-pack by appending them to the wasm-pack build command, after passing --. For example:

      wasm-pack build examples/js-hello-world --mode no-install -- -Z offline

      In the above example, the flag -Z offline will be passed to cargo build. This feature is documented [here][cargo opts docs].

    [cargo opts docs]: https://rustwasm.github.io/wasm-pack/book/commands/build.html#extra-options [torkve]: https://github.com/torkve [issue/455]: https://github.com/rustwasm/wasm-pack/issues/455 [pull/461]: https://github.com/rustwasm/wasm-pack/pull/461

  • Pre-build before wasm-pack publish - [csmoe], [issue/438] [pull/444]

    Previously, if you ran wasm-pack publish before you had successfully run wasm-pack build, you'd receive an error that a package could not be found- because there would be no pkg or out-directory containing a package.json.

    In this situation, you would hope that wasm-pack would build your package for you when you ran wasm-pack publish. This is slightly complicated by the fact that not everyone wants to build their package to the default target or to a directory named pkg.

    To solve this, running wasm-pack publish before a successful build will give you an interactive prompt to build your package- allowing you to specify your out directory as well as the target you'd like to build to. Check it out in the gif below:

    pre-build publish workflow

    [issue/438]: https://github.com/rustwasm/wasm-pack/issues/438 [pull/444]: https://github.com/rustwasm/wasm-pack/pull/444

  • Generate self-.gitignore as part of pkg folder - [RReverser], [pull/453]

    Since wasm-pack was first published, the pkg directory was intended to be treated as a build artifact, and as such should never be published to version control. This was never enforced by any assets generated by wasm-pack, however.

    Now, when building your package, wasm-pack will also generate a .gitignore file so that the pkg, or out-directory, will be ignored.

    If you use another version control tool, you'll need to still create or edit your own ignore file- pull requests to support other version control tools are welcome!

    If you require editing of the generated package.json or add additonal assets to your package before publishing, you'll want to remove the .gitignore file and commit to version control. We intend to have a solution that makes this workflow significantly easier in upcoming releases!

    [RReverser]: https://github.com/RReverser [pull/453]: https://github.com/rustwasm/wasm-pack/pull/453

  • Support cargo workspaces - [fitzgen], [issue/252] [issue/305] [pull/430]

    Workspaces are a well-liked and used feature of cargo that allow you to build multiple crates in a single cargo project. Because of how wasm-pack handled paths for target and out-directories, we did not support cargo workspaces out of the box. Now they should work well and the feature is well guarded by tests!

    [issue/252]: https://github.com/rustwasm/wasm-pack/issues/252 [issue/305]: https://github.com/rustwasm/wasm-pack/issues/305 [pull/430]: https://github.com/rustwasm/wasm-pack/pull/430

  • Use a global cache for all downloaded binaries - [alexcrichton], [pull/426]

    wasm-pack is an integrated build tool that orchestrates several other command line tools to build your wasm project for you. How wasm-pack does this has evolved significantly since it's early versions. In the last version, a bin directory was created to house the tool binaries that wasm-pack needed to build our project, but this had several limitations. Firstly, it created a bin directory in your project's root, which could be confusing. Secondly, it meant that sharing these tools across multiple projects was not possible. We did this because it gaves us the fine-grained control over the version of these tools that you used.

    Now, wasm-pack will not generate a bin directory, but rather will use a global cache. We retain the fine-grained control over the versions of these tools that are used, but allow multiple projects that use the same tools at the same versions to share the already installed asset. Your global cache will generally be in your user's home directory- we use the [dirs crate] to determine where to place this global cache. This is not currently customizable but is something we intend to look into doing!

    This feature ensures that wasm-pack users are downloading a minimal number of binaries from the network, which, for wasm-pack users with multiple projects, should speed up build times.

    [dirs crate]: https://docs.rs/dirs/1.0.4/dirs/fn.cache_dir.html [pull/426]: https://github.com/rustwasm/wasm-pack/pull/426

๐ŸŒ„ 0.5.1

โ˜€๏ธ 0.5.0

  • โœจ Features

    • Website! - ashleygwilliams, [pull/246]

      We have a website now. It has the installer and links to documentation. In the future, we hope to have calls to action for folks first coming to the site who are looking to do specific things- these will help them find the docs and tutorials they need to.

      This PR also has a complete rework of our documentation.

      Check it out here!

    • ๐Ÿฑ Module Support

      • BREAKING: use correct package.json keys for generated JavaScript - ashleygwilliams, [issue/309] [pull/312]

        This is marked as potentially breaking because it changes the package.json keys that are generated by the project.

        Previously, we generated a JavaScript file and placed it in the main key, regardless of what you were targeting, ES6 and Node.js alike.

        We have received a lot of requests for wasm-pack to generate "isomorphic" packages, that contain assets that could work on both Node.js and ES6, and this led to us looking more closely at how we are using package.json.

        With this release, we will do the following:

        • --target browser: By default, we generate JS that is an ES6 module. We used to put this in the main field. Now we put it in the module field. We also add sideEffects: false so that bundlers that want to tree shake can.

        • --target nodejs: This target doesn't change. We put generated JS that is a CommonJS module in the main key.

        • --target no-modules: This is a new target. For this target we generate bare JavaScript. This code is put in a browser field.

        You can see the structs that represent each target's expected package.json here.

        Thanks so much to [bterlson] for his help in sorting this out for us!

      [bterlson]: https://github.com/bterlson [issue/309]: https://github.com/rustwasm/wasm-pack/issues/309 [pull/312]: https://github.com/rustwasm/wasm-pack/pull/312

    • ๐Ÿ› ๏ธ New Commands

      • wasm-pack init is now wasm-pack build - [csmoe], [issue/188] [pull/216]

        When this project was first conceived, we imagined it would be simply a way to package up generate wasm and js and publish it to npm. Here we are at version 0.5.0 and we have become much more- an integrated build tool!

        As a result, the original command init does a lot more than that these days. We've renamed the command to better reflect the work it's actually doing. init will still work, but is deprecated now, and we will eventually remove it.

      [csmoe]: https://github.com/csmoe [issue/188]: https://github.com/rustwasm/wasm-pack/issues/188 [pull/216]: https://github.com/rustwasm/wasm-pack/pull/216

      • add new command: wasm-pack test - [fitzgen], [pull/271]

        This is an experimental new command that will run your tests in Node.js or a headless browser using wasm-pack test. Check out this tutorial to learn more!

      [pull/271]: https://github.com/rustwasm/wasm-pack/pull/271

      • add 2FA support to wasm-pack publish - [mstallmo], [issue/257] [pull/282]

        We've been wrapping the npm login and npm publish commands as wasm-pack login and wasm-pack publish for a while now- but we didn't fully support two factor authentication. Now we do! (Be safe out there! 2FA is good for everyone!)

      [issue/257]: https://github.com/rustwasm/wasm-pack/issues/257 [pull/282]: https://github.com/rustwasm/wasm-pack/pull/282

    • ๐ŸŽ New Flags

      • New target, bare JavaScript: --target no-modules - ashleygwilliams, [issue/317] [pull/327]

        wasm-bindgen offers a no-modules flag that until now, we didn't support. This flag produces bare, no modules JavaScript. So if that's your thing, this target is for you!

      [issue/317]: https://github.com/rustwasm/wasm-pack/issues/317 [pull/327]: https://github.com/rustwasm/wasm-pack/pull/327

      • --access flag for wasm-pack publish - ashleygwilliams, [issue/297] [pull/299]

        Many of our tutorials use scopes to help prevent folks from attempting to publish packages that will lead to npm Registry errors because the package name already exists.

        However, by default, scoped packages are assumed by the npm registry to be private, and the ability to publish private packages to the npm registry is a paid feature. Worry not! Now you can pass --access public to wasm-pack publish and publish scoped packages publicly.

      [issue/297]: https://github.com/rustwasm/wasm-pack/issues/297 [pull/299]: https://github.com/rustwasm/wasm-pack/pull/299

    • โœ… New Checks

      • rustc version check - ashleygwilliams, [issue/351] [pull/353]

        Now that we have a new fangled installer, there's a chance that folks might install wasm-pack and not have Rust installed. Additionally, now that the features we required from the nightly channel of Rust have moved to beta- we don't need to enforce nightly.

        As of this release, we will check that your Rust version is above 1.30.0. You can be on either the nightly or beta channel and all of wasm-packs calls to cargo will respect that.

        Really hate this? You can pass --mode force to wasm-pack to skip this check. I hope you know what you're doing!

      • coordinating wasm-bindgen versions and installing from binaries for improved speed - [datapup], [issue/146] [pull/244] [pull/324]

        This is the true gem of this release. Have you been frustrated by how long wasm-pack takes to run? Overusing --mode no-install? This is the release you're looking for.

        Many releases back we realized that folks were struggling to keep the wasm-bindgen library that their project used in sync with the wasm-bindgen CLI application which wasm-pack runs for you. This became such an issue that we opted to force install wasm-bindgen to ensure that every wasm-pack user had the latest version.

        Like many technical solutions, this solved our original problem, but caused a new one. Now, we we are forcing a cargo install of wasm-bindgen on every run, and that means downloading and compiling wasm-bindgen everytime you want to run wasm-pack. That's unacceptable!

        We're happy to announce that we have a pretty great solution, and several more planned for future releases. As of this release, we will read your Cargo.lock to find the version of wasm-bindgen you are using in your local project. We will attempt to fetch a binary version of wasm-bindgen that matches your local version. We place that binary local to your project, and use it when you run wasm-pack build. The next time you run wasm-pack build we'll use that binary, instead of fetching a new one. We still fall back to cargo install for less common architectures but this is a huge speed improvement. Check out these benchmarks!

        wasm-pack v0.4.2
        $ time wasm-pack init                   # fresh build
        real    1m58.802s
        user    14m49.679s
        sys     0m24.957s
        
        $ time wasm-pack init                   # re-build
        real    0m56.953s
        user    11m12.075s
        sys     0m18.835s
        
        $ time wasm-pack init -m no-install     # re-build with no-install
        real    0m0.091s
        user    0m0.052s
        sys     0m0.042s
        wasm-pack v0.5.0
        $ time wasm-pack build                  # fresh build
        real    1m3.350s
        user    3m46.912s
        sys     0m6.057s
        
        $ time wasm-pack build                  # re-build
        real    0m0.230s
        user    0m0.185s
        sys     0m0.047s
        
        $ time wasm-pack build -m no-install    # re-build with no-install
        real    0m0.104s
        user    0m0.066s
        sys     0m0.041s

      [datapup]: https://github.com/datapup [issue/146]: https://github.com/rustwasm/wasm-pack/issues/146 [pull/244]: https://github.com/rustwasm/wasm-pack/pull/244 [pull/324]: https://github.com/rustwasm/wasm-pack/pull/324

      • enforce cargo build with --lib - ashleygwilliams, [issue/303] [pull/330]

        Right now, wasm-pack only works on Rust library projects. But sometimes, if you're new to Rust, you might end up having a main.rs in your project, just by mistake. Some folks ran into this and realized that it can cause issues!

        As a result, we are enforcing that cargo build only build the library at this time.

        Want to use wasm-pack on a binary application? We're interested in hearing from you! Checkout [issue/326] and please comment! We want to support binary applicaitons in the future and are always happy and curious to hear about how folks use wasm-pack!

      [issue/326]: https://github.com/rustwasm/wasm-pack/issues/326 [issue/303]: https://github.com/rustwasm/wasm-pack/issues/303 [pull/330]: https://github.com/rustwasm/wasm-pack/pull/330

    • Installers and Releases

      • Appveyor Windows Pre-Built binaries - [alexcrichton], [issue/147] [pull/301]

        We finally got Appveyor to publish pre-built binaries to GitHub releases. Aside: I really wish there were an easier way to test and debug this stuff.

      [alexcrichton]: https://github.com/alexcrichton [issue/147]: https://github.com/rustwasm/wasm-pack/issues/147 [pull/301]: https://github.com/rustwasm/wasm-pack/pull/301

      • new experimental installer - [alexcrichton], [pull/307]

        Whew, this one is exciting. Up until now, wasm-pack has been distributed using cargo install. This is not ideal for several reasons. Updating is confusing, and every time it's installed the user has to wait for it to compile- right at the moment they just want to hurry up and use it already.

        Say hello to the new wasm-pack installer- we have an executable for Windows and a curl script for *nix users. Not pleased with that? File an issue for your preferred distribution method and we'll do our best to get it working!

        This is experimental- so please try it out and file issues as you run into things! You'll always be able to use cargo install as a backup.

        Checkout the new installer here!

      [pull/307]: https://github.com/rustwasm/wasm-pack/pull/307

  • ๐Ÿ› ๏ธ Maintenance

  • ๐Ÿ“– Documentation

โœจ 0.4.2

โญ 0.4.1

๐ŸŒŸ 0.4.0

This release has a ton of awesome things in it, but the best thing is that almost all of this awesome work is brought to you by a new contributor to wasm-pack. Welcome ya'll! We're so glad to have you!

โœจ Features

๐Ÿค• Fixes

  • fixed broken progress bar spinner - migerh, pull/164

    Oh no! We broke the progress bar spinner in version 0.3.0. Thankfully, it's fixed now- with a thoughtful refactor that also makes the underlying code sounder overall.

๐Ÿ› ๏ธ Maintenance

  • modularize command.rs - ashleygwilliams, pull/182

    Thanks to the growth of wasm-pack, command.rs was getting pretty long. We've broken it out into per command modules now, to help make it easier to read and maintain!

  • improve PoisonError conversion - migerh, pull/187

    As part of the awesome progress bar spinner fix in pull/164, migerh introduced a small concern with an unwrap due to an outstanding need to convert PoisonError into wasm-pack's custom Error. Though not a critical concern, migerh mitigated this right away by replacing std::sync::RwLock with the parking_lot crate! This cleaned up the code even more than the previous patch!

๐Ÿ“– Documentation

  • cleaned up the README - ashleygwilliams, pull/155

    Our README was struggling with a common problem- doing too much at once. More specifically, it wasn't clear who the audience was, contributers or end users? We've cleaned up our README and created a document specifically to help contributors get up and running.

๐ŸŒ  0.3.1

Babby's first point release! Are we a real project now?

๐Ÿค• Fixes

  • fixed init Is a Directory error - ashleygwilliams, pull/139

    Our new logging feature accidentally introduced a regression into 0.3.0. When calling wasm-pack init, if a directory was not passed, a user would receive a "Is a Directory" Error. Sorry about that! Thanks to jbolila for filing issue/136!

  • typescript files were not included in published package - danreeves, pull/138

    Generating Typescript type files by default was a pretty rad feature in 0.3.0 but we accidentally forgot to ensure they were included in the published package. Thanks so much to danreeves for catching this issue and fixing it for us!

๐Ÿ’ซ 0.3.0

โœจ Features

  • Logging - mgattozzi, pull/134

    Up until now, we've forced folks to rely on emoji-jammed console output to debug errors. While emojis are fun, this is often not the most pleasant experience. Now we'll generate a wasm-pack.log file if wasm-pack errors on you, and you can customize the log verbosity using the (previously unimplemented) verbosity flag.

  • --target flag - djfarly, pull/132

    wasm-bindgen-cli is able to generate a JS module wrapper for generated wasm files for both ES6 modules and CommonJS. Up until now, we only used wasm-bindgen's default behavior, ES6 modules. You can now pass a --target flag with either nodejs or browser to generate the type of module you want to use. Defaults to browser if not passed.

  • human readable panics - yoshuawuyts, pull/118

    Panics aren't always the most friendly situation ever. While we never want to panic on ya, if we do- we'll do it in a way that's a little more readable now.

  • typescript support by default - kwonoj, pull/109

    wasm-bindgen now generates typescript type files by default. To suppress generating the type file you can pass the --no-typescript flag. The type file is useful for more than just typescript folks- many IDEs use it for completion!

  • wrap npm login command - djfarly, pull/100

    In order to publish a package to npm, you need to be logged in. You can now use wasm-pack login to login to the npm (or any other) registry.

  • exit early on failure - mgattozzi, pull/90

    Until now, wasm-pack would continue to run tasks, even if a task failed. Now- if something fails, we'll exit so you don't have to wait to fix the error.

๐Ÿค• Fixes

  • force install wasm-bindgen - ashleygwilliams, pull/133

    Using an out of date version of wasm-bindgen can run you into a bunch of trouble. This very small change should fix the large number of bug reports we received from users using an out of date wasm-bindgen-cli by force installing wasm-bindgen-cli to ensure the user always has the latest version. We don't expect this to be a forever solution (it's a bit slow!) but it should help those who are getting started have a less rough time.

  • fix CI release builds - ashleygwilliams, pull/135

    This was not working! But now it is! You can always use cargo install to install wasm-pack, but now you can find pre-built Linux and Mac binaries in the Releases tab of our GitHub repo.

๐Ÿ› ๏ธ Maintenance

  • remove quicli dependency - mgattozzi, pull/131

    While quicli is a great way to get started writing a CLI app in Rust- it's not meant for large, mature applications. Now that wasm-pack is bigger and has many active users, we've removed this dependency to unblock further development on the tool.

  • update rustfmt CI test - djfarly, pull/128

    Since 0.2.0 how one should call rustfmt changed! We've kept it up to date so we can continue to maintain conventional style in the codebase.

  • custom module for errors - mgattozzi, pull/120

    Thanks to the failure crate, we've been playing fast and loose with errors for a bit. We're finally getting serious about error handling - by organizing all of our specific errors in a specific module. This will make it easier to communicate these errors out and handle new error cases from future features.

๐Ÿ“– Documentation

Special thanks to data-pup who continues to be our documentation champion! In case you missed it, check out the guides in the docs directory!!

๐ŸŒŒ 0.2.0

This release focuses on filling out all commands and improving stderr/out handling for improved user experience!

โœจ Features

  • pack and publish - jamiebuilds, pull/67 You can now run wasm-pack pack to generate a tarball of your generated package, as well as run wasm-pack publish to publish your package to the npm registry. Both commands require that you have npm installed, and the publish command requires that you be logged in to the npm client. We're working on wrapping the npm login command so that you can also login directly from wasm-pack, see pull/100 for more details.
  • package.json is pretty printed now - yoshuawuyts, pull/70

    Previously, package.json was not very human readable. Now it is pretty printed!

  • collaborators - yoshuawuyts, pull/70

    wasm-pack now will fill out the collaborators field in your package.json for you based on your Cargo.toml authors data. For more discussion on how we decided on this v.s. other types of author fields in package.json, see issues/2.

๐Ÿค• Fixes

๐Ÿ› ๏ธ Maintenance and ๐Ÿ“– Documentation

Thanks so much to mgattozzi, data-pup, sendilkumarn, Andy-Bell, steveklabnik, jasondavies, and edsrzf for all the awesome refactoring, documentation, typo-fixing, and testing work. We appreciate it so much!

๐Ÿ’ฅ 0.1.0

  • First release!