How to preview a Hugo site on a mobile phone on a local network (MacOS)

· 1 min read

When developing a theme for a Hugo site, you'll want to see how it looks on mobile phones. If you run a hugo server command and try to navigate to the Mac's IP address from your phone, it won't be resolved and you'll get a server not found error.

To make it work, you need to tell hugo server to bind the your Mac's IP address. You can achieve this by running a command like this.

hugo server --buildDrafts --bind --baseURL

However, it's likely that your IP address is assigned dynamically by the router, so you'll have to modify the command every time you get a new address.

To simplify my workflow, I've created a shell script with the following commands that grab the IP address from ipconfig and pass it on to hugo server.

export IPADDR="$(ipconfig getifaddr en0)"
hugo server --buildDrafts --bind $IPADDR --baseURL http://$IPADDR

To start the server, I simply run ./ in the website directory and viola - the site is available on my local Wi-Fi network.

Tags: hugo