Hosting a Hugo site on a Cloudflare Worker

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

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

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:

  1. Installs a specific version of Hugo
  2. Installs a specific version of Dart Sass to transpile Sass to CSS
  3. Sets the system timezone
  4. Ensures that Page.GitInfo returns the expected results
  5. Addresses https://github.com/gohugoio/hugo/issues/9810

In my view all but #2 are required for every site.