Document not found (404)
+This URL is invalid, sorry. Please use the navigation bar or search to continue.
+ +diff --git a/_installer/build-installer.rs b/_installer/build-installer.rs new file mode 100644 index 00000000..9e6ffd1f --- /dev/null +++ b/_installer/build-installer.rs @@ -0,0 +1,30 @@ +use std::fs; + +fn main() { + fs::create_dir_all("docs/installer").unwrap(); + fs::copy( + "docs/_installer/wasm-pack.js", + "docs/installer/wasm-pack.js", + ).unwrap(); + let index = fs::read_to_string("docs/_installer/index.html").unwrap(); + fs::write( + "docs/installer/index.html", + fixup(&index), + ).unwrap(); + + let init = fs::read_to_string("docs/_installer/init.sh").unwrap(); + fs::write( + "docs/installer/init.sh", + fixup(&init), + ).unwrap(); +} + +fn fixup(input: &str) -> String { + let manifest = fs::read_to_string("Cargo.toml").unwrap(); + let version = manifest.lines() + .find(|line| line.starts_with("version =")) + .unwrap(); + let version = &version[version.find('"').unwrap() + 1..version.rfind('"').unwrap()]; + + input.replace("$VERSION", &format!("v{}", version)) +} diff --git a/_installer/index.html b/_installer/index.html new file mode 100644 index 00000000..db6cd467 --- /dev/null +++ b/_installer/index.html @@ -0,0 +1,102 @@ + +
+ +wasm-pack
+ To install from source on any platform: +
+cargo install wasm-pack
+ On supported platforms, you can also use npm or yarn to download a precompiled binary: +
+npm install -g wasm-pack
or yarn global add wasm-pack
+ This is the unpublished documentation of
+ wasm-pack
, the published documentation is available
+
+ on the main Rust and WebAssembly documentation site
+ . Features documented here may not be available in released versions of
+ wasm-pack
.
+
This URL is invalid, sorry. Please use the navigation bar or search to continue.
+ +
+ This is the unpublished documentation of
+ wasm-pack
, the published documentation is available
+
+ on the main Rust and WebAssembly documentation site
+ . Features documented here may not be available in released versions of
+ wasm-pack
.
+
Cargo.toml
Configurationwasm-pack
can be configured via the package.metadata.wasm-pack
key in
+Cargo.toml
. Every option has a default, and is not required.
There are three profiles: dev
, profiling
, and release
. These correspond to
+the --dev
, --profiling
, and --release
flags passed to wasm-pack build
.
The available configuration options and their default values are shown below:
+[package.metadata.wasm-pack.profile.dev]
+# Should `wasm-opt` be used to further optimize the wasm binary generated after
+# the Rust compiler has finished? Using `wasm-opt` can often further decrease
+# binary size or do clever tricks that haven't made their way into LLVM yet.
+#
+# Configuration is set to `false` by default for the dev profile, but it can
+# be set to an array of strings which are explicit arguments to pass to
+# `wasm-opt`. For example `['-Os']` would optimize for size while `['-O4']`
+# would execute very expensive optimizations passes
+wasm-opt = ['-O']
+
+[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
+# Should we omit the default import path?
+omit-default-module-path = false
+
+[package.metadata.wasm-pack.profile.profiling]
+wasm-opt = ['-O']
+
+[package.metadata.wasm-pack.profile.profiling.wasm-bindgen]
+debug-js-glue = false
+demangle-name-section = true
+dwarf-debug-info = false
+omit-default-module-path = false
+
+# `wasm-opt` is on by default in for the release profile, but it can be
+# disabled by setting it to `false`
+[package.metadata.wasm-pack.profile.release]
+wasm-opt = false
+
+[package.metadata.wasm-pack.profile.release.wasm-bindgen]
+debug-js-glue = false
+demangle-name-section = true
+dwarf-debug-info = false
+omit-default-module-path = false
+
+
+
+ This is the unpublished documentation of
+ wasm-pack
, the published documentation is available
+
+ on the main Rust and WebAssembly documentation site
+ . Features documented here may not be available in released versions of
+ wasm-pack
.
+
The wasm-pack build
command creates the files necessary for JavaScript
+interoperability and for publishing a package to npm. This involves compiling
+your code to wasm and generating a pkg folder. This pkg folder will contain the
+wasm binary, a JS wrapper file, your README
, and a package.json
file.
The pkg
directory is automatically .gitignore
d by default, since it contains
+build artifacts which are not intended to be checked into version
+control.0
The wasm-pack build
command can be given an optional path argument, e.g.:
wasm-pack build examples/js-hello-world
+
+This path should point to a directory that contains a Cargo.toml
file. If no
+path is given, the build
command will run in the current directory.
By default, wasm-pack
will generate a directory for its build output called pkg
.
+If you'd like to customize this you can use the --out-dir
flag.
wasm-pack build --out-dir out
+
+The above command will put your build artifacts in a directory called out
, instead
+of the default pkg
.
Flag --out-name
sets the prefix for output file names. If not provided, package name is used instead.
Usage examples, assuming our crate is named dom
:
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
+
+The build
command accepts an optional profile argument: one of --dev
,
+--profiling
, or --release
. If none is supplied, then --release
is used.
This controls whether debug assertions are enabled, debug info is generated, and +which (if any) optimizations are enabled.
+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 --dev
profile will build the output package using cargo's default
+non-release profile. Building this way is
+faster but applies few optimizations to the output, and enables debug assertions
+and other runtime correctness checks. The --profiling
and --release
profiles
+use cargo's release profile, but the former enables debug info as well, which
+helps when investigating performance issues in a profiler.
The exact meaning of the profile flags may evolve as the platform matures.
+The build
command accepts a --target
argument. This will customize the JS
+that is emitted and how the WebAssembly files are instantiated and loaded. For
+more documentation on the various strategies here, see the documentation on
+using the compiled output.
wasm-pack build --target nodejs
+
+Option | Usage | Description |
---|---|---|
not specified or bundler | Bundler | Outputs JS that is suitable for interoperation with a Bundler like Webpack. You'll import the JS and the module key is specified in package.json . sideEffects: false is by default. |
nodejs | Node.js | Outputs JS that uses CommonJS modules, for use with a require statement. main key in package.json . |
web | Native in browser | Outputs JS that can be natively imported as an ES module in a browser, but the WebAssembly must be manually instantiated and loaded. |
no-modules | Native in browser | Same as web , except the JS is included on a page and modifies global state, and doesn't support as many wasm-bindgen features as web |
The build
command also accepts an optional --scope
argument. This will scope
+your package name, which is useful if your package name might conflict with
+something in the public registry. For example:
wasm-pack build examples/js-hello-world --scope test
+
+This command would create a package.json
file for a package called
+@test/js-hello-world
. For more information about scoping, you can refer to
+the npm documentation here.
The build
command accepts an optional --mode
argument.
wasm-pack build examples/js-hello-world --mode no-install
+
+Option | Description |
---|---|
no-install | wasm-pack build implicitly and create wasm binding without installing wasm-bindgen . |
normal | do all the stuffs of no-install with installed wasm-bindgen . |
The build
command can pass extra options straight to cargo build
even if
+they are not supported in wasm-pack. To use them simply add the extra arguments
+at the very end of your command, just as you would for cargo build
. For
+example, to build the previous example using cargo's offline feature:
wasm-pack build examples/js-hello-world --mode no-install -- --offline
+
+0 If you need to include additional assets in the pkg +directory and your NPM package, we intend to have a solution for your use case +soon. ↩
+ +
+ This is the unpublished documentation of
+ wasm-pack
, the published documentation is available
+
+ on the main Rust and WebAssembly documentation site
+ . Features documented here may not be available in released versions of
+ wasm-pack
.
+
wasm-pack
has several commands to help you during the process of building
+a Rust-generated WebAssembly project.
new
: This command generates a new project for you using a template. Learn morebuild
: This command builds a pkg
directory for you with compiled wasm and generated JS. Learn morepack
and publish
: These commands will create a tarball, and optionally publish it to a registry, such as npm. Learn moreinit
: This command has been deprecated in favor of build
.By default wasm-pack
displays a lot of useful information.
You can cause it to display even more information by using --verbose
, or you can silence all stdout by using --quiet
.
You can also use --log-level
to have fine-grained control over wasm-pack's log output:
--log-level info
is the default, it causes all messages to be logged.--log-level warn
causes warnings and errors to be displayed, but not info.--log-level error
causes only errors to be displayed.These flags are global flags, so they can be used with every command, and they must come before the command:
+wasm-pack --log-level error build
+wasm-pack --quiet build
+wasm-pack --verbose build
+
+
+
+ This is the unpublished documentation of
+ wasm-pack
, the published documentation is available
+
+ on the main Rust and WebAssembly documentation site
+ . Features documented here may not be available in released versions of
+ wasm-pack
.
+
This command has been deprecated in favor of build
, which does the same thing, but is
+a much more representative name for the command. Read the docs for build
.
+ This is the unpublished documentation of
+ wasm-pack
, the published documentation is available
+
+ on the main Rust and WebAssembly documentation site
+ . Features documented here may not be available in released versions of
+ wasm-pack
.
+
The wasm-pack new
command creates a new RustWasm project for you,
+using cargo-generate
under the hood.
It takes 3 parameters, name, template, and mode:
+wasm-pack new <name> --template <template> --mode <normal|noinstall|force>
+
+The default template is rustwasm/wasm-pack-template
.
The wasm-pack new
command must be given a name argument, e.g.:
wasm-pack new myproject
+
+The wasm-pack new
command can be given an optional template argument, e.g.:
wasm-pack new myproject --template https://github.com/rustwasm/wasm-pack-template
+
+The template can be an address to a git repo that contains a cargo-generate
+template.
The wasm-pack new
command can be given an optional mode argument, e.g.:
wasm-pack new myproject --mode noinstall
+
+The mode passed can be either "normal", "noinstall", or "force". "normal" is passed by +default.
+noinstall
means that wasm-pack should not attempt to install any underlying tools.
+If a necessary tool cannot be found, the command will error.
force
means that wasm-pack should not check the local Rust version. If a local Rust
+is an unacceptable Rust version, the command will error.
+ This is the unpublished documentation of
+ wasm-pack
, the published documentation is available
+
+ on the main Rust and WebAssembly documentation site
+ . Features documented here may not be available in released versions of
+ wasm-pack
.
+
The publish
and pack
commands interact with the pkg directory that's
+created when you run wasm-pack build
. The pack
command creates a tarball
+from the pkg directory and the publish
command creates a tarball from the
+pkg directory and publishes it to the NPM registry.
Underneath, these commands use npm pack
and npm publish
. You can read
+more about these in the NPM documentation:
npm pack
npm publish
Both these commands take the path to the pkg directory as the first argument. +You can either set the argument directly to the pkg directory or to the parent +of the pkg directory:
+$ wasm-pack pack myproject/pkg
+| 🎒 packed up your package!
+$ wasm-pack pack myproject
+| 🎒 packed up your package!
+
+If you try to call pack
or publish
on another directory, you get an error:
$ wasm-pack pack myproject/src/
+Unable to find the pkg directory at path 'myproject/src/', or in a child directory of 'myproject/src/'
+
+If you don't set a path, they use the current directory as the path.
+You can also publish tagged releases with the optional --tag
argument, e.g.
wasm-pack publish --tag next
+
+By default, the latest
tag is used to identify the current version of a package,
+and npm install <pkg> (without any @<version> or @<tag> specifier) installs the latest tag.
You can read more about distribution tags on NPM.
+ +
+ This is the unpublished documentation of
+ wasm-pack
, the published documentation is available
+
+ on the main Rust and WebAssembly documentation site
+ . Features documented here may not be available in released versions of
+ wasm-pack
.
+
The wasm-pack test
command wraps the wasm-bindgen-test-runner
+CLI allowing you to run wasm tests in different browsers without needing to install the different
+webdrivers yourself.
wasm-pack test --help
+
+The wasm-pack test
command can be given an optional path argument.
This path should point to a directory that contains a Cargo.toml
file. If no
+path is given, the test
command will run in the current directory.
# Run tests for the current directory's crate
+wasm-pack test
+
+# Run tests for a specified crate
+wasm-pack test crates/crate-in-my-workspace
+
+The test
command accepts an optional profile argument: --release
.
If none is supplied, then a debug test build will be used.
+Choose where to run your tests by passing in any combination of testing environment flags.
+--headless
is useful for running browser tests in a headless browser as part of a CI process.
wasm-pack test --node --firefox --chrome --safari --headless
+
+The test
command can pass extra options straight to cargo test
even if they are not
+supported in wasm-pack.
To use them simply add the extra arguments at the very end of your command, just
+as you would for cargo test
.
cargo test -h
for a list of all options that you can pass through.
When debugging a specific issue, you may find yourself wanting to run a subset of tests, instead of your entire suite of tests.
+Here are a few examples of how to run a subset of your tests:
+# Example directory structure
+$ tree crates/foo
+├── Cargo.toml
+├── README.md
+├── src
+│ ├── diff
+│ │ ├── diff_test_case.rs
+│ │ └── mod.rs
+│ ├── lib.rs
+└── tests
+ ├── diff_patch.rs
+ └── node.rs
+
+# Run all tests in tests/diff_patch.rs in Firefox
+wasm-pack test crates/foo --firefox --headless --test diff_patch
+
+# Run all tests in tests/diff_patch.rs that contain the word "replace"
+wasm-pack test crates/foo --firefox --headless --test diff_patch replace
+
+# Run all tests inside of a `tests` module inside of src/lib/diff.rs
+wasm-pack test crates/foo --firefox --headless --lib diff::tests
+
+# Same as the above, but only if they contain the word replace
+wasm-pack test crates/foo --firefox --headless --lib diff::tests::replace
+
+Note that you can also filter tests by location in which they're supposed to +run. For example:
+# Run all tests which are intended to execute in Node.js
+wasm-pack test --node
+
+# Run all tests which are intended to be executed in a browser
+wasm-pack test --firefox --headless
+
+
+
+ This is the unpublished documentation of
+ wasm-pack
, the published documentation is available
+
+ on the main Rust and WebAssembly documentation site
+ . Features documented here may not be available in released versions of
+ wasm-pack
.
+
The technical prerequisites for contributing to this project are the same as for +using it. You can find them documented here.
+You'll also want to check out the contributing guidelines.
+rustwasm/wasm-pack
repositorycd wasm-pack
cargo run
. To test command line arguments you can run cargo run -- <args>
.Documentation lives in the /docs
directory. Each command has its own page.
+Additionally there are extra pages explaining the prerequisites, setup, and how to
+contribute (which you are reading now!).
Tests live in the /tests
directory. To run the tests you can run:
cargo test
+
+You can also manually test the CLI tool by running:
+cargo run -- <args>
+
+...for example:
+cargo run -- init /tests/fixtures/js-hello-world --scope=ag_dubs
+
+
+
+ This is the unpublished documentation of
+ wasm-pack
, the published documentation is available
+
+ on the main Rust and WebAssembly documentation site
+ . Features documented here may not be available in released versions of
+ wasm-pack
.
+
wasm-pack
docs!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!
+ + +