property
BuildOutput.metafile
metafile?: BuildMetafile
Metadata about the build:
- inputs: every bundled source file with its byte size, imports, and format
- outputs: every generated file with its byte size, the inputs that contributed to it, imports between chunks, and exports
Only present when BuildConfig.metafile is true.
Use it for bundle size analysis, inspecting the dependency graph, or as input to bundle analyzer tools.
const 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));
}