Cloudflare Pages
--preset cloudflare-pages builds for Cloudflare Pages, which does not deploy a Workers project. The output is the directory Pages uploads, .output/public/:
Reference
| Preset | cloudflare-pages |
| Runs on | Cloudflare Pages |
event.runtime.name | cloudflare |
| Server target | browser |
| Lifetime, startup | request, request |
Output
.output/
hamur.json
wrangler.json only when your wrangler config has bindings (pages_build_output_dir: "public")
public/
_worker.js/index.js the server, a Pages advanced-mode Worker (fetch only)
_routes.json which paths run the Worker
_headers, _redirects from your route rules
... your public files and /_hamur/
Config keys
| Key | Default | What it does |
|---|---|---|
cloudflarePages.routes | computed | { include?, exclude? } replaces a list of _routes.json; at most 100 rules together |
cloudflare.devBindings | true | as on cloudflare |
cloudflare.env | unset | as on cloudflare |
cloudflare.bindings.<NAME>.id | env HAMUR_CF_<NAME>_ID | as on cloudflare |
Detection
The build selects it when CF_PAGES is set, unless --preset, preset or HAMUR_PRESET names another. It is a row of the one table of markers in Choosing a preset.
Deploy command
hamur deploy builds, then runs wrangler pages deploy .output/public; with --preview it runs wrangler pages deploy .output/public --branch preview. See hamur deploy. The preview command of the preset, which hamur preview runs or prints, is bunx wrangler pages dev .output/public.
Limits
- Runs: streamed answers, private
app/env.tsentries read at run time. - Does not run: WebSockets and
server.syncedState,server.pubsub,server.metrics, image transforms at run time, Durable Object classes. scheduledTasks,tasks.queueand Durable Objects fail the build;tasks.runOnStartdoes not run. The request body limit is Cloudflare's: 100 MB (Free, Pro) to 5 GB (Enterprise).cloudflare.observabilityis not written: Pages Functions have no such setting.
The levels are the features of the preset: hamur build warns or fails when the app uses a feature the preset does not run (see Preset features).
.output/public/
_worker.js/index.js the server, a Pages advanced-mode Worker; it exports fetch only
_routes.json which paths run the Worker
_headers, _redirects from your route rules
... your public files and /_hamur/
The Worker serves public files through env.ASSETS.fetch, so route rules still apply to them. _routes.json is { "version": 1, "include": ["/*"], "exclude": [...] }: exclude lists /_hamur/* and the public files, which Pages then serves without running the Worker. Pages allows 100 include and exclude rules together, each at most 100 characters, so the build collapses the files by directory (/img/*) until they fit. A directory that a page or handler can answer in stays as separate files. What still does not fit is left to the Worker, and the build warns. A path that a route rule needs the Worker for (basicAuth, ipRestriction, cors, proxy and the others listed under Cloudflare) is never excluded.
cloudflarePages.routes: { include?, exclude? } replaces the computed lists. A list over the limits, or an exclude entry over a path the rules need the Worker for, fails the build.
When your wrangler.json has bindings, the build also writes .output/wrangler.json with pages_build_output_dir: "public". useRuntimeEnv() and the typed event.runtime.env work as on cloudflare.
Pages has no cron triggers and a Pages Function cannot consume a queue, and it cannot define a Durable Object class. scheduledTasks, tasks.queue and Durable Objects fail the build:
scheduledTasks is not supported on the "cloudflare-pages" preset: Pages has no cron triggers; use the cloudflare preset
tasks.queue is not supported on the "cloudflare-pages" preset: a Pages Function cannot consume a queue; use the cloudflare preset
Deploy with wrangler pages deploy .output/public, or preview locally with wrangler pages dev .output/public.