devserve

command module
v0.0.0-...-7fabb54 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2025 License: MIT Imports: 13 Imported by: 0

README

devserve: A tiny webserver with live- and hot-reload

devserve is a small development webserver with built-in live-reloading for HTML files.

Features

  • Serve static files from specified directory (or CWD by default)
  • Watch files for changes
  • Automatically reload HTML files
  • Hot-reload CSS changes (no page reload)

How does it work?

HTML files are served with this script injected just before </body>. It sets up the page to listen for server-sent events on /events

The server watches files for any changes and notifies via event: change events on the /events endpoint.

Any other files and directories are served by http.ServeFile directly.

Installation

$ go install github.com/czak/devserve@latest

Usage

By default devserve will serve files from current directory on :8080:

$ devserve
2025/03/27 16:00:34 Serving files from "." on ":8080"

Directory and address can be overridden with -dir and -addr respectively:

$ devserve -dir public -addr "127.0.0.1:3000"
2025/03/27 16:01:25 Serving files from "public" on "127.0.0.1:3000"

All flags:

$ devserve -h
Usage of devserve:
  -addr string
        network address (default ":8080")
  -dir string
        directory to serve from (default ".")

Notes

  • Should work on all Go platforms, but only tested on Linux

References

CSS hot reloading code was taken from https://esbuild.github.io/api/#hot-reloading-css

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL