Ffeature
Bun

function

bundle.feature

function feature(
flag: string
): boolean;

Check if a feature flag is enabled at compile time.

This function is replaced with a boolean literal (true or false) at bundle time, enabling dead-code elimination. The bundler will remove unreachable branches.

@param flag

The name of the feature flag to check

@returns

true if the flag was passed via --feature=FLAG, false otherwise

import { feature } from "bun:bundle";

// With --feature=DEBUG, this becomes: if (true) { ... }
// Without --feature=DEBUG, this becomes: if (false) { ... }
if (feature("DEBUG")) {
  console.log("Debug mode enabled");
}