Pfiles
Bun

property

BuildConfigBase.files

files?: Record<string, string | ArrayBufferLike | TypedArray<ArrayBufferLike> | Blob>

A map of file paths to their contents for in-memory bundling.

This allows you to bundle virtual files that don't exist on disk, or override the contents of files that do exist on disk. The keys are file paths (which should match how they're imported) and the values are the file contents.

File contents can be provided as:

  • string - The source code as a string
  • Blob - A Blob containing the source code
  • NodeJS.TypedArray - A typed array (e.g., Uint8Array) containing the source code
  • ArrayBufferLike - An ArrayBuffer containing the source code
// Bundle entirely from memory (no files on disk needed)
await Bun.build({
  entrypoints: ["/app/index.ts"],
  files: {
    "/app/index.ts": `
      import { helper } from "./helper.ts";
      console.log(helper());
    `,
    "/app/helper.ts": `
      export function helper() {
        return "Hello from memory!";
      }
    `,
  },
});