method

bun.__internal.ImportMetaGlob.glob

glob<TModule = unknown>(
pattern: string | string[],
options?: ImportMetaGlobOptions & { eager: false }
): Record<string, () => Promise<TModule>>;

Import every module that matches a glob pattern. Compatible with Vite's import.meta.glob.

Bun's transpiler and bundler replace the call with an object literal, so the arguments must be literals.

const pages = import.meta.glob("./pages/*.tsx");
// {
//   "./pages/about.tsx": () => import("./pages/about.tsx"),
//   "./pages/home.tsx": () => import("./pages/home.tsx"),
// }
glob<TModule = unknown>(
pattern: string | string[],
options: ImportMetaGlobOptions & { eager: true }
): Record<string, TModule>;
const pages = import.meta.glob("./pages/*.tsx", { eager: true });
// import * as about from "./pages/about.tsx";
// import * as home from "./pages/home.tsx";
// { "./pages/about.tsx": about, "./pages/home.tsx": home }