/** * @file Runtime Bundle Analysis * @description Runtime utilities for analyzing bundle composition, chunk loading, * and module dependencies. Helps identify optimization opportunities. * * Features: * - Chunk loading analysis * - Module dependency tracking * - Bundle size estimation * - Dynamic import monitoring * - Resource timing analysis * - Code splitting recommendations */ /** * Bundle chunk information */ export interface ChunkInfo { id: string; name: string; size: number; loadTime: number; dependencies: string[]; isAsync: boolean; isEntry: boolean; loadedAt: number; modules: ModuleInfo[]; } /** * Module information */ export interface ModuleInfo { id: string; name: string; size: number; importedBy: string[]; imports: string[]; isExternal: boolean; } /** * Bundle analysis report */ export interface BundleAnalysisReport { totalSize: number; chunks: ChunkInfo[]; largestChunks: ChunkInfo[]; slowestChunks: ChunkInfo[]; duplicateModules: string[]; recommendations: BundleRecommendation[]; timestamp: number; } /** * Bundle optimization recommendation */ export interface BundleRecommendation { type: 'split' | 'combine' | 'lazy' | 'preload' | 'remove' | 'dedupe'; priority: 'high' | 'medium' | 'low'; target: string; message: string; estimatedSavings?: number; } /** * Resource timing entry */ export interface ResourceTimingEntry { name: string; entryType: string; startTime: number; duration: number; transferSize: number; encodedBodySize: number; decodedBodySize: number; initiatorType: string; cached: boolean; } /** * Dynamic import tracking entry */ export interface DynamicImportEntry { modulePath: string; chunkName: string | null; startTime: number; endTime: number; duration: number; success: boolean; error?: string; } /** * Bundle analyzer configuration */ export interface BundleAnalyzerConfig { /** Enable analysis */ enabled: boolean; /** Track dynamic imports */ trackDynamicImports: boolean; /** Track resource timing */ trackResourceTiming: boolean; /** Large chunk threshold in bytes */ largeChunkThreshold: number; /** Slow chunk threshold in ms */ slowChunkThreshold: number; /** Enable recommendations */ generateRecommendations: boolean; /** Debug mode */ debug: boolean; } /** * Runtime bundle analyzer */ export declare class BundleAnalyzer { private config; private chunks; private dynamicImports; private resourceObserver; constructor(config?: Partial); /** * Start analyzing bundles */ start(): void; /** * Stop analyzing */ stop(): void; /** * Track a dynamic import */ trackDynamicImport(modulePath: string, importPromise: Promise): Promise; /** * Get bundle analysis report */ getReport(): BundleAnalysisReport; /** * Get resource timing data */ getResourceTiming(): ResourceTimingEntry[]; /** * Get dynamic import history */ getDynamicImports(): DynamicImportEntry[]; /** * Clear analysis data */ clear(): void; /** * Analyze a specific chunk */ analyzeChunk(chunkId: string, options?: Partial): ChunkInfo; private startResourceTracking; private analyzeInitialBundles; private processResourceEntry; private isJavaScriptResource; private extractChunkId; private extractChunkName; private findDuplicateModules; private generateRecommendations; private log; } /** * Create a tracked dynamic import function */ export declare function createTrackedImport(analyzer: BundleAnalyzer): (importFn: () => Promise, modulePath: string) => Promise; /** * Format bytes to human-readable string */ export declare function formatBytes(bytes: number): string; /** * Calculate bundle budget status */ export declare function checkBundleBudget(size: number, budget: number): { status: 'ok' | 'warning' | 'exceeded'; percent: number; }; /** * Get or create the global bundle analyzer instance */ export declare function getBundleAnalyzer(config?: Partial): BundleAnalyzer; /** * Reset the analyzer instance */ export declare function resetBundleAnalyzer(): void;