webadev 0.1.1

A tiny web dev server with live reload
webadev-0.1.1 is not a library.
Visit the last successful build: webadev-0.12.0

Webadev

A tiny web dev server with live reload, written in Rust.

Features

  • Serve a static folder (HTML/CSS/JS)
  • Live reload in the browser on file change
  • Smart script injection (no manual setup needed)
  • Auto-reconnect (reloads the page when the server restarts)
  • Custom IP/port support

Usage

Install and run from cargo.

cargo install webadev

# serve the html file in current directory
webadev

Options

  • --dir / -d: directory to serve
  • --port / -p: port to run on (default: 8080, use 0 for a random free port)
  • --ip / -i: IP address to bind to (default: 127.0.0.1, use 0.0.0.0 to access from other devices)
  • --open / -o: open the page in the browser on start (false by default; live reload keeps an already-open tab in sync across restarts)
  • --header: additional HTTP header on every response (repeatable), e.g. --header "Access-Control-Allow-Origin: *"

Examples

Use with an external API (CORS).

webadev --header "Access-Control-Allow-Origin: http://localhost:5173"

Accessing from another device (LAN) (on mobile/tablets over same WiFi).

./target/release/webadev --dir ./client --port 9000 --ip 0.0.0.0

# visit: http://<your-local-ip>:9000

Local installation

1. Clone the repo

git clone https://github.com/francoisromain/webadev.git
cd webadev

2. Build the project

cargo build --release

3. Run the server

./target/release/webadev --dir ./client --header "Access-Control-Allow-Origin: *"

Install globally from the local package

cargo install --path . --locked

This compiles and copies the binary to ~/.cargo/bin/webadev.

Use from anywhere.

cd ~/some/project
webadev            # serves the current directory on 127.0.0.1:8080

Update later after source changes.

cargo install --path . --locked --force

Similar tools

Inspiration

This project was inspired by rust-live-server by Kartik Mehta. Thank you!

It's a full re-write. The main changes are:

  • Replace Warp with Axum
  • Replace WebSocket with SSE/eventsource
  • Add features to the server: reconnect and reload-on-reconnect, header option.
  • Add features to the watcher: debounce, path dedup, kind/extension filtering.
  • Fixes: fall back to index for empty URL, serve non-UTF8 HTML, bind-first and report real port, open browser by default.
  • CLI: use clap crate parser.
  • Tests: add unit tests on watcher and server, plus e2e tests.