A Go tool and CLI for building and serving WebAssembly apps from a src/ directory.
- Module path:
github.com/vrianta/tofus - Go version:
1.24.3
- Put your source code under a
src/directory. - Run
tofus --buildfrom the project root. - Run
tofus --runfrom the generatedbuild/directory, or usetofus --build --run.
- Build WebAssembly apps from Go packages under
src/ - Copy non-
.gofiles into thebuild/directory as static assets - Auto-generate HTTP routes for
main.wasmapplications - Serve static assets from generated directories
- All source code must be inside the
src/directory. - A WebAssembly build is created only for folders that contain
main.go.
Recommended install:
go install github.com/vrianta/tofus@latestAlternative install:
./install.shtofus --build- Creates a
build/directory. - Scans the
src/directory recursively. - For each folder that contains
main.go, it buildsmain.wasmin the correspondingbuild/location. - Copies all non-
.gofiles intobuild/while preserving the directory structure.
Before build:
src/
assets/
js/
main.js
css/
main.css
login/
main.go
main.go
After build:
build/
assets/
js/
main.js
css/
main.css
login/
main.wasm
main.wasm
cd build
tofus --runtofus --build --runThis builds the project first and then runs the server without requiring you to change into the build/ directory.
- The tool scans the generated
build/tree. - For each folder containing
main.wasm, it creates a route for that folder. - For folders with only static files, it creates a file server for those assets.
Given this build/ tree:
build/
assets/
js/
main.js
css/
main.css
login/
main.wasm
main.wasm
Generated routes:
//login/
Static file servers:
/assets/css//assets/js/
- Only directories with
main.goinsrc/become WebAssembly app routes. - Non-
.gofiles are copied as static assets. - If
build/already exists, it is updated with the new output. - Nested
main.gofiles are supported as long as they live insidesrc/.
- If
src/is missing or empty, the build produces no output. - If a folder contains no
main.goand only static files, those files are still copied as static assets. - If a route is not created, verify that
main.goexists in the expectedsrc/folder.