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 (debounced by 200ms)
- CSS hot-reload (no full page reload)
- Smart script injection (no manual setup needed)
- Auto-reconnect (reloads the page when the server restarts)
- Custom IP/port support
- Add headers
CLI
# serve the current directory
Options
--dir/-d: directory to serve--port/-p: port to run on (default: 8080, use0for a random free port)--ip/-i: IP address to bind to (default: 127.0.0.1, use0.0.0.0to 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: *"--index: default file for directory requests (default:index.html)
Examples
Use with an external API (CORS).
Accessing from another device (LAN) (on mobile/tablets over same WiFi).
# visit: http://<your-local-ip>:9000
Library
From simplest to most control.
1. Static serving
use IpAddr;
use PathBuf;
use ;
let dir: PathBuf = "public".into; // directory to serve
let config = Config ;
let server = new.await?; // binds; url known, not serving yet
println!;
server.run.await?; // blocks until shutdown
Use 0 as config.port to let the OS pick a free port (the chosen port is visible in server.url).
2. With live reload
use IpAddr;
use PathBuf;
use broadcast;
use ;
let dir: PathBuf = ".".into; // directory to watch and serve
let = channel; // keep a receiver alive so watch() can send
watch?;
let config = Config ;
let server = bind.await?; // watches upstream, drives reloads
server.run.await?;
The broadcast channel notifies subscribers of reload events (ReloadType, Vec<PathBuf>):
ReloadType::Css(CSS-only) orReloadType::Page(full reload),- the changed paths.
3. Advanced: merge routes, TLS, graceful shutdown
Use the low-level bind and serve to compose with your own axum router:
use PathBuf;
use broadcast;
use ;
let = channel;
let dir: PathBuf = ".".into;
let config = Config ;
let = bind.await?;
// here you can tweak the axum router
serve.await?;
Local installation
# clone the repo
# build the project
# run the server
# install globally from the local package
# compiles and copies the binary to `~/.cargo/bin/webadev`
# use from anywhere.
# serves the current directory on 127.0.0.1:8080
# update later after source changes