diff options
Diffstat (limited to 'packages/bun-types/bun.d.ts')
-rw-r--r-- | packages/bun-types/bun.d.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/packages/bun-types/bun.d.ts b/packages/bun-types/bun.d.ts index 514a6bbdb..9b2d314e8 100644 --- a/packages/bun-types/bun.d.ts +++ b/packages/bun-types/bun.d.ts @@ -3293,6 +3293,37 @@ declare module "bun" { * The config object passed to `Bun.build` as is. Can be mutated. */ config: BuildConfig & { plugins: BunPlugin[] }; + + /** + * Create a lazy-loaded virtual module that can be `import`ed or `require`d from other modules + * + * @param specifier The module specifier to register the callback for + * @param callback The function to run when the module is imported or required + * + * ### Example + * @example + * ```ts + * Bun.plugin({ + * setup(builder) { + * builder.module("hello:world", () => { + * return { exports: { foo: "bar" }, loader: "object" }; + * }); + * }, + * }); + * + * // sometime later + * const { foo } = await import("hello:world"); + * console.log(foo); // "bar" + * + * // or + * const { foo } = require("hello:world"); + * console.log(foo); // "bar" + * ``` + */ + module( + specifier: string, + callback: () => OnLoadResult | Promise<OnLoadResult>, + ): void; } interface BunPlugin { |