tyco
1
Following a discussion on hosting Hugo on a Cloudflare worker, @jmooring came up with an excellent solution.
Here’s an example project hosted on a Cloudflare Worker:
This is the build script:
And the wrangler.toml file
Those are the only two files you need to copy to your project and configure to your liking. For example–
- change Dart SASS version or if you don’t transpile SASS to CSS, you can remove Dart SASS code from the
build.sh file.
- change the time zone.
- change Hugo version
- change Node JS version
I was able to get the deployment working without a custom build script by using the following simplified wrangler.jsonc configuration:
{
"name": "example-com",
"compatibility_date": "2025-07-20",
"assets": {
"directory": "./public",
"html_handling": "auto-trailing-slash",
"not_found_handling": "404-page",
"run_worker_first": false
},
"build": {
"command": "hugo build --gc --minify",
},
"workers_dev": true,
"preview_urls": true
}
Not sure it will work for every environment as I have mine themes defined in go modules
tyco
3
This example is shared by a Hugo support/maintainer person. So, for a user, it is the way I would recommend to go with.
The build script:
- Installs a specific version of Hugo
- Installs a specific version of Dart Sass to transpile Sass to CSS
- Sets the system timezone
- Ensures that
Page.GitInfo returns the expected results
- Addresses https://github.com/gohugoio/hugo/issues/9810
In my view all but #2 are required for every site.
1 Like
@jmooring Hi Jo I had a go with your build.sh script but fails.
I get this in the cloudflare worker build logs:
stderr: ‘/bin/sh: 1: ./build.sh: Permission denied’,
Have I missed something real simple?
tyco
6
Doh!
I I did a
git add --chmod=+x build.sh
instead of
chmod +x build.sh
All good now
In our Host on Cloudflare documentation I’ve change the build command from this:
[build]
command = "./build.sh'"
To this:
[build]
command = "chmod a+x build.sh && ./build.sh"
That makes the permissions of the file in the repository irrelevant.
2 Likes
tifenak
10
I tried the worker, but I have to remember every time to rebase my project before pushing changes (mostly markdown content).