Skip to content

Latest commit

 

History

History

webpack-demo

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Webpack Demo

[MDN] 编译 Rust 为 WebAssembly

快速开始

环境安装

创建 Rust 包

生成项目

cargo new --lib hello-wasm
    Created library `hello-wasm` package

编辑 src/lib.rs

extern crate wasm_bindgen;

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern {
    pub fn alert(s: &str);
}

#[wasm_bindgen]
pub fn greet(name: &str) {
    alert(&format!("Hello, {}!", name));
}

编辑 Cargo.toml

[package]
name = "hello-wasm"
version = "0.1.0"
description = "A sample project with wasm-pack"
license = "MIT"

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = "0.2"

构建 Rust 包

wasm-pack build hello-wasm