Setup
bun add @bitstillery/mithril
Types are built-in; no @types package needed.
Basic application
Scaffold a project:
bun init my-app,cd my-app,bun add @bitstillery/mithrilAdd to
package.json:"dev": "bun run --watch src/index.tsx"Create
src/index.tsx:
import m, {state, MithrilComponent} from '@bitstillery/mithril'
const $s = state({count: 0})
class App extends MithrilComponent {
view() {
return (
<div>
<p>Count: {$s.count}</p>
<button onclick={() => $s.count++}>Add</button>
</div>
)
}
}
m.mount(document.getElementById('app'), App)
Create
index.htmlwith<div id="app"></div>and<script type="module" src="src/index.tsx"></script>Run
bun run dev
Use fetch() for HTTP (e.g. in oninit). Use m.route for multiple views. See route and Store. For TSX, set "jsx": "react-jsx" in tsconfig.json, or use htm.