[][src]Crate wasm_run

Synopsis

Build tool that replaces cargo run to build WASM projects.

To build your WASM project you normally need an external tool like wasm-bindgen, wasm-pack or cargo-wasm. wasm-run takes a different approach: it's a library that you install as a dependency to a binary of your project. Because of that you don't need any external tool, the tooling is built as part of your dependences.

To build your project for production you can use the command cargo run -- build and to run a development server that reloads automatically when the sources change you can use cargo run -- serve.

Please note that there is a space between -- and build and between -- and serve!

One of the main advantage of this library is that it provides greater customization: you can set a few hooks during the build process in order to customize the build directory or use a template to generate your index.html, download some CSS, ... you name it. I personally use it to reduce the amount of files by bundling the CSS and the JS into the index.html so I had only two files (index.html, app_bg.wasm).

Examples

There are two basic examples to help you get started quickly:

  • a "basic" example for a frontend only app that rebuilds the app when a file change is detected;
  • a "backend-and-frontend" example using the web framework Rocket (backend) which uses Rocket itself to serve the file during the development (any file change is also detected and it rebuilds and restart automatically).

Additional Information

  • You can use this library to build examples in the examples/ directory of your project. cargo run --example your_example -- serve. But you will need to specify the name of the WASM crate in your project and it must be present in the workspace. Please check the "example" example.
  • If you want to use your own backend you will need to disable the serve feature by disabling the default features. You can use the full-restart feature to force the backend to also be recompiled when a file changes (otherwise only the frontend is re-compiled). You will also need to specify run_server to the macro arguments to run your backend.
  • You can add commands to the CLI by adding variants in the enum.
  • You can add parameters to the Build and Serve commands by overriding them. Please check the documentation on the macro main.

Re-exports

pub use anyhow;
pub use async_std;
pub use futures;
pub use notify;
pub use tide;

Structs

DefaultBuildArgs

Build arguments.

DefaultServeArgs

Serve arguments.

Hooks

Hooks.

Enums

BuildProfile

A build profile for the WASM.

Traits

BuildArgs

A trait that allows overriding the build command.

ServeArgs

A trait that allows overriding the serve command.

Attribute Macros

main

Makes an entrypoint to your binary (not WASM).