Analyze and debug space usage through source maps
—
Core functionality for analyzing JavaScript bundles through source maps, supporting multiple input formats and providing detailed size breakdowns.
Analyzes bundle(s) and returns comprehensive exploration results with file size breakdowns.
/**
* Analyze bundle(s) and return exploration results
* @param bundlesAndFileTokens - Bundle input (file paths, globs, Bundle objects, or arrays)
* @param options - Configuration options for analysis
* @returns Promise resolving to analysis results
*/
function explore(
bundlesAndFileTokens: BundlesAndFileTokens,
options?: ExploreOptions
): Promise<ExploreResult>;
type BundlesAndFileTokens = (Bundle | string)[] | Bundle | string;Usage Examples:
import { explore } from "source-map-explorer";
// Single file analysis
const result = await explore("dist/bundle.js");
// Multiple files using glob
const result = await explore("dist/*.js");
// Explicit bundle with separate source map
const result = await explore({
code: "dist/bundle.js",
map: "dist/bundle.js.map"
});
// Multiple bundles mixed formats
const result = await explore([
"dist/main.js",
{ code: "dist/chunk.js", map: "dist/chunk.js.map" },
"dist/vendor.*"
]);
// Using Buffer data
const codeBuffer = fs.readFileSync("bundle.js");
const result = await explore({ code: codeBuffer });The main explore function handles all bundle processing internally, including:
All bundle processing logic is encapsulated within the explore function and does not expose separate utility functions for external use.
interface Bundle {
/** JavaScript code as file path or Buffer */
code: File;
/** Optional source map as file path or Buffer */
map?: File;
/** Optional coverage ranges for heat map visualization */
coverageRanges?: ColumnsRange[][];
}
type File = string | Buffer;
interface ColumnsRange {
/** First column index (inclusive) */
start: number;
/** Last column index (inclusive) */
end: number;
}Source Map Explorer supports flexible input patterns:
"dist/bundle.js" - Looks for inline source map or bundle.js.map"dist/*.js" - Processes all matching files{ code: "path.js", map: "path.js.map" } - Explicit source map{ code: fs.readFileSync("bundle.js") } - In-memory analysisThe analysis engine automatically detects source maps through multiple methods:
sourceMappingURL commentssourceMappingURL comments pointing to .map filesfilename.js.map when analyzing filename.jsmap propertyExamples:
// Inline source map (automatically detected)
const result = await explore("bundle-with-inline-map.js");
// External source map (automatically found)
const result = await explore("bundle.js"); // Looks for bundle.js.map
// Explicit source map
const result = await explore({
code: "bundle.js",
map: "custom-map-name.map"
});
// No source map comment, but map file exists
const result = await explore({
code: "no-comment.js",
map: "no-comment.js.map"
});The bundle analysis follows these steps:
gzip: true calculates compressed sizes but disables unmapped byte calculationInstall with Tessl CLI
npx tessl i tessl/npm-source-map-explorer