Webadev
A web dev server with live reload.
Features
- Serve a static folder with 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, requires a --port)
- Custom IP/port support
- Serve under a URL path prefix
- Add headers
If you need to bundle and serve, check Bundla.
CLI
# serve the current directory
Options
--dir/-d: directory to serve (default:.)--port/-p: port to run on (default: 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 (default: false)--header: additional HTTP header on every response (repeatable; e.g.--header "Access-Control-Allow-Origin: *")--index: default file for directory requests (default:index.html)--base: URL path prefix (default: root; e.g.--base /app). Pages must reference assets relatively (./style.css) or include the prefix (/app/style.css).
Examples
Use with an external API (CORS).
Accessing from another device (LAN) (on mobile/tablets over same WiFi).
# visit: http://<your-local-ip>:9000
Serve under a path prefix /app/.
# visit: http://127.0.0.1:<port>/app/
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).
Set config.base to prefix the path (e.g. /app). Empty string or / serves at the root.
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),Vec<PathBuf: the modified file paths.
3. Advanced: compose with your own axum router
Use the low-level bind and serve:
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:<resolved> (random free port by default)
# update later after source changes
Feature flags
serve(default): the HTTP server (Config,Server,bind,serve).default-features = false: watcher only (watch,ReloadType), disable the server and does not pull Axum as a dependency.
# watcher only, no HTTP server
= { = "0.7", = false }
Similar tools
See docs/similar-tools.md for a comparison table.