Bun

interface

BuildOutput

interface BuildOutput

The output of a build

  • logs: BuildMessage | ResolveMessage[]
  • metafile?: BuildMetafile

    Metadata 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 format
    • outputs: All generated output files, their byte sizes, which inputs contributed to each output, imports between chunks, and exports

    This can be used for:

    • Bundle size analysis and visualization
    • Detecting unused code or dependencies
    • Understanding the dependency graph
    • Integration with 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));
    }
    
  • success: boolean