mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-16 08:08:06 -04:00
131 lines
4.0 KiB
Markdown
131 lines
4.0 KiB
Markdown
---
|
|
title: Host on Netlify
|
|
description: Host your site on Netlify.
|
|
categories: []
|
|
keywords: []
|
|
aliases: [/hosting-and-deployment/hosting-on-netlify/]
|
|
---
|
|
|
|
Use these instructions to enable continuous deployment from a GitHub repository. The same general steps apply if you are using Azure DevOps, Bitbucket, or GitLab for version control.
|
|
|
|
## Prerequisites
|
|
|
|
Please complete the following tasks before continuing:
|
|
|
|
1. [Create](https://app.netlify.com/signup) a Netlify account
|
|
1. [Log in](https://app.netlify.com/login) to your Netlify account
|
|
1. [Create](https://github.com/signup) a GitHub account
|
|
1. [Log in](https://github.com/login) to your GitHub account
|
|
1. [Create](https://github.com/new) a GitHub repository for your project
|
|
1. [Create](https://git-scm.com/docs/git-init) a local Git repository for your project with a [remote](https://git-scm.com/docs/git-remote) reference to your GitHub repository
|
|
1. Create a Hugo site within your local Git repository and test it with the `hugo server` command
|
|
1. Commit the changes to your local Git repository and push to your GitHub repository.
|
|
|
|
## Procedure
|
|
|
|
Step 1
|
|
: Log in to your Netlify account, navigate to the Sites page, press the **Add new site** button, and choose "Import an existing project" from the dropdown menu.
|
|
|
|
Step 2
|
|
: Select your deployment method.
|
|
|
|

|
|
|
|
Step 3
|
|
: Authorize Netlify to connect with your GitHub account by pressing the **Authorize Netlify** button.
|
|
|
|

|
|
|
|
Step 4
|
|
: Press the **Configure Netlify on GitHub** button.
|
|
|
|

|
|
|
|
Step 5
|
|
: Install the Netlify app by selecting your GitHub account.
|
|
|
|

|
|
|
|
Step 6
|
|
: Press the **Install** button.
|
|
|
|

|
|
|
|
Step 7
|
|
: Click on the site's repository from the list.
|
|
|
|

|
|
|
|
Step 8
|
|
: Set the site name and branch from which to deploy.
|
|
|
|

|
|
|
|
Step 9
|
|
: Define the build settings, press the **Add environment variables** button, then press the **New variable** button.
|
|
|
|

|
|
|
|
Step 10
|
|
: Create a new environment variable named `HUGO_VERSION` and set the value to the [latest version](https://github.com/gohugoio/hugo/releases/latest).
|
|
|
|

|
|
|
|
Step 11
|
|
: Press the "Deploy my new site" button at the bottom of the page.
|
|
|
|

|
|
|
|
Step 12
|
|
: At the bottom of the screen, wait for the deploy to complete, then click on the deploy log entry.
|
|
|
|

|
|
|
|
Step 13
|
|
: Press the **Open production deploy** button to view the live site.
|
|
|
|

|
|
|
|
## Configuration file
|
|
|
|
In the procedure above we configured our site using the Netlify user interface. Most site owners find it easier to use a configuration file checked into source control.
|
|
|
|
Create a new file named `netlify.toml` in the root of your project directory. In its simplest form, the configuration file might look like this:
|
|
|
|
```toml {file="netlify.toml"}
|
|
[build.environment]
|
|
GO_VERSION = "1.24.5"
|
|
HUGO_VERSION = "0.148.2"
|
|
NODE_VERSION = "22.18.0"
|
|
TZ = "Europe/Oslo"
|
|
|
|
[build]
|
|
publish = "public"
|
|
command = """\
|
|
git config core.quotepath false && \
|
|
hugo --gc --minify --baseURL "${URL}"
|
|
"""
|
|
```
|
|
|
|
If your site requires Dart Sass to transpile Sass to CSS, the configuration file should look something like this:
|
|
|
|
```toml {file="netlify.toml"}
|
|
[build.environment]
|
|
DART_SASS_VERSION = "1.90.0"
|
|
GO_VERSION = "1.24.5"
|
|
HUGO_VERSION = "0.148.2"
|
|
NODE_VERSION = "22.18.0"
|
|
TZ = "Europe/Oslo"
|
|
|
|
[build]
|
|
publish = "public"
|
|
command = """\
|
|
curl -sLJO "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" && \
|
|
tar -C "${HOME}/.local" -xf "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" && \
|
|
rm "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" && \
|
|
export PATH="${HOME}/.local/dart-sass:${PATH}" && \
|
|
git config core.quotepath false && \
|
|
hugo --gc --minify --baseURL "${URL}"
|
|
"""
|
|
```
|