cursery.nixDocs

Pages

The Vite plugin builds the pages in its pages option. Each has a server entry and a client, the code that runs in the browser.

Declare pages#

Pages are keyed by their path in the build output:

vite.config.js
import cursery from "cursery/vite-plugin";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [
    cursery({
      pages: {
        "index.html": {
          entry: {
            server: "./src/page.nix",
            client: { type: "nix", path: "./src/app" },
          },
        },
        "settings/index.html": {
          entry: {
            server: "./src/page.nix",
            client: {
              type: "nix",
              path: "./src/settings",
              effects: "./src/settings/effects.js",
            },
          },
        },
        "about/index.html": {
          entry: {
            server: "./src/about.nix",
            client: { type: "static" },
          },
        },
      },
    }),
  ],
});

The dev server serves each page at its route, so settings/index.html is at /settings/. Paths are relative to the project root, and must stay inside it.

Pages can share a server entry.

Clients#

A page's client has one of three types:

  • nix: an app directory at path. The page renders it, and mounts it in the browser. effects is an optional module of effects.
  • manual: a JavaScript module at path, responsible for hydrating the client. See Embedding.
  • static: no client. The page is HTML only.

The client decides the server entry's inputs. Only nix clients fill children and assets, and static pages get no scripts.