Toolchain Baseline
The Stim Webtoys Library uses a modern JavaScript toolchain:- Package manager/runtime: Bun 1.3+ (
[email protected]pinned inpackage.json) - Build/dev server: Vite
- Lint + format: Biome
- Typecheck: TypeScript (
tsc --noEmit) - Tests: Bun test with preload/importmap wiring
- Deploy tooling: Wrangler for Cloudflare Pages
Prerequisites
Node is supported for fallback script execution (
engines.node: ^22), but use Bun for installs and scripts.Installing Bun
Install Bun 1.3 or higher from bun.sh:Installation
Clone and Install
Installing Dependencies
bun.lock. Use bun install --frozen-lockfile in CI or other reproducible-install contexts where lockfile changes must be disallowed.
Core Development Commands
Dev Server
Use
bun run dev:host when you need the server bound to all interfaces for mobile/LAN testing.Building
Build Output
The production build outputs todist/. Preview the build on http://localhost:4173 using Vite’s preview server with the --host flag for LAN testing.
Development Workflows
Golden-Path Recipe: JS/TS Feature
Golden-Path Recipe: Add/Rename Toy
Implement Toy
Create or modify:
- Toy implementation in
assets/js/toys/ - Toy metadata in
assets/data/toys.json - Standalone page in
toys/for page-backed toys - Update docs:
docs/TOY_DEVELOPMENT.md,docs/TOY_SCRIPT_INDEX.md,docs/toys.md - Tests in
tests/where behavior changed
Golden-Path Recipe: Pages Deployment
Cloudflare Pages Workflows
Troubleshooting
Microphone Permissions
- If the browser denied microphone access, re-allow it via the address bar/site settings and click the start button again
- Hard-refreshing the page will re-trigger the prompt on most browsers
- Switch to demo audio if you keep seeing timeouts or “blocked” errors
- Use the YouTube audio option on
toy.htmlto paste a video link and capture tab audio
WebGPU Gating
- A WebGPU fallback warning means the browser lacked a compatible adapter or device at startup
- Toys will fall back to WebGL when possible
- To force a retry after toggling a browser flag or switching GPUs, refresh the page
- WebGPU-only toys (like
multi) won’t run without WebGPU support
Dev-Server Hosting
- Check the served port in the terminal output (Vite defaults to
5173; preview uses4173) - Connect from other devices via
http://<your-ip>:<port>
Common Issues
| Issue | Solution |
|---|---|
bun run test behaves differently from bun test | Always use bun run test so preload/importmap flags apply |
| Formatting/lint drift | Run bun run lint:fix followed by bun run format |
| Typecheck errors after dependency changes | Rerun bun install then bun run typecheck |
check:toys failures after renaming | Verify toy docs and metadata updates landed together |
| Pages command failures locally | Verify Wrangler auth/context and rerun bun run pages:dev |
navigator.gpu missing during local testing | Run bun run dev:webgpu so Chromium starts with WebGPU flags |
Helpful Scripts Reference
Here are all the key scripts frompackage.json:
Repository Layout
Understand the project structure:assets/js/toys/- Individual toy implementations (e.g.,cube-wave.ts,spiral-burst.ts)assets/js/core/- Rendering and input helpers used by multiple toysassets/js/utils/- Small utility modules supporting core helpers and toysassets/css/- Shared styling for HTML entry pointsassets/data/- Static data files consumed by toys (e.g.,toys.json)tests/- Bun specs validating core behaviorstoy.html,brand.html, etc. - Entry points loading specific toys or collectionsdocs/- Comprehensive project documentationscripts/- Build, deployment, and utility scripts
Next Steps
Code Quality
Learn about linting, formatting, and testing practices
Getting Started
Review the contribution guidelines