UNPKG

@module-federation/vite

Version:
76 lines (75 loc) 3.12 kB
export type OutputBundleItem = { type: 'chunk' | 'asset'; name?: string; fileName: string; modules?: Record<string, unknown> | undefined; dynamicImports?: string[] | undefined; }; export declare const ASSET_TYPES: readonly ["js", "css"]; export declare const LOAD_TIMINGS: readonly ["sync", "async"]; export declare const JS_EXTENSIONS: readonly [".ts", ".tsx", ".jsx", ".mjs", ".cjs"]; export type AssetType = (typeof ASSET_TYPES)[number]; export type AssetMap = { sync: string[]; async: string[]; }; export type PreloadMap = Record<string, { [K in (typeof ASSET_TYPES)[number]]: AssetMap; }>; /** * Creates an empty asset map structure for tracking JS and CSS assets * @returns Initialized asset map with sync/async arrays for JS and CSS */ export declare const createEmptyAssetMap: () => { js: AssetMap; css: AssetMap; }; /** * Tracks an asset in the preload map with deduplication * @param map - The preload map to update * @param key - The module key to track under * @param fileName - The asset filename to track * @param isAsync - Whether the asset is loaded async * @param type - The asset type ('js' or 'css') */ export declare const trackAsset: (map: PreloadMap, key: string, fileName: string, isAsync: boolean, type: AssetType) => void; /** * Checks if a file is a CSS file by extension * @param fileName - The filename to check * @returns True if file has a CSS extension (.css, .scss, .less) */ export declare const isCSSFile: (fileName: string) => boolean; /** * Collects all CSS assets from the bundle * @param bundle - The Rollup output bundle * @returns Set of CSS asset filenames */ export declare const collectCssAssets: (bundle: Record<string, OutputBundleItem>) => Set<string>; /** * Processes module assets and tracks them in the files map * @param bundle - The Rollup output bundle * @param filesMap - The preload map to populate * @param moduleMatcher - Function that matches module paths to keys */ export declare const processModuleAssets: (bundle: Record<string, OutputBundleItem>, filesMap: PreloadMap, moduleMatcher: (modulePath: string) => string | undefined) => void; /** * Adds global CSS assets to all module exports * @param filesMap - The preload map to update * @param cssAssets - Set of CSS asset filenames to add */ export declare const addCssAssetsToAllExports: (filesMap: PreloadMap, cssAssets: Set<string>) => void; /** * Deduplicates assets in the files map * @param filesMap - The preload map to deduplicate * @returns New deduplicated preload map */ export declare const deduplicateAssets: (filesMap: PreloadMap) => PreloadMap; /** * Builds a mapping between module files and their share keys * @param shareKeys - Set of share keys to map * @param resolveFn - Function to resolve module paths * @returns Map of file paths to their corresponding share keys */ export declare const buildFileToShareKeyMap: (shareKeys: Set<string>, resolveFn: (id: string) => Promise<{ id: string; } | null>) => Promise<Map<string, string>>;