devserver

command module
v0.0.0-...-e91959e Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2024 License: MIT Imports: 27 Imported by: 0

README

devserver

devserver is a reverse proxy and build server for web applications.

Features

  • Rebuild and restart when you hit Enter.
  • Live reload on restarts and file changes
  • Hot-reloading for CSS files: CSS files used via a <link> tag are updated in place without reloading the page.

Installation

go install github.com/tmichel/devserver@latest

Under the hood devserver uses fswatch for monitoring file changes.

To install fswatch on macOS run the following

brew install fswatch

Detailed install instructions can be found in fswatch's README.

Usage

For details run

devserver -h
Example
cd /path/to/your/project
devserver \
    -build-cmd "go build -o bin/my-app"  \
    -server-cmd "bin/my-app -addr {}" \
    -web-root $PWD/files
# visit http://localhost:8080

-build-cmd defines the build command. Defaults to make. Set it to an empty string to skip the build.

-server-cmd defines the command for starting the server. Use {} as a placeholder for the host and port. It is passed in the format of host:port.

-web-root sets the root directory for files served by your web server. It is used to compute absolute URLs for files. For example when -web-root /path/to/web-root is set the file located at /path/to/web-root/css/style.css will be reported as /css/style.css. This allows hot reloading CSS files.

Example: using go run

Sometimes building and running are not separate. For example when using go run to build and execute your program there is no separate build step. In these situations you can specify -build-cmd="" to skip the build.

cd /path/to/your/project
devserver \
    -build-cmd "" \
    -server-cmd "go run . -addr {}"  \
    -web-root $PWD/files
# visit http://localhost:8080

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