A function that will be called when the plugin is loaded.
This function may be called in the same tick that it is registered, or it may be called later. It could potentially be called multiple times for different targets.
Symbol
A function that will be called when the plugin is loaded.
This function may be called in the same tick that it is registered, or it may be called later. It could potentially be called multiple times for different targets.
A builder object that can be used to register plugin hooks
The builder object passed to Bun.plugin
The config object passed to Bun.build
as is. Can be mutated.
Create a lazy-loaded virtual module that can be import
ed or require
d from other modules
The module specifier to register the callback for
The function to run when the module is imported or required
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"
Register a callback to load imports with a specific import specifier
The constraints to apply the plugin to
The callback to handle the import
this
for method chaining
Bun.plugin({
setup(builder) {
builder.onLoad({ filter: /^hello:world$/ }, (args) => {
return { exports: { foo: "bar" }, loader: "object" };
});
},
});
Register a callback to resolve imports matching a filter and/or namespace
The constraints to apply the plugin to
The callback to handle the import
this
for method chaining
Bun.plugin({
setup(builder) {
builder.onResolve({ filter: /^wat$/ }, (args) => {
return { path: "/tmp/woah.js" };
});
},
});
Register a callback which will be invoked when bundling starts. When using hot module reloading, this is called at the start of each incremental rebuild.
this
for method chaining
Bun.plugin({
setup(builder) {
builder.onStart(() => {
console.log("bundle just started!!")
});
},
});