Deploy Hugo Website with Surge for Free
Surge is static web publishing for Web Developers, right from the CLI.
Install Surge CLI⌗
npm install -g surge
Deploy with Surge⌗
Navigate to the public
folder generated by Hugo CLI.
surge
The site, by default, will hosted on a sub domain of surge.sh
.
Deploy Changes⌗
surge --domain <your-site>.surge.sh
If the same domain name is not provided, another random sub domain will be prompted by Surge CLI which has to changed to original for each deployment.
Custom Domain⌗
A CNAME
record has be added to your domain or sub domain and by setting the hostname to:
na-west1.surge.sh
Site can now be deployed on the new custom domain.
surge --domain <your-site.your-domain.com>
Script⌗
All these steps can be added to a script for easy deployment. A script named deploy.sh
can be created in the root folder of Hugo project with below contents.
This script will build the Hugo site and deploy it on the given domain.
hugo
surge --domain <your-site.your-domain.com> ./public
Appropriate permissions has be set to make it executable.
sudo chmod 755 ./deploy.sh
Easy Deploy
./deploy.sh