property metafile | Bun module | Bun
BuildDocsReferenceGuidesBlogDiscord/
Bun/
BuildOutput/
metafilePmetafile
Search the reference...
/
BuildDocsReferenceGuidesBlogDiscord/
Bun/
BuildOutput/
metafilePmetafile
property
BuildOutput.metafilemetafile?:
BuildMetafileMetadata about the build including inputs, outputs, and their relationships.
Only present when BuildConfig.metafile is true.
The metafile contains detailed information about:
inputs: All source files that were bundled, their byte sizes, imports, and formatoutputs: All generated output files, their byte sizes, which inputs contributed to each output, imports between chunks, and exportsThis can be used for:
Bundle size analysis and visualizationDetecting unused code or dependenciesUnderstanding the dependency graphIntegration with bundle analyzer toolsconst result = await Bun.build({
entrypoints: ['./src/index.ts'],
outdir: './dist',
metafile: true,
});
if (result.metafile) {
// Analyze input files
for (const [path, input] of Object.entries(result.metafile.inputs)) {
console.log(`${path}: ${input.bytes} bytes, ${input.imports.length} imports`);
}
// Analyze output files
for (const [path, output] of Object.entries(result.metafile.outputs)) {
console.log(`${path}: ${output.bytes} bytes`);
for (const [inputPath, info] of Object.entries(output.inputs)) {
console.log(` - ${inputPath}: ${info.bytesInOutput} bytes`);
}
}
// Write to disk for external analysis tools
await Bun.write('./dist/meta.json', JSON.stringify(result.metafile));
}
Resources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlog Toolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco
We're hiring →