温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/bun/BunPlugin/setup
点击访问原文链接

BunPlugin.setup method | Bun module | Bun

BunPlugin.setup method | Bun module | BunBuildDocsReferenceGuidesBlogDiscord/Bun/BunPlugin/setupMsetup

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/Bun/BunPlugin/setupMsetup

method

BunPlugin.setupsetup(build: PluginBuilder): void | Promisevoid>;

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.

@param build

A builder object that can be used to register plugin hooks

Referenced typesinterface PluginBuilder

The builder object passed to Bun.plugin

config: BuildConfig & { plugins: BunPlugin[] }

The config object passed to Bun.build as is. Can be mutated.

module(specifier: string,callback: () => OnLoadResult | PromiseOnLoadResult>): this;

Create a lazy-loaded virtual module that can be imported or required 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

@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"
onBeforeParse(constraints: PluginConstraints,callback: OnBeforeParseCallback): this;onEnd(callback: OnEndCallback): this;

Register a callback which will be invoked when bundling ends. This is called after all modules have been bundled and the build is complete.

@returns

this for method chaining

const plugin: Bun.BunPlugin = {
name: "my-plugin",
setup(builder) {
builder.onEnd((result) => {
console.log("bundle just finished!!", result);
});
},
};
onLoad(constraints: PluginConstraints,callback: OnLoadCallback): this;

Register a callback to load imports with a specific import specifier

@param constraints

The constraints to apply the plugin to

@param callback

The callback to handle the import

@returns

this for method chaining

Bun.plugin({
setup(builder) {
builder.onLoad({ filter: /^hello:world$/ }, (args) => {
return { exports: { foo: "bar" }, loader: "object" };
});
},
});
onResolve(constraints: PluginConstraints,callback: OnResolveCallback): this;

Register a callback to resolve imports matching a filter and/or namespace

@param constraints

The constraints to apply the plugin to

@param callback

The callback to handle the import

@returns

this for method chaining

Bun.plugin({
setup(builder) {
builder.onResolve({ filter: /^wat$/ }, (args) => {
return { path: "/tmp/woah.js" };
});
},
});
onStart(callback: OnStartCallback): this;

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.

@returns

this for method chaining

Bun.plugin({
setup(builder) {
builder.onStart(() => {
console.log("bundle just started!!")
});
},
});

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

BunPlugin.setup method | Bun module | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for method bun.BunPlugin.setup | Bun