LinuxCommandLibrary

hugo-server

Serve Hugo website locally for preview

TLDR

Build and serve a site

$ hugo server
copy

Build and serve a site on a specified port number
$ hugo server [[-p|--port]] [port_number]
copy

Build and serve a site while minifying supported output formats (HTML, XML, etc.)
$ hugo server --minify
copy

Build and serve a site in the production environment with full re-renders while minifying supported formats
$ hugo server [[-e|--environment]] [production] --disableFastRender --minify
copy

Display help
$ hugo server [[-h|--help]]
copy

SYNOPSIS

hugo server [options]

PARAMETERS

-D, --buildDrafts
    Include content marked as drafts in the build.

-F, --buildFuture
    Include content with a future publication date.

-E, --buildExpired
    Include content past its expiration date.

-w, --watch
    Watch for changes to files and rebuild the site (default behavior).

-p, --port number
    Specify the port for the server to listen on (default: 1313).

--bind address
    IP address to bind to (default: 127.0.0.1).

-s, --source path
    Filesystem path to read files relative from; defaults to current working directory.

-t, --theme name
    Name of the theme to use (located in the themes directory).

-b, --baseURL url
    Hostname and path to the root, e.g., "http://localhost:1313/". Used for internal links.

--disableLiveReload
    Disable automatic browser refresh on file changes, but still rebuilds the site.

--noHTTPCache
    Disable HTTP caching for development (useful for debugging).

--cleanDestinationDir
    Remove files from the public (destination) directory before building.

--config file
    Path to the config file (e.g., config.toml, config.yaml). Can be a comma-separated list.

DESCRIPTION

hugo-server is a subcommand of the Hugo static site generator, primarily used for local development and previewing of Hugo-generated websites. It starts a lightweight web server that serves the generated static files from the public directory. Its most powerful feature is LiveReload, which automatically rebuilds the site and refreshes the browser whenever changes are detected in the source content, templates, or configuration files. This significantly accelerates the development workflow by providing immediate feedback.

The command handles various content states, allowing developers to include drafts, future-dated, or expired content during development. It can be configured to listen on specific ports and IP addresses, making it flexible for different development setups. Unlike hugo build, hugo-server keeps running, continuously monitoring files and serving the site, making it an indispensable tool for interactive development.

CAVEATS

hugo-server is optimized for local development and previewing. It is not suitable for production deployment due to its simplicity, lack of advanced security features, and limited performance compared to dedicated web servers like Nginx or Apache.

LiveReload, while powerful, might occasionally have issues with very large sites, complex JavaScript, or specific browser extensions.

LIVERELOAD

hugo-server implements a powerful LiveReload feature. It automatically detects changes to content files, templates, and configuration, triggers a quick rebuild of the site, and then sends a signal to the browser tab to refresh, providing instant feedback during development.

DEFAULT PORT

By default, hugo-server listens on port 1313. If this port is already in use, it will automatically attempt to find and use the next available port, typically 1314, 1315, and so on.

HISTORY

Hugo was first released in 2013, written in Go. Its server subcommand has been a core feature from early on, designed to provide a fast and efficient local development experience with its integrated live-reloading capabilities. This emphasis on developer experience, alongside Hugo's speed and flexibility, has been a key factor in its widespread adoption as a leading static site generator.

SEE ALSO

hugo(1), hugo build(1), nginx(8), apache2(8)

Copied to clipboard