Files
rules_bun/docs/index.md
eric 7139aa3ba2
Some checks failed
CI / test (macos-14, darwin-arm64) (push) Has been cancelled
CI / test (windows-latest, windows) (push) Has been cancelled
CI / test (ubuntu-latest, linux-x64) (push) Has been cancelled
Docs Pages / deploy (push) Failing after 42s
fix: bun_install adds node_modules to each directory
2026-03-06 21:44:15 +01:00

2.0 KiB

rules_bun docs

Documentation for rules_bun, a Bazel ruleset for Bun.

Ruleset layout

The repository exposes its public Bazel API from the bun/ package:

  • @rules_bun//bun:defs.bzl for build rules
  • @rules_bun//bun:extensions.bzl for Bzlmod extensions
  • @rules_bun//bun:repositories.bzl for legacy WORKSPACE setup

Supporting material lives in:

Rule reference

Bzlmod extensions

Typical Bzlmod setup

bazel_dep(name = "rules_bun", version = "0.2.1")

bun_ext = use_extension("@rules_bun//bun:extensions.bzl", "bun")

use_repo(
	bun_ext,
	"bun_linux_x64",
	"bun_linux_aarch64",
	"bun_darwin_x64",
	"bun_darwin_aarch64",
	"bun_windows_x64",
)

register_toolchains(
	"@rules_bun//bun:darwin_aarch64_toolchain",
	"@rules_bun//bun:darwin_x64_toolchain",
	"@rules_bun//bun:linux_aarch64_toolchain",
	"@rules_bun//bun:linux_x64_toolchain",
	"@rules_bun//bun:windows_x64_toolchain",
)

Vite package scripts

Use bun_script for package-script driven workflows such as dev, build, and preview.

The node_modules label below refers to dependencies installed by bun_install.

load("@rules_bun//bun:defs.bzl", "bun_script")

bun_script(
	name = "web_dev",
	script = "dev",
	package_json = "package.json",
	node_modules = "@my_workspace//:node_modules",
	data = glob([
		"src/**",
		"public/**",
		"index.html",
		"vite.config.*",
		"tsconfig*.json",
	]),
)

bun_script runs from the package directory by default and adds node_modules/.bin to PATH.

Regeneration

The rule reference is generated from the public Starlark symbols in @rules_bun//bun:defs.bzl:

bazel build //docs:rules_md
cp bazel-bin/docs/rules.md docs/rules.md