Create a lazy-loaded virtual module that can be import
ed or require
d from other modules
method
PluginBuilder.module
specifier: string,
): this;
@param specifier
The module specifier to register the callback for
@param callback
The function to run when the module is imported or required
@returns
this
for method chaining
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"