UNPKG

@ordojs/core

Version:

Core compiler and runtime for OrdoJS framework

198 lines 4.46 kB
/** * @fileoverview OrdoJS Code Splitter - Implements code splitting and lazy loading */ import { type ComponentAST, type OptimizationError } from '../types/index.js'; import { type Route } from './fs-router.js'; /** * Code splitting configuration */ export interface CodeSplittingConfig { /** * Whether to enable code splitting */ enabled: boolean; /** * Chunk size threshold in bytes */ chunkSizeThreshold: number; /** * Whether to enable route-based splitting */ routeBasedSplitting: boolean; /** * Whether to enable component-based splitting */ componentBasedSplitting: boolean; /** * Maximum number of chunks */ maxChunks: number; /** * Paths to always include in the main bundle */ alwaysIncludeInMain: string[]; } /** * Chunk information */ export interface ChunkInfo { /** * Chunk ID */ id: string; /** * Chunk name */ name: string; /** * Components in this chunk */ components: string[]; /** * Routes in this chunk */ routes: string[]; /** * Dependencies on other chunks */ dependencies: string[]; /** * Estimated size in bytes */ estimatedSize: number; /** * Whether this is the main chunk */ isMain: boolean; /** * Entry point for this chunk */ entryPoint?: string; } /** * Code splitting result */ export interface CodeSplittingResult { /** * Chunks generated */ chunks: ChunkInfo[]; /** * Import map for dynamic imports */ importMap: Record<string, string>; /** * Lazy loading code */ lazyLoadingCode: string; /** * Errors encountered during code splitting */ errors: OptimizationError[]; /** * Warnings encountered during code splitting */ warnings: OptimizationError[]; } /** * Code splitter for automatic code splitting and lazy loading */ export declare class CodeSplitter { private config; private errors; private warnings; private componentRegistry; private routeRegistry; private dependencyGraph; private chunks; constructor(config?: Partial<CodeSplittingConfig>); /** * Register a component for code splitting analysis */ registerComponent(component: ComponentAST): void; /** * Register multiple components */ registerComponents(components: ComponentAST[]): void; /** * Register routes for route-based code splitting */ registerRoutes(routes: Route[]): void; /** * Analyze dependencies and create chunks */ analyze(): CodeSplittingResult; /** * Get errors encountered during code splitting */ getErrors(): OptimizationError[]; /** * Get warnings encountered during code splitting */ getWarnings(): OptimizationError[]; /** * Reset code splitter state */ private reset; /** * Build dependency graph between components */ private buildDependencyGraph; /** * Extract component dependencies from AST */ private extractComponentDependencies; /** * Create route-based chunks */ private createRouteBasedChunks; /** * Create component-based chunks */ private createComponentBasedChunks; /** * Group components by their dependencies */ private groupComponentsByDependencies; /** * Optimize chunks by merging small chunks and splitting large ones */ private optimizeChunks; /** * Generate import map for dynamic imports */ private generateImportMap; /** * Generate lazy loading code */ private generateLazyLoadingCode; /** * Get dependencies for a chunk */ private getChunkDependencies; /** * Estimate chunk size based on component ASTs */ private estimateChunkSize; /** * Count AST nodes in a component */ private countASTNodes; /** * Count nodes in an HTML element recursively */ private countHTMLElementNodes; /** * Get route directory from path */ private getRouteDirectory; /** * Get component name for a route */ private getRouteComponentName; /** * Sanitize chunk name for file system */ private sanitizeChunkName; } //# sourceMappingURL=code-splitter.d.ts.map