A template for kick starting a Rust and WebAssembly project using wasm-pack.
Built with 🦀🕸 by The Rust and WebAssembly Working Group
📚 Read this template tutorial! 📚
This template is designed for compiling Rust libraries into WebAssembly and publishing the resulting package to NPM.
Be sure to check out other wasm-pack
tutorials online for other
templates and usages of wasm-pack
.
Learn more about cargo generate
here.
cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project
cd my-project
wasm-pack build
wasm-pack test --headless --firefox
rm -rf lib/src/flutter_web_wasm_base.dart
dart_js_facade_gen pkg/flutter_web_wasm.d.ts | tee lib/src/flutter_web_wasm_base.dart
wasm-pack publish
In example/lib/web/index.html import your js library via script tag
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>example</title>
</head>
<body>
<script src="main.dart.js" type="application/javascript"></script>
<script src="https://unpkg.com/[email protected]/flutter_web_wasm.js"></script> <!-- Import your freshly generated library from unpk cdn -->
</body>
</html>
In your example/lib/main.dart import your library
import 'package:flutter_web_wasm/flutter_web_wasm.dart';
wasm-bindgen
for communicating between WebAssembly and JavaScript.console_error_panic_hook
for logging panic messages to the developer console.wee_alloc
, an allocator optimized for small code size.