Reference

leylines/vite

Functions

leylines

Create a Vite plugin that captures browser logs into a local Leylines store.

export function leylines(options?: LeylinesVitePluginOptions): VitePluginLike;

šŸ” leylines on GitHub

Types

LeylinesVitePluginOptions

Options for the Leylines Vite development plugin.

export interface LeylinesVitePluginOptions extends OpenScopedLogsOptions {
  endpoint?: string;
  scope?: string;
  captureConsole?: boolean | LogLevel[];
  captureErrors?: boolean;
  captureRejections?: boolean;
  production?: boolean;
  stripProduction?: boolean;
  metadata?: JsonObject;
  posthog?: boolean | PostHogViteOptions;
  viteLogger?: boolean | ViteLoggerCaptureOptions;
  captureViteLogger?: boolean | ViteLoggerCaptureLevel[];
}

Properties

  • endpoint Browser log ingestion endpoint injected into the page. Defaults to /__scoped_logs.

  • scope Root browser logger scope. Defaults to browser.

  • captureConsole Capture console methods from the browser logger injection.

  • captureErrors Capture uncaught browser errors. Defaults to true.

  • captureRejections Capture unhandled promise rejections. Defaults to true.

  • production Enable the plugin and its Node log store during production builds.

  • stripProduction Remove browser logger calls from production builds and replace remaining logger references with no-ops.

  • metadata Metadata merged into entries written by Vite ingestion middleware.

  • posthog Redirect PostHog browser product analytics into the local Leylines store.

  • viteLogger Capture Vite's own logger output into the local Leylines store.

  • captureViteLogger Shorthand for viteLogger.levels with the default dev.vite scope.

šŸ” LeylinesVitePluginOptions on GitHub

PostHogViteOptions

Options for redirecting PostHog browser events into the local Leylines store.

export interface PostHogViteOptions {
  endpoint?: string;
  scope?: string;
}

Properties

  • endpoint Local PostHog-compatible ingestion endpoint. Defaults to /__leylines/posthog.

  • scope Scope assigned to redirected PostHog entries. Defaults to posthog.

šŸ” PostHogViteOptions on GitHub

RequestLike

interface RequestLike {
  method?: string;
  on(event: 'data', listener: (chunk: Buffer | string) => void): void;
  on(event: 'end', listener: () => void): void;
  on(event: 'error', listener: (error: Error) => void): void;
}

šŸ” RequestLike on GitHub

ResponseLike

interface ResponseLike {
  statusCode: number;
  setHeader(name: string, value: string): void;
  end(body?: string): void;
}

šŸ” ResponseLike on GitHub

ViteLoggerCaptureLevel

export type ViteLoggerCaptureLevel = Extract<LogLevel, 'info' | 'warn' | 'error'>;

šŸ” ViteLoggerCaptureLevel on GitHub

ViteLoggerCaptureOptions

Options for capturing Vite's own logger output into Leylines.

export interface ViteLoggerCaptureOptions {
  scope?: string;
  levels?: ViteLoggerCaptureLevel[];
}

Properties

  • scope Scope assigned to captured Vite logger entries. Defaults to dev.vite.

  • levels Vite logger levels to capture. Defaults to warn and error.

šŸ” ViteLoggerCaptureOptions on GitHub

ViteLoggerLike

interface ViteLoggerLike {
  info?: ViteLoggerMethod;
  warn?: ViteLoggerMethod;
  warnOnce?: ViteLoggerMethod;
  error?: ViteLoggerMethod;
}

šŸ” ViteLoggerLike on GitHub

ViteLoggerMethod

type ViteLoggerMethod = (message: string, options?: ViteLogOptionsLike, ...rest: unknown[]) => void;

šŸ” ViteLoggerMethod on GitHub

ViteLogOptionsLike

interface ViteLogOptionsLike {
  error?: unknown;
  [key: string]: unknown;
}

šŸ” ViteLogOptionsLike on GitHub

VitePluginLike

Minimal Vite plugin shape returned by leylines.

export interface VitePluginLike {
  name: string;
  apply?: 'serve' | 'build';
  configResolved(config: ViteResolvedConfigLike): void;
  configureServer(server: ViteServerLike): void;
  transformIndexHtml(html: string): string;
  transform(code: string, id?: string): string | null;
  closeBundle(): void;
}

Properties

  • name Vite plugin name.

  • apply Vite apply mode.

  • configResolved Receive resolved Vite mode and command.

  • configureServer Register local ingestion middleware on the Vite dev server.

  • transformIndexHtml Inject browser logger setup into HTML.

  • transform Rewrite application modules before Vite compiles them.

  • closeBundle Close any store resources opened by the plugin.

šŸ” VitePluginLike on GitHub

ViteResolvedConfigLike

interface ViteResolvedConfigLike {
  mode?: string;
  command?: string;
  logger?: ViteLoggerLike;
}

šŸ” ViteResolvedConfigLike on GitHub

ViteServerLike

interface ViteServerLike {
  middlewares: {
    use(path: string, handler: (req: RequestLike, res: ResponseLike, next: (error?: unknown) => void) => void): void;
  };
}

šŸ” ViteServerLike on GitHub