# Install wasm-pack
cargo install wasm-pack
# Or use npm
npm install -g wasm-packcd /home/user/ruvector/examples/scipix
wasm-pack build \
--target web \
--out-dir web/pkg \
--release \
-- --features wasm
# Or use the provided script
./web/build.shwasm-pack build \
--target web \
--out-dir web/pkg \
--dev \
-- --features wasm
# Or
npm run build:devThe build creates:
web/pkg/
├── ruvector_scipix.js # JavaScript bindings
├── ruvector_scipix_bg.wasm # WASM binary (~800KB gzipped)
├── ruvector_scipix.d.ts # TypeScript definitions
└── package.json # Package metadata
cd web
python3 -m http.server 8080./web/build.sh --serveNavigate to: http://localhost:8080/example.html
npm install ruvector-scipix-wasmcp -r web/pkg your-project/src/wasm/import { createScipix } from './pkg/ruvector_scipix.js';
const scipix = await createScipix();
const result = await scipix.recognize(imageData);rustup target add wasm32-unknown-unknown# Update Cargo.toml with WASM dependencies
cargo updateEnsure you're serving files with proper CORS headers:
# Use a CORS-enabled server
npm install -g http-server
http-server web -p 8080 --corsThe release build should be optimized. Check:
# Verify optimization settings in Cargo.toml
[profile.release]
opt-level = "z"
lto = true
codegen-units = 1Current optimizations applied:
- ✅ Size optimization (
opt-level = "z") - ✅ LTO enabled
- ✅ Single codegen unit
- ✅ Debug symbols stripped
- ✅ wee_alloc (custom allocator)
- ✅ Panic = abort
Expected sizes:
- Raw WASM: ~1.5MB
- Gzipped: ~800KB
- With Brotli: ~600KB
# Build with specific features
wasm-pack build --features "wasm,preprocess"
# No default features
wasm-pack build --no-default-features --features wasm# Modern browsers only
wasm-pack build --target web
# For bundlers (Webpack, Rollup)
wasm-pack build --target bundler
# For Node.js
wasm-pack build --target nodejscargo build --timings --release --target wasm32-unknown-unknown --features wasm- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Build WASM
run: |
cd examples/scipix
wasm-pack build --target web --out-dir web/pkg --release -- --features wasm
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: wasm-build
path: examples/scipix/web/pkg/- Build the WASM module
- Test with the demo HTML
- Integrate into your application
- Deploy to production