UNPKG

@stacksjs/stx

Version:

A performant UI Framework. Powered by Bun.

87 lines 2.74 kB
/** * Generate the hot reload client script to inject into HTML */ export declare function generateHotReloadScript(wsPort: number, options?: HotReloadOptions): string; /** * Inject hot reload script into HTML content */ export declare function injectHotReload(html: string, wsPort: number, options?: HotReloadOptions): string; /** * Determine if a file change should trigger a CSS-only update */ export declare function isCssOnlyChange(filename: string): boolean; /** * Determine if a file change should trigger a reload */ export declare function shouldReloadOnChange(filename: string): boolean; /** * Determine if a file should be ignored */ export declare function shouldIgnoreFile(filename: string): boolean; /** * Get or create the global HMR server instance */ export declare function getHmrServer(options?: HotReloadOptions): HotReloadServer; /** * Stop and clear the global HMR server */ export declare function stopHmrServer(): void; /** * Hot Reload Module * * Provides WebSocket-based hot module reload (HMR) for the stx dev server. * When template files change, connected browsers automatically refresh. * * ## Features * * - WebSocket server for real-time browser communication * - Client script injection into HTML * - Full page reload on template changes * - CSS-only updates without full reload (when possible) * - Connection status overlay * - Automatic reconnection on disconnect * * ## Usage * * The hot reload is automatically enabled when using `stx dev` or `serveStxFile()`. * No additional configuration needed. * * ## Architecture * * ``` * File System Watch → HMR Server → WebSocket → Browser Client → Reload * ``` */ // ============================================================================= // Types // ============================================================================= export declare interface HotReloadOptions { wsPort?: number showOverlay?: boolean reconnectInterval?: number maxReconnectAttempts?: number verbose?: boolean } export declare interface HotReloadMessage { type: 'reload' | 'css-update' | 'connected' | 'error' path?: string content?: string timestamp?: number } /** * Hot Reload Server * * Manages WebSocket connections and broadcasts reload messages to browsers. */ export declare class HotReloadServer { private clients: Set<WebSocketClient>; private server: ReturnType<typeof Bun.serve> | null; private options: Required<HotReloadOptions>; constructor(options?: HotReloadOptions); start(port?: number): number; stop(): void; broadcast(message: HotReloadMessage): void; reload(filePath?: string): void; updateCss(filePath: string, content?: string): void; error(message: string): void; }