Overview
Theinit-wasm command generates Docker-based build configuration files that enable you to compile your Talon game to WebAssembly (WASM). This allows you to deploy your game as a web application that runs in any modern browser.
Syntax
Path to your main Wren script file. This will be used as the entry point for the compiled WebAssembly module.
What It Creates
Runninginit-wasm generates three files in your current directory:
1. Dockerfile
A Docker configuration that:- Sets up an Emscripten environment for WASM compilation
- Compiles your Talon game to WebAssembly
- Generates all necessary web assets
- Outputs files to the
dist/directory
2. docker-compose.yml
A Docker Compose file that:- Defines the build service
- Configures volume mounts
- Sets up output directories
- Uses your project directory name as the service name
3. shell.html
A custom HTML shell template that:- Provides the webpage structure for your game
- Loads the WebAssembly module
- Handles canvas rendering
- Manages browser integration
Generated Files
All files are customized with:- Project Name: Extracted from your current directory name
- Main File: The
.wrenfile you specified as the entry point
Build Process
Step 1: Initialize
Generate the WASM build configuration:Dockerfiledocker-compose.ymlshell.html
Step 2: Build
Compile the WebAssembly module using Docker Compose:- Build the Docker image with Emscripten
- Compile your game to WASM
- Generate HTML, JavaScript, and WASM files
- Output web assets to
dist/folder
Step 3: Deploy
Find your web build in thedist/ directory:
Complete Example
Project Structure
Initialize WASM Build
Build WebAssembly
Check Results
Deployment
Local Testing
Serve thedist/ directory with a local web server:
http://localhost:8000 in your browser.
Static Hosting
Upload thedist/ directory to any static hosting service:
- GitHub Pages: Commit
dist/and enable Pages - Netlify: Drag and drop
dist/folder - Vercel: Deploy with
vercel dist/ - itch.io: Upload as HTML5 game
- AWS S3: Sync
dist/to an S3 bucket
Custom Domain
After uploading, your game will be accessible at:Requirements
Docker
You must have Docker installed and running:- Linux: Install via package manager or docker.com
- macOS: Install Docker Desktop
- Windows: Install Docker Desktop
Docker Compose
Modern Docker installations include Docker Compose v2:Browser Requirements
Your game will run in browsers with WebAssembly support:- Chrome 57+
- Firefox 52+
- Safari 11+
- Edge 16+
File Templates
The generated files use templates with placeholders:{{{ PROJECT_NAME }}}- Replaced with your directory name{{{ MAIN_FILE }}}- Replaced with your specified.wrenfile
Advanced Usage
Customizing HTML Shell
Theshell.html file can be customized:
Embedding Assets
To include game assets in the WASM build:- Modify the
Dockerfileto copy asset directories - Use Emscripten’s
--embed-fileor--preload-fileflags - Access assets in Wren code as normal file paths
Optimizing Build Size
Modify the Dockerfile to add optimization flags:Browser Features
Your WASM game has access to:- Canvas Rendering: Full Raylib 2D drawing API
- Input Handling: Keyboard and mouse events
- Audio: WebAudio for sound playback (if implemented)
- File System: Virtual file system via Emscripten
- Local Storage: Browser storage APIs
Troubleshooting
Docker Not Found
Build Fails
Check Docker logs:- Syntax errors in Wren code
- Missing module imports
- Unsupported Raylib features
- Memory allocation issues
Black Screen in Browser
Check browser console (F12) for errors:- WebAssembly module failed to load
- JavaScript syntax errors
- CORS issues (use proper web server)
- Missing files
Slow Loading
Large WASM files take time to download:- Optimize assets
- Use compression (gzip)
- Consider a loading screen
- Split large games into modules
CORS Errors
When testing locally, use a proper web server:Build Time
First build may take several minutes:- Docker image download: ~2-3 minutes
- Emscripten setup: ~1-2 minutes
- Compilation: ~1-3 minutes
- Total: ~4-8 minutes
Performance
WebAssembly provides near-native performance:- Execution Speed: ~80-90% of native code
- Startup Time: Depends on WASM module size
- Memory: Limited by browser heap (typically 1-4GB)
- Graphics: Hardware accelerated via WebGL
Comparison with Native Builds
| Feature | init-wasm | init-exe |
|---|---|---|
| Output | HTML + WASM | Native binaries |
| Performance | ~80-90% native | 100% native |
| Distribution | Web hosting | Download & install |
| Updates | Instant (reload page) | Manual download |
| Platform support | Any modern browser | Linux, Windows |
| File size | Smaller | Larger |
| Installation | None | Required |
Related Commands
talon run- Run your game during developmenttalon --hot- Develop with automatic reloadingtalon init-exe- Build native executables
Best Practices
- Test Locally: Verify WASM build works before deploying
- Version Control: Add
Dockerfile,docker-compose.yml, andshell.htmlto Git - Ignore Build Output: Add
dist/to.gitignore - Optimize Assets: Compress images and audio files
- Mobile Support: Test on mobile browsers for touch input
- Loading Screen: Add a loading indicator for large games
- Error Handling: Provide fallbacks for unsupported features
Example Deployment
Deploying to itch.io
-
Build your game:
-
Create a ZIP of the
dist/folder: -
Upload to itch.io:
- Create new project
- Select “HTML” as project type
- Upload
game.zip - Check “This file will be played in the browser”
- Set canvas size
Deploying to GitHub Pages
Next Steps
After building for WASM:- Test: Verify in multiple browsers
- Optimize: Reduce file sizes and loading times
- Polish: Add loading screens and error messages
- Share: Deploy to web hosting or game platforms