How to Configure Pagefind in Cloudflare Pages Build Settings
To ensure Pagefind runs automatically during your Cloudflare Pages deployment, update your project’s build configuration.
In Cloudflare Pages, navigate to:
Workers & Pages → Your Project → Settings → Build → Build configuration
Then set the build command to:
hugo && npx pagefind --site public --output-path public/pagefind
This command first generates your site with Hugo, placing the output in the public directory. Pagefind then scans that directory, builds the search index, and writes its files into public/pagefind, making the search functionality available on your deployed site.
If your build process requires more complex logic, you can instead create a build.sh script and set that file as your build command.
Tags: