# `Phoenix.ReactServer.Runtime.Bun`
[🔗](https://github.com/mfreeman451/phoenix-react-ng/blob/v0.8.5/lib/phoenix/react_server/runtime/bun.ex#L1)

Bun runtime for Phoenix.ReactServer server.

This runtime uses Bun as the JavaScript runtime for rendering React components.
Bun provides fast startup times and excellent performance for server-side rendering.

## Configuration

Configure in `runtime.exs`:

```elixir
import Config

config :phoenix_react_ng, Phoenix.ReactServer.Runtime.Bun,
  cd: File.cwd!(),
  cmd: System.find_executable("bun"),
  # In dev mode, the server_js will be watched and recompiled when changed
  # In prod mode, this needs to be precompiled with `mix phx.react.bun.bundle`
  server_js: Path.expand("bun/server.js", :code.priv_dir(:phoenix_react_ng)),
  port: 5225,
  env: :dev
```

## Configuration Options

- `:cd` - Working directory for the Bun process (default: current directory)
- `:cmd` - Path to Bun executable (default: system `bun` command)
- `:server_js` - Path to the bundled server JavaScript file
- `:port` - Port for the Bun HTTP server (default: 5225)
- `:env` - Environment mode (`:dev` or `:prod`, default: `:dev`)

## Development Mode

In development mode (`env: :dev`), the runtime will:
- Start a file watcher for component changes
- Automatically rebuild the server bundle when components change
- Enable hot reloading for React components

## Production Mode

In production mode (`env: :prod`), you must pre-bundle the components:

```bash
mix phx.react.bun.bundle --component-base=assets/component --output=priv/react/server.js
```

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `start_link`

```elixir
@spec start_link(term()) :: GenServer.on_start()
```

Starts the Bun runtime server.

## Parameters

- `init_arg` - Initialization arguments (typically `[]`)

## Returns

- `{:ok, pid}` - Runtime started successfully
- `{:error, reason}` - Failed to start runtime

---

*Consult [api-reference.md](api-reference.md) for complete listing*
