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 10.0.1.10 --baseURL http://10.0.1.10

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 server.sh 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 ./server.sh in the website directory and viola - the site is available on my local Wi-Fi network.

Tags: hugo