- Docs
- Start
Getting started
An app lives in a Gradle project that takes Lithe 0.1.0 from Maven Central, or in the Lithe repository as a module of its build. This page runs an example first, then walks you through an app of your own.
Run an example
The wrappers of the Kotlin toolchain are in the repository and provide the JDK, so all you need is a shell. Every command goes through the wrapper at the root: ./kotlin on Linux and macOS, .\kotlin.bat on Windows. The first run downloads the toolchain and a JDK into the user cache, so grab a coffee.
git clone https://github.com/Ayfri/lithe.git
cd lithe
# Build the example once, which fetches its libraries
./kotlin build -m todo
# Serve it on http://127.0.0.1:8080 and rebuild on every save
./kotlin run -m devserver -- --module examples/todo
# Or write the production site to build/lithe/todo/dist
./kotlin run -m cli -- examples/todo
Which example to open:
examples/tasksis a complete app.examples/todois the page the performance figures measure.examples/features/holds one small app per feature.
./kotlin test runs every test, the end to end ones in a headless Chrome when one is installed.
An app of your own
An app that renders to a static site is a module of the repository: a folder with a module.yaml, listed under modules: in project.yaml. It's a kmp/lib module with the jvm and js platforms that depends on runtime:
product:
type: kmp/lib
platforms: [jvm, js]
apply:
- ../../kotlin.module-template.yaml
dependencies:
- ../../runtime
It holds:
src/App.lithe, the root component of the page, without required props. Other.litheand.ktfiles sit anywhere undersrc/, and a file's folder undersrc/is its package.resources/index.html, the page.{{lithe.app}}is replaced by the rendered app, and its parent element needsid="app". The other files ofresources/are copied next to the page.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My app</title>
</head>
<body>
<main id="app">{{lithe.app}}</main>
</body>
</html>
Now a first component, in src/App.lithe:
<script kotlin>
var name by state("world")
</script>
<h1>Hello {name}</h1>
<input value={::name}>
Type in the input and the title follows. That's the whole reactivity story for now.
Build the module once with ./kotlin build -m <module>, which downloads its libraries into the toolchain cache. Then either serve it with the dev server, or build the site with ./kotlin run -m cli -- <module dir> (see Static sites).
In a Gradle project
A Kotlin Multiplatform project that renders with Compose HTML in the browser, a Kobweb site included, compiles its .lithe files with the Gradle plugin io.github.ayfri.lithe. The plugin and the libraries come from Maven Central. To try the code of the repository instead, this command puts it in the local Maven repository, which the examples read first:
./kotlin publish mavenLocal
examples/kobweb and this site, examples/website, are such projects. Kobweb has the setup.
Editors
The language server for .lithe files gives you errors as you type, completion, hover, rename and more, in VS Code and IntelliJ IDEA. Editors shows how to set it up: install the VS Code extension or the IntelliJ plugin, which bring the server along.