Skip to content

Programmatic Usage

Bunup can be used programmatically in your scripts. This is useful when you need custom build workflows or want to integrate bunup into your own tools.

INFO

The build function must be run in the Bun runtime.

Basic Usage

typescript
import { build } from 'bunup';

await build({
  entry: ['src/index.ts'],
});

Options

The build function accepts the same options as defineConfig. See the Options Guide for detailed documentation of all available options.

For TypeScript users, the BuildOptions type is available:

typescript
import { build, type BuildOptions } from 'bunup';

const options: BuildOptions = {
  entry: ['src/index.ts'],
  format: ['esm', 'cjs'],
};

await build(options);

The full type definition can be found in the bunup source code.

Using Plugins

Plugins can be used programmatically the same way they are used in the configuration file:

typescript
import { build } from 'bunup';
import { injectStyles } from 'bunup/plugins';

await build({
  entry: ['src/index.ts'],
  plugins: [injectStyles({
    minify: true,
    targets: { chrome: 95 }
  })]
});

Released under the MIT License.