BunBundle (bun_bundle v0.1.1)

Copy Markdown View Source

BunBundle installs and runs Bun as an asset bundler for Elixir web apps.

It vendors a small JS bundler taken from its counterpart, the Ruby gem bun_bun_bundle, and runs it under Bun. Bun ships Lightning CSS built in. That covers glob imports, nesting, autoprefixing, and minification without a separate CSS toolchain.

Configuration

config :bun_bundle, version: "1.4.2"

All bundler configuration lives in config/bun.json at your project root. Bun reads it directly. BunBundle does not translate config. The same format is used by the Ruby and Crystal ports.

Global options

  • :version. The expected Bun version.
  • :version_check. Whether to warn on version drift at boot. Defaults to true.
  • :path. Override the path to the Bun binary. By default it is downloaded to _build/bun-<target>.

Usage in Phoenix

# config/dev.exs
config :my_app, MyAppWeb.Endpoint,
  watchers: [
    bun: {BunBundle, :install_and_run, [~w(--dev)]}
  ]

# mix.exs aliases
"assets.setup": ["bun.install --if-missing"],
"assets.build": ["bun"],
"assets.deploy": ["bun --prod", "phx.digest"]

Summary

Functions

Returns the path to the Bun executable.

Returns the version of the installed Bun binary.

Returns the configured Bun version.

Downloads the configured Bun release and installs it under _build/.

Installs Bun if missing, then runs the bundler with args.

Returns the latest Bun version known to this package release.

Runs Bun against the vendored bundler with the given args.

Returns the path to the vendored bake.js entry point.

Functions

bin_path()

Returns the path to the Bun executable.

The executable may not exist yet if install/0 has not been run.

bin_version()

Returns the version of the installed Bun binary.

Returns {:ok, version_string} on success. Returns :error if Bun is not installed or does not respond.

configured_version()

Returns the configured Bun version.

install()

Downloads the configured Bun release and installs it under _build/.

install_and_run(args)

Installs Bun if missing, then runs the bundler with args.

This is the function to call from a Phoenix :watchers list.

latest_version()

Returns the latest Bun version known to this package release.

run(extra_args)

Runs Bun against the vendored bundler with the given args.

Output is streamed to stdio. Returns the exit status.

script_path()

Returns the path to the vendored bake.js entry point.