How to Move the Hugo Public Folder Outside the Project Root

planet volumes HvnO9NWEp s unsplash scaled
Genx Avatar

To place the public folder outside of the Hugo root directory, use the publishDir setting in your Hugo configuration file. Here’s a step-by-step guide for documenting this process:


How to:

Putting Hugo’s output (public folder) outside the main site directory is useful for custom deployments, multi-repo management, or tailored static workflows.

1. Set the Output Directory in Config

Open your Hugo config file (config.toml, hugo.toml, or config.yaml).
Add or edit the following at the top level (not inside any section):

publishDir = "/absolute/path/to/your/destination"

Example: To place the output in /Users/username/mydeploy/public, use:

publishDir = "/Users/username/mydeploy/public"
  • You can use an absolute or relative path.gohugo

2. Build or Serve Your Site

  • For a static build: hugo
  • For live preview (development): hugo server
  • By default, Hugo will now output the generated site files to the folder specified in publishDir.
  • There’s no need to specify additional destination flags unless you want to override the config file.

3. (Optional) For Temporary Overrides

You may temporarily override the config value using the –destination (or -d) flag:

hugo --destination "/another/folder"

4. Using with Tools Like Pagefind

If you use post-processing tools (like Pagefind) that expect your site output, always point them to your new output directory:

npx pagefind --site /Users/username/mydeploy/public

Notes

  • The original public folder in your Hugo project root will not be used.
  • If you switch back, remove or update the publishDir value.
  • For incremental development, you do not need –renderToDisk unless you require actual files in your destination during hugo server sessions.

This ensures your Hugo build artifacts are organized exactly where you need them, outside of your main site.

Share This Post:

Genx

in

Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

1 × 2 =

Webmention: Have you posted a response to this article? Let me know the URL: