1. Docs
  2. Sites
Edit on GitHub[]to change page

Static sites

A Lithe site is one page: the root component App rendered to HTML at build time, plus a client that hydrates what can change. An app that renders to a static site is a kmp/lib module with the jvm and js platforms that depends on runtime, with:

  • src/App.lithe, the root component of the page, without required props. Other .lithe and .kt files sit anywhere under src/.
  • resources/index.html, the page. {{lithe.app}} is replaced by the rendered app, and its parent element needs id="app".
Lithe
<main id="app">{{lithe.app}}</main>

Getting started has a whole module.

Building

Shell
./kotlin run -m cli -- <module dir>

The command writes a production build of the site to build/lithe/<module>/dist:

File Content
index.html The page with the app rendered at build time, its <head> elements, which replace those of the template, and the links of the two files below.
app.css The scoped styles of every component, only when a component has a style block.
app.mjs The client, which hydrates the page or its islands. Linked with dead code removal and minified. A static page has none.

The other files of resources/ are copied next to them. The libraries, and the Compose compiler plugin for a module that uses Compose, come from the toolchain cache, so the module is built once with ./kotlin build -m <module> before the first site build. The build compiles every .lithe file of the module and of the modules it depends on to Kotlin, in build/lithe/<module>/generated, and prints the warnings of the Lithe compiler.

The page is rendered in the JVM of the build, so what a component prints while it renders shows as the build runs, ahead of the build log.

Options

Option Effect
--source-maps The errors of the Kotlin compiler point at the .lithe files, see Compiler errors.
--strip-comments The HTML comments of the components are left out of the page.

Compiler errors

The Lithe compiler reports its own errors and warnings with the file, line and column, see Compile errors and warnings. The errors of the Kotlin compiler name the generated files. With --source-maps, they point at the .lithe file, like the ones of the Lithe compiler:

app/src/App.lithe:12:8: Unresolved reference 'nope'.

Paths are relative to the project directory. Source maps are off by default because they make the compilation of the components about 10% slower, and a build with errors is the only one that needs them. They only concern the build log: a site ships no source map for the browser either way.

The client

The client is linked as a whole program with dead code removal, so it only carries the blocks its components use: the link drops @for, @await, <head> and the others when nothing calls them. Then esbuild minifies it. The first site build downloads its native binary (about 4.8 MB) from the npm registry into the build cache and checks it against the registry checksum, so you need neither Node nor Bun.

  • A Long is a JavaScript bigint, so the classes that emulate 64-bit integers are not shipped. The dev server does the same, so a Long is the same value in both builds.
  • The polyfills of the ES2015 link are removed, because every Baseline browser has those functions.
  • Kotlin builds a property object for each read of a by variable, which the runtime leaves unused: the build removes it, so a read allocates nothing.

Performance has the size of each example.

Build cache

Builds keep their intermediate outputs in build/lithe-cache, addressed by a hash of their inputs, and share them between the apps of the project. Each step keeps its 8 latest outputs, and deleting the folder is always safe. Static rendering always runs, because the app can read files or the clock while it renders.

Errors of a build

Message Cause
path is missing, it is the page the app is rendered into There is no resources/index.html.
path needs a {{lithe.app}} placeholder and a </head> tag The template misses one.
path is missing, it is the root component of the page There is no src/App.lithe.
Static rendering failed: The app threw while rendering, the stack trace follows.
Compose compiler plugin not found: jar. Build app once with the toolchain so it downloads the plugin. A module uses Compose and was never built.

Build, dev server and runtime errors lists the others.