Home >Backend Development >Golang >Step-by-Step Guide to Deploy Hugo on Vercel
This guide will walk you through deploying a Hugo website to Vercel.
I will ensure you avoid at least one common mistake.
Assuming Hugo is already installed:
hugo new site
Then set up a git repository for the site.
git init
Add commit and push your project files:
git add .
git commit
git push -u origin master
For instance, you can use a Nno jQuery, no Bootstrap super fast theme like hugo-blog-awesome:
As a github module:
git submodule add https://github.com/hugo-sid/hugo-blog-awesome.git
Or a Hugo module
hugo mod get github.com/hugo-sid/hugo-blog-awesome
In root dir add vercel.json where we gonna define hugo version Go version and the buildCommand, after defining hugo as Framework Preset in vercel those config will be auto detected.
vercel.json
{ "build": { "env": { "HUGO_VERSION": "0.135.0", "GO_VERSION": "1.19.5" } }, "buildCommand": "hugo --gc --minify" }
- use hugo env to show versions of Go and Hugo you're using
Then push update to Github:
git add .
git commit -m "vercel deploy"
git push -u origin master
During the import process, ensure that the project is connected correctly to your Hugo repository.
Vercel detect env and command build:
Or you ou can set it manually in Vercel environment variables here
Deployement logs:
After a successful build ??, Vercel will provide a preview link where you can view your live Hugo website. You can also configure a custom domain through Vercel's settings for your project.
If you have a domain name you can add the domain name to the vercel in domains section of the project settings. Then add a CNAME to your domain provider to point to the vercel domain.
The main problem is that hugo support is not that good even if vercel already updated their Node image to have Hugo and with default settings, I met with the error of hugo layout not found and my deployment leads to an XML page.
This is because the env parameter Hugo and Go versions need to be defined with in the json file vercel.json
Setting up a personal site with Hugo and Vercel is really easy, despite some minor problems. I hope this post can help you to set up your own site. For more details about the changes I made to the site, see the commit history of my site.
Some Sources:
https://vercel.com/guides/deploying-hugo-with-vercel
https://vercel.com/docs/projects/project-configuration
https://blog.gusibi.site/article/Best-Practices-for-Deploying-Hugo-on-Vercel
The above is the detailed content of Step-by-Step Guide to Deploy Hugo on Vercel. For more information, please follow other related articles on the PHP Chinese website!