Previews and Deployment
There are multiple possible options for deploying a Hugo site, including Netlify, Firebase Hosting, Bitbucket with Aerobatic, and more; you can read about them all in Hosting and Deployment. Hugo also makes it easy to deploy your site locally for quick previews of your content.
Serving your site locally
Depending on your deployment choice you may want to serve your site locally during development to preview content changes. To serve your site locally:
-
Ensure you have an up to date local copy of your site files cloned from your repo. Don’t forget to use
--recurse-submodules
or you won’t pull down some of the code you need to generate a working site.git clone --recurse-submodules --depth 1 https://github.com/my/example.git
Note
If you’ve just added the theme as a submodule in a local version of your site and haven’t committed it to a repo yet, you must get local copies of the theme’s own submodules before serving your site.
git submodule update --init --recursive
-
Ensure you have the tools described in Prerequisites and installation installed on your local machine, including
postcss-cli
(you’ll need it to generate the site resources the first time you run the server). -
Run the
hugo server
command in your site root. By default your site will be available at http://localhost:1313/.
Now that you’re serving your site locally, Hugo will watch for changes to the content and automatically refresh your site. If you have more than one local git branch, when you switch between git branches the local website reflects the files in the current branch.
Deployment with Netlify
We recommend using Netlify as a particularly simple way to serve your site from your Git provider (GitHub, GitLab, or BitBucket), with continuous deployment, previews of the generated site when you or your users create pull requests against the doc repo, and more. Netlify is free to use for Open Source projects, with premium tiers if you require greater support.
Before deploying with Netlify, make sure that you’ve pushed your site source to your chosen GitHub (or other provider) repo, following any setup instructions in Using the theme.
Then follow the instructions in Host on Netlify to set up a Netlify account (if you don’t have one already) and authorize access to your GitHub or other Git provider account. Once you’re logged in:
- Click New site from Git.
- Click your chosen Git provider, then choose your site repo from your list of repos.
- In the Deploy settings page:
- For your Build command, specify
cd themes/docsy && git submodule update -f --init && cd ../.. && hugo
. You need to specify this rather than justhugo
so that Netlify can use the theme’s submodules. - Click Show advanced.
- In the Advanced build settings section, click New variable.
- Specify
HUGO_VERSION
as the Key for the new variable, and0.53
or later as its Value. - (Optional) Click New variable again, and this time set
HUGO_ENV
toproduction
. Do this if you want your site to be indexed by search engines. You must do this if you want to use a Google Custom Search Engine.
- For your Build command, specify
- Click Deploy site.
Note
Netlify uses your site repo’s package.json
file to install any JavaScript dependencies (like postcss
) before building your site. If you haven’t just copied our example site’s version of this file, make sure that you’ve specified all our prerequisites.
For example, if you want to use a version of postcss-cli
later than version 8.0.0, you need to ensure that your package.json
also specifies postcss
separately:
"devDependencies": {
"autoprefixer": "^9.8.6",
"postcss-cli": "^8.0.0",
"postcss": "^8.0.0"
}
Alternatively, you can follow the same instructions but specify your Deploy settings in a netlify.toml
file in your repo rather than in the Deploy settings page. You can see an example of this in the Docsy theme repo (though note that the build command here is a little unusual because the Docsy user guide is inside the theme repo).
If you have an existing deployment you can view and update the relevant information by selecting the site from your list of sites in Netlify, then clicking Site settings - Build and deploy. Ensure that Ubuntu Xenial 16.04 is selected in the Build image selection section - if you’re creating a new deployment this is used by default. You need to use this image to run the extended version of Hugo.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.