BunPlugin

Bun

Symbol

BunPlugin

interface BunPlugin

A Bun plugin. Used for extending Bun's behavior at runtime, or with Bun.build

  • name: string

    Human-readable name of the plugin

    In a future version of Bun, this will be used in error messages.

  • target?: Target

    The target JavaScript environment the plugin should be applied to.

    • bun: The default environment when using bun run or bun to load a script
    • browser: The plugin will be applied to browser builds
    • node: The plugin will be applied to Node.js builds

    If unspecified, it is assumed that the plugin is compatible with all targets.

    This field is not read by Bun.plugin, only Bun.build and bun build

  • setup(build: PluginBuilder): void | Promise<void>

    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