This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
webp-wasm is a pure WebAssembly/JavaScript port of libwebp that enables WebP encoding/decoding (including animated WebP) in browsers and Node.js without native dependencies.
# Full build (ESM with TypeScript)
npm run build
# Development build (outputs to src/ for hot reload)
npm run build-wasm:dev
# Build variants
npm run build:esm # ESM module build
npm run build:cjs # CommonJS build
# Run tests
npm test
# Development server (Vite)
npm run devlibwebp (C) → Emscripten → webp-wasm.wasm + webp-wasm.js → TypeScript wrapper → dist/
- libwebp/ - Vendored libwebp v1.3.2 source (git submodule)
- webp/ - C++ wrapper using Emscripten bindings (
emscripten/bind.h) - src/index.ts - TypeScript API that loads and wraps the WASM module
- Makefile - Orchestrates WASM compilation using emcc/em++
| File | Purpose |
|---|---|
webp/webp.cpp |
Emscripten bindings (EMSCRIPTEN_BINDINGS macro) |
webp/encode.cpp |
WebP encoding including animation |
webp/decode.cpp |
WebP decoding including animation |
src/index.ts |
Public TypeScript API |
src/types.d.ts |
TypeScript type definitions |
build.sh |
Build script with emsdk auto-setup |
| Submodule | Version | Source |
|---|---|---|
| libwebp | v1.3.2 | chromium.googlesource.com/webm/libwebp |
| emsdk | 3.1.74 | github.com/emscripten-core/emsdk |
The build script automatically installs emsdk if EMSDK environment variable is not set.
The library exports async functions that load the WASM module on first call:
- Encoding:
encodeRGB,encodeRGBA,encode,encodeAnimation - Decoding:
decodeRGB,decodeRGBA,decodeAnimation - Utilities:
encoderVersion,decoderVersion
Animation encoding supports per-frame quality settings via WebPAnimationFrame.config.
Tests use Jest with experimental WASM module support:
npm test # Run all tests
npm test -- tests/encode.test.js # Run single test fileTest fixtures are PNG images in tests/fixtures/.