API reference

vite

Every export of @kitr/vite, @kitr/vite/client, read from the published type definitions. The guide shows them in use.

@kitr/vite

configEnables

function configEnables(configDir: string, name: string): boolean;

Static read of config/<name>.ts: does it set enabled to anything but false? A literal true turns the package on; an expression (process.env.DEBUG === '1') is decided at runtime, so the code has to ship for it. Absent or false: no.

crawlFilter

function crawlFilter(): (page: {
  path: string;
  sitemap?: {
    exclude?: boolean;
  };
}) => boolean;

Start's crawler treats /docs/a#install and /docs/a as two pages: it renders the same file once per anchor and lists every anchor in the sitemap. This keeps one page per path: a hash is dropped, and a path already taken is skipped and left out of the sitemap.

finishPrerender

function finishPrerender(options: {
  guard?: PrerenderGuard;
  clientDir: string;
  serverEntry: string;
  notFoundPage?: boolean;
  logger: {
    warn(msg: string): void;
    error(msg: string): void;
  };
}): Promise<void>;

After Start's prerender: print one line per page that failed ([prerender] 404 at /x, linked from /y), with the status asked again of the built server, and fail the build when a listed route failed or failOnError is on. A static site also gets 404.html: the root's notFoundComponent, rendered for a path no route matches, which Cloudflare Pages, Netlify and GitHub Pages serve for unknown paths. It is written here because Start's prerender refuses a page that answers 404, and so it is never crawled or listed in the sitemap.

kitr

function kitr(options?: KitrPluginOptions): PluginOption[];

The kitr() Vite plugin. It reads kitrrc.ts and the installed packages' vite declarations at build time and:

  • wires TanStack Start (or the router plugin) and every plugin a package declares (React, Tailwind),
  • exposes virtual:kitr/providers and virtual:kitr/config as static imports,
  • pre-declares optimizeDeps from the packages' lists so dev start never rediscovers,
  • sets the active platform's port, outDir and the #app-style aliases.

prerenderGuard

function prerenderGuard(options: {
  routes: string[];
  failOnError?: boolean;
}): PrerenderGuard;

Start's prerender throws on the first page that does not answer 200, and the build dies with a dump of the Response. Start runs with failOnError: false instead, and this keeps the record: filter (crawlFilter, plus a note of every page asked for) holds each page out of the sitemap, onSuccess puts it back and notes which page links where, and failures() is the difference, for finishPrerender to print and fail on.

readPrerender

function readPrerender(root: string, configDir: string): {
  pages?: Array<{
    path: string;
  }>;
  prerender?: Record<string, unknown>;
  sitemap?: Record<string, unknown>;
  failOnError?: boolean;
};

Static read of config/seo.ts: prerender: ['/a'] or { routes: [...], crawlLinks } becomes Start's pages + prerender, and site.url turns on the sitemap. failOnError: true comes back beside them, for prerenderGuard. No execution needed.

readRc

function readRc(root: string): RcInfo;

Static read of kitrrc.ts: import('...') specs under providers: and the packages list. No execution needed.

readRcPlatforms

function readRcPlatforms(src: string): Record<string, RcPlatform>;

Static read of platforms: { site: web({ mode: 'ssr' }) }: names, factories and literal options.

robotsFor

function robotsFor(root: string, configDir?: string): Promise<string | null>;

The robots.txt for a project: robotsTxt() from

KitrPluginOptions

interface KitrPluginOptions {
  /** Project root. Default: Vite's root. */
  root?: string;
  /** Use TanStack Start (SSR, prerender, server functions). Default: when an installed package asks for it (`router` does). */
  start?: boolean | Record<string, unknown>;
  /**
   * Leave out the Vite plugin a package declares, by its short name: `{ tailwind: false }` skips
   * `@kitr/tailwind/vite`, `{ react: false }` skips `@vitejs/plugin-react`. Default: every declared plugin.
   */
  plugins?: Record<string, boolean>;
  /** Route files directory. Default `app/routes`. */
  routesDirectory?: string;
  generatedRouteTree?: string;
  /** Extra options for @tanstack/router-plugin. */
  router?: Record<string, unknown>;
  /**
   * Include `@kitr/devtools/provider`. Default: always in development; in production builds only
   * when `config/devtools.ts` sets `enabled`.
   */
  devtools?: boolean;
  /** Which platform from kitrrc.ts this build is for. Default: `KITR_PLATFORM` (set by `kitr dev|build <name>`), else the first web platform. */
  platform?: string;
  /**
   * Run `kitr types` when the build starts and again in dev whenever a watched file changes, so
   * `.kitr/` is always current. Needs `@kitr/cli` installed (it is, in every kitr project).
   * Default true.
   */
  types?: boolean;
}

Options for kitr() in vite.config.ts. All optional: the rest comes from kitrrc.ts.

PrerenderFailure

interface PrerenderFailure {
  /** The page's path, without its `#hash`. */
  path: string;
  /** The first page whose HTML linked to it; missing for a page only the config lists. */
  from?: string;
  /** Listed in `config/seo.ts` `prerender.routes` (or `/` on a static site), not crawled. */
  listed: boolean;
}

A page the prerender asked for and did not write.

PrerenderGuard

interface PrerenderGuard {
  /** Start's `prerender.filter`: drops anchors and repeats, and notes every page it lets through. */
  filter(page: {
    path: string;
    sitemap?: {
      exclude?: boolean;
    };
  }): boolean;
  /** Start's `prerender.onSuccess`: notes the page as written and which pages it links to. */
  onSuccess(result: {
    page: {
      path: string;
      sitemap?: {
        exclude?: boolean;
      };
    };
    html: string;
  }): void;
  /** Pages that passed the filter and were never written. */
  failures(): PrerenderFailure[];
  /** Fail the build for crawled pages too (`prerender.failOnError` in `config/seo.ts`). */
  failOnError: boolean;
}

The filter and onSuccess hooks prerenderGuard() hands Start, and what they saw.