The WebAssembly backend is the recommended compilation target for miso applications.
Path 1: Sampler template
The miso-sampler repository is a template that includes a sample counter application and build scripts for WebAssembly, JavaScript, and vanilla GHC. It requires Nix Flakes.Path 2: Manual setup
If you prefer to create your project from scratch — or if you are not using Nix — follow these steps to build the counter application manually. You need three files:cabal.project, app.cabal, and Main.hs.
Install GHC and cabal
Install GHCup to get GHC and cabal. For new Haskell users, GHCup is the recommended approach.Then follow the Installation guide to add the WASM or JavaScript backend compiler.
Build the application
With the WASM backend installed and A
wasm32-wasi-cabal on your $PATH, run:.wasm binary is produced in the dist-newstyle/ directory. See the Installation guide for the complete steps to package and serve the WASM output in a browser.Understanding the counter app
The counter application demonstrates the core miso architecture: Model-View-Update.| Component | Description |
|---|---|
App Int Action | The application type: model is Int, messages are Action |
component | Constructs an App from an initial model, update function, and view function |
updateModel | A pure function that handles each Action and updates the model or runs effects |
viewModel | A pure function that renders the model as a virtual DOM tree |
startApp | Bootstraps the application and starts the event loop |
#ifdef WASM block exports hs_start as a JavaScript symbol, which is required when compiling with the WebAssembly backend.
Next steps
Installation
Set up the WASM or JS backend compiler in detail
Architecture
Understand the Model-View-Update pattern
Hot reload
Set up live reload with ghciwatch and WASM browser mode
Examples
Explore real-world miso applications