Build output
What hamur build and hamur generate write, how the files are named and where they are served from, what the build prints, and the keys that change it. Each key is also in the hamur reference with its checks; the keys of the styles pipeline are on Styling.
Where files are served from
app.cdnURL
app.cdnURL is the URL of a CDN that serves the client files: an absolute http: or https: URL with no ? or #, normalised to end in /. The default is "": the files come from app.baseURL. Anything else fails when the config loads: app.cdnURL must be an absolute URL such as "https://cdn.example.com/" (got "/cdn").
import { defineConfig } from "hamur"
export default defineConfig({
framework: "react",
app: { cdnURL: "https://cdn.example.com/" },
server: { csp: {} },
})
The client files are then at <cdnURL><buildAssetsDir>. These URLs name the CDN: the import map and its CSS entries, every modulepreload, the stylesheet links and the data-hamur-href of inlined stylesheets, the entry script, the chunk preloader, the URL of an imported file and a CSS url(). These stay on app.baseURL: the files of public/, <path>/_payload.json, /_hamur/data requests, the reports and every route. A web worker's script stays there too, since a new Worker() script must share the document's origin.
Upload .output/public<buildAssetsDir> to the CDN. hamur dev ignores the key, and hamur preview of a build that has it prints [hamur] app.cdnURL is set: pages load their files from https://cdn.example.com/; upload .output/public/_hamur/ there first.
What the CDN must do.
- Answer module scripts with
Access-Control-Allow-Originfor the app's origin. A module script is always fetched with CORS. A script,modulepreloadand stylesheet link of another origin carriescrossorigin;app.crossOriginunset becomes"anonymous"whenapp.cdnURLis set, as it does withbuild.sri. An explicitfalsestays and fails nothing at build time. - Serve the bytes unchanged.
build.sridigests hold wherever the files are served, so a CDN that rewrites a file breaks them. - With
server.cspon, Hamur adds the CDN's origin todefault-src,script-src,script-src-elem,style-src,style-src-elemandimg-src. A directive you set inserver.csp.directiveswins, as for every other.
At run time. HAMUR_APP_CDN_URL, read when the server starts, replaces the CDN URL in the URLs the server writes for each page: the import map, the preloads, the stylesheet links and the entry. Empty means no CDN. A build moves to another origin without a rebuild. A value that is not an absolute URL fails the start: HAMUR_APP_CDN_URL must be an absolute URL such as "https://cdn.example.com/" (got "cdn").
# move the files to another origin without a rebuild
HAMUR_APP_CDN_URL=https://assets.example.net/ bun .output/server/index.mjs
# serve the app under a sub-path chosen at start (experimental.runtimeBaseURL)
HAMUR_APP_BASE_URL=/docs/ bun .output/server/index.mjs
The variable does not change the asset URLs inside JS and CSS chunks, nor the import logo from "./logo.png" strings of the server bundle. They keep the value the build had, equal in the HTML and in the client, which is why the two never disagree. So the old origin must keep serving the files those chunks name, and a HAMUR_APP_CDN_URL="" start still lists the build's CDN in the CSP. A runtimeConfig.app.cdnURL or runtimeConfig.app.baseURL key shares these names and warns at load.
Relative asset paths (app.baseURL: "./") are not built. An imported file's URL is one string in the server and the client bundle, and a depth-relative string cannot be one string for both; a <base href> would make every #fragment link leave the page. For a host that serves the app under a path, such as GitHub Pages under /my-repo/, set app.baseURL for that mode:
import { defineConfig } from "hamur"
export default defineConfig({
framework: "react",
app: { baseURL: "/" },
$env: {
pages: { app: { baseURL: "/my-repo/" } },
},
})
Run hamur build --mode pages for that deploy.
experimental.runtimeBaseURL
An experimental key, false by default. With true, HAMUR_APP_BASE_URL replaces app.baseURL when the server starts: routes, the document's links, the client router and Link hrefs follow it. The server also answers the files under the build's base and buildAssetsDir, since asset URLs inside chunks keep the build-time value.
import { defineConfig } from "hamur"
export default defineConfig({
framework: "react",
preset: "bun",
experimental: { runtimeBaseURL: true },
})
- The preset must serve its own files:
bunornode. Others fail at load:experimental.runtimeBaseURL needs a preset that serves its own files (bun, node); preset "static" does not. - The value is an absolute path:
HAMUR_APP_BASE_URL=docsfails the start withHAMUR_APP_BASE_URL must be a path such as "/docs/" (got "docs"). Without the key the variable is ignored. - When the value differs from the build's base, everything the build rendered holds the old base, so the server does not serve it: a prerendered page and its
_payload.json, a storedprerender: "shell"shell and anisrseed. Those pages render on demand under the new base.
File names and chunks
Hash-only names and build.hashSalt
A production client JS or CSS file is <16 hex>.js or <16 hex>.css below app.buildAssetsDir: the first 16 hex digits of the SHA-256 of build.hashSalt, a NUL byte and the file's bytes. No name carries a page or an entry name. Worker chunks are named the same way. Images, fonts and media keep <name>-<hash>.<ext>.
build.hashSalt is a string, "" by default, mixed into every JS and CSS hash. Changing it renames every JS and CSS file and no other asset, which is how an app gets new URLs after a CDN served a file with the wrong headers. A value that is not a string fails: build.hashSalt must be a string (got 1).
import { defineConfig } from "hamur"
export default defineConfig({
framework: "react",
build: { hashSalt: "2026-11-23" },
})
Chunk keys
A client chunk has two names. Its file name is the hash of its content, so it changes with its code. Its chunk key is #hamur-chunk/<key>, the specifier by which one chunk imports another and the key of the import map that every production document carries: <key> is 8 hex digits of the SHA-256 of the chunk's sorted, root-relative input paths, and the import map maps it to the hashed URL. The entry is #hamur-chunk/entry. Chunks import each other through the keys, so an edit of one page renames that page's chunk and none of the files that import it. hamur build --analyze=html shows each chunk's key.
build.chunkSizeWarningLimit and build.minChunkSize
build.chunkSizeWarningLimit is KiB of minified JavaScript, 500 by default and 0 for off. After the file table the build warns, naming the two largest packages of each chunk above it:
[hamur] 2 client chunks are larger than 500 KiB after minification: <file> (712 KiB, react-dom, chart.js); split them with import() or raise build.chunkSizeWarningLimit
build.minChunkSize is Bun's minChunkSize for the client build, in bytes, 0 by default: Bun folds a shared chunk smaller than that into its importers. Both must be non-negative integers (build.minChunkSize must be a non-negative integer (got "16k")). Hamur sets no other value for you. There is no key that groups packages into a named chunk: it was measured on conformance-react and Bun did not give one chunk, because it splits by the set of entry points that reach a module.
import { defineConfig } from "hamur"
export default defineConfig({
framework: "react",
build: { chunkSizeWarningLimit: 300, minChunkSize: 16384 },
})
build.clientBundle
"split" is the default: route chunks and an import map. "single" builds the client without code splitting: one JS file and one CSS file, every route and layout in the one file, no import map. "inline" is for ssr: false and a static preset: one index.html with the JavaScript and CSS inside it, every imported file and CSS url() a data: URI whatever its size, and nothing under app.buildAssetsDir, so the page opens from file://.
import { defineConfig } from "hamur"
export default defineConfig({
framework: "html",
ssr: false,
preset: "static",
build: { clientBundle: "inline" },
})
"inline"needsapp.history: "hash", sincehistory.pushStatethrows onfile:. Left unset it becomes"hash";"browser"fails withbuild.clientBundle "inline" needs app.history "hash". With SSR or another preset it fails withbuild.clientBundle "inline" needs ssr: false and the static preset.- Under
"single"and"inline"an island page fails (build.clientBundle "single" cannot build islands: each island is a chunk its page loads by itself), so does a worker imported by URL (import it with?worker&inline), and so doesapp.routeDiscovery: "lazy". build.sourcemapother than"none"becomes an inline source map in"inline".- Any other value fails:
build.clientBundle must be "split", "single" or "inline" (got "one").
app.importMap
Modules hosted elsewhere go in app.importMap, a record of specifier to URL, merged into every production document's import map (and into the one hamur dev writes).
import { defineConfig } from "hamur"
export default defineConfig({
framework: "react",
app: { importMap: { "remote/widget": "https://widgets.example.com/widget.js" } },
})
import("remote/widget") stays external in every build and is a plain import at run time, so keep it behind import.meta.client: the server build leaves it external too, and there it fails. Hamur never sees the module, so it has no hash, no tree-shaking and no integrity digest from build.sri; app.crossOrigin applies to it. A key must be a non-empty specifier that does not start with #hamur-, and a value an absolute https: URL or a path that starts with /. A path stays as written under app.cdnURL, since it is your file. There is no shared-library or federation mode: the UI library stays in the bundle.
build.compileHints
false by default. With true, the entry, app root, layout and page chunks, and the chunks they import statically, start with //# allFunctionsCalledOnLoad, which asks V8 to compile every function of the file when it loads. The line is part of what the file name hashes, so a name still depends on the code only. Whether it pays is for you to measure: it trades compile time of functions that never run for the time of the first call, and only some browsers read it.
build.extractAsyncDataHandlers
For the static preset only. A static page restores its useAsyncData data from its payload file, so the handler function is dead weight in the client until refresh() runs it. With true, the build moves an inline handler (useAsyncData("key", () => …)) into a chunk that loads when it runs. Hamur has no JavaScript parser, so it moves a handler only when it can prove the handler uses nothing from the component: every name in it is its own parameter or declaration, a top-level import of the file, or one of $fetch, fetch, JSON, Math, Date, Number, String, Object, Array, URL, Promise, encodeURIComponent and console. A handler that it cannot prove stays in place and the build logs the reason once, for example [hamur] app/pages/x.tsx: useAsyncData("k") handler is not extracted: it uses "count". The output is always correct. On a server preset the key logs [hamur] build.extractAsyncDataHandlers applies to the static preset only and changes nothing; hamur dev moves nothing.
import { defineConfig } from "hamur"
export default defineConfig({
framework: "react",
preset: "static",
build: { extractAsyncDataHandlers: true },
})
What the build writes and prints
build.license
false by default. true writes .output/.hamur-license.md, a Markdown list of the packages under node_modules that the client build holds (name, version, license field, and the text of their LICENSE*, LICENCE* or COPYING* file); it is not served. { fileName } writes .output/public/<fileName>, as [{ name, version, identifier, text }] when the name ends .json and as Markdown otherwise; the name must be a bare file name (build.license.fileName must be a file name such as "licenses.json" (got "../x")). includeServer: true adds the packages that only the server bundle holds. A package with no license file is listed with text: "" and the build warns [hamur] <name>@<version> has no license file. A workspace package linked into node_modules is left out.
import { defineConfig } from "hamur"
export default defineConfig({
framework: "react",
build: { license: { fileName: "licenses.json", includeServer: false } },
})
build.sourcemapIgnoreList
true by default. Every source map Hamur writes or composes (the client map under build.sourcemap, the maps of hamur dev's server chunks and the worker maps) gets x_google_ignoreList, the indices of the sources under node_modules/ and in Hamur's own runtime, so a debugger skips them when you step. false writes none. A value that is not a boolean fails: build.sourcemapIgnoreList must be a boolean (got "no").
import { defineConfig } from "hamur"
export default defineConfig({
framework: "react",
build: { sourcemap: "external", sourcemapIgnoreList: true, compileHints: false },
})
--analyze=html
hamur build --analyze=html writes .hamur/analyze/client.html and server.html. Each is one self-contained page, with an inline SVG treemap that Hamur writes (no external URL and no library), of chunk, package and module, with raw and gzip sizes and each chunk's import map key. --analyze=json writes .hamur/analyze/stats.json with the same data, and a bare --analyze prints the largest modules of each client chunk as text. --insights <reports.json>, with --analyze=html, takes the client reports sent with server.clientReports.chunks: true and shows which chunks each route loaded. Any other value fails: --analyze takes html or json (got "pdf"); --insights needs --analyze=html.
The route report
After the file table hamur build prints Routes:, one line per page route sorted by path: a mark, the path, and the first-load JavaScript, which is the client entry plus the route's own chunks and what they import, in gzip. Then Server routes: lists each server route's methods and path, and a legend:
○ prerendered ◇ cached by a route rule λ rendered per request ◌ SPA ∅ script-free
A route has the first mark that holds: ∅ (no script, first-load JavaScript 0 B), ◌ (ssr: false), ○ (written by the prerender), ◇ (cached or isr), else λ. --debug prints the resolved route rules (password values shown as [hidden]) and the redirects after it. --json also writes .output/report.json, typed as BuildReport, and build:done receives the same object as outputs.report.
The static-preset hint
After the prerender, a build for a server preset prints once
[hamur] All routes are prerendered and nothing runs on the server; preset "static" would ship no server bundle
when every page route was written, no handler has a route, there is no defineServer middleware and no route rule other than prerender, headers and redirect applies. Nothing is guessed from source; the line reads the route table, the rules and hamur.json. The output is the same with or without it, and adding a handler with a route removes it.
Prerender
prerender.format
The name of the file a prerendered page is written to. "directory" (default) writes <path>/index.html; "file" writes <path>.html (/about is about.html, /blog/a is blog/a.html, / stays index.html); "preserve" follows the page's file (about.tsx is about.html, about/index.tsx is about/index.html, and blog/[slug].tsx is blog/<slug>.html).
import { defineConfig } from "hamur"
export default defineConfig({
framework: "html",
preset: "static",
prerender: { format: "file", workers: "auto" },
build: { minifyHtml: true },
})
Only the file name changes. hamur.json, useRoute().path, the redirect pages, 200.html, 404.html and the payload files (<path>/_payload.json) are as before. Cloudflare Pages, Netlify and GitHub Pages serve about.html at /about; nginx or S3 need a rewrite of their own. "file" with app.trailingSlash: "always" fails the load, since a host looks /about/ up as a directory. The prerender.cache store is stamped with the format, so changing it renders again. A value other than the three fails: prerender.format must be "directory", "file" or "preserve" (got "flat").
prerender.workers
1 (default) prerenders in the build's own process. A number above 1, or "auto" (navigator.hardwareConcurrency - 1, at least 1), starts that many Bun workers, each importing the built server. The main thread keeps the queue, the crawl, the prerender:page and prerender:done hooks and the file writes; prerender.concurrency applies per worker. A worker that exits fails the build with Prerender worker <n> exited with code <code> while rendering <paths>.
What changes with more than one worker:
- A server plugin and a module run once per worker, so a plugin that opens a database opens it per worker.
prerender.sharedDatashares per worker, so an upstreamGETmay run once per worker instead of once.- A handler that depends on call order does not give the output of one worker.
For handlers that do not depend on order the output is byte-identical to workers: 1. A value that is not a positive integer or "auto" fails: prerender.workers must be a positive integer or "auto" (got 0).
build.minifyHtml
false by default. On, the build drops whitespace that cannot show, from what Hamur writes (the head tags, the lines and indentation around the app root, the payload and the entry script) and, in an html app, from the page's body. A whitespace-only text node with a line break between two tags, at least one of which is a block or metadata tag (div, p, section, ul, li, table, script, style, h1 to h6 and the like), is removed; every other text node stays, and nothing inside pre, textarea, script, style or template is touched. Another library's markup is never minified, since hydration compares it with what the client renders, and what a render:html hook adds is not either. The one case it can change is an element that a stylesheet sets to white-space: pre outside a pre. hamur dev does not minify.
--check-links
hamur build --check-links runs, after the build, a crawl of every page route without params, every prerender.routes entry and every route-rule pattern with prerender: true, following links as prerender.crawl does, and writes nothing to .output/public. With @hamur/seo every link rule of seo.linkChecker runs and reports; without it only broken runs: each crawled link the server answers with 400 or more prints as [hamur] link checker: 1 finding on 1 page under the page that links to it, and the build fails only under prerender.failOnError. On the static preset the build already crawls and checks while it prerenders, so the flag changes nothing there (--check-links: the static preset checks links while it prerenders). hamur generate --check-links is refused: --check-links is a hamur build flag; hamur generate checks links while it prerenders.
--routes and --debug-prerender
hamur build --routes "/blog/**,!/blog/draft" bundles and prerenders only the pages that match the patterns, which are written like route-rule patterns and may be negated with !. Every file is still scanned; the others answer 404. The build prints [hamur] --routes: this output serves 3 of 40 pages and is not for deployment, and records the filter in .output/hamur.json, so hamur deploy refuses it: .output was built with --routes "/a"; build again without --routes before deploying. Errors: --routes needs patterns such as "/blog/**", --routes "/nope" matches no page. It is not hamur warm --routes <file>, which takes a file of paths.
hamur generate --debug-prerender builds the server unminified with linked source maps, one worker and prerender.concurrency: 1, and stops at the first page that fails, printing its request path and a stack mapped to your files (app/pages/x.load.ts:3:9).
hamur build --analyze=html
hamur build --json
hamur build --debug
hamur build --watch
hamur build --routes "/blog/**,!/blog/draft"
hamur generate --debug-prerender
hamur build --force
Faster rebuilds
build.cache and cacheDir
cacheDir is where Hamur and its modules keep what a later build can reuse: node_modules/.cache/hamur by default, relative to the root. <cacheDir>/build/ is core's; a module uses <cacheDir>/<its name>/. The prerender store stays in the build directory, since it belongs to one output. A non-string or empty value fails: cacheDir must be a non-empty string (got "").
build.cache is false by default. With true, hamur build skips an unchanged client and server build: after a build it stores .output/public and .output/server (and server-edge and the license file when the build wrote them) as a tar in <cacheDir>/build/, with the content hash of every file the build read.
import { defineConfig } from "hamur"
export default defineConfig({
framework: "react",
cacheDir: "node_modules/.cache/hamur",
build: { cache: true },
})
- The key is the hash of the resolved config, the preset, the mode, the values of the
staticentries ofapp/env.ts, the Bun and Hamur versions and the lockfile. A config the key cannot see, such as a value a function in the config reads fromprocess.env, is not part of it. - A hit needs the archive, every input file to hash as before, and the list of files under
srcDir,serverDir,publicDir,shared/and the layers to be the same (a new file is a miss). It restores the archive, logsBuild cache: restored the client and server build (<12 hex>)and runs only the prerender, which can call an API and so always runs. The chunk size warning is not printed on a hit. - A miss builds as usual and stores; the 10 newest archives are kept. A debug line,
Build cache: miss, <reason>, says which key part differed. --analyzebuilds without the cache, since it reads the build's metafiles.hamur build --forceempties<cacheDir>/build/, withbuild.cacheon or off, and ignores the prerender store. In CI, keep<cacheDir>between runs.
--watch
hamur build --watch (and hamur generate --watch, which prerenders each time) builds once, then watches the app root and the layers with the dev watcher, honouring ignore and .hamurignore and leaving out the output, and runs the whole build again on a change. Changes are debounced by 100 ms and a build runs at a time; a change during a build queues exactly one more. It prints Built in <n> ms, Watching for changes once armed, and Rebuilt in <n> ms after each success. A failed build, the first included, prints error: <message> and the process stays up; the next save builds again. SIGINT and SIGTERM stop it with exit code 0, and --docker cannot be combined with it.
The loading template of a shell
A shell document, the one a page answers when ssr: false applies to it and the client has not mounted, shows nothing until the client has fetched its data. A loading template fills that time. app/spa-loading-template.html is the template when the file exists, and app.spaLoadingTemplate names another one (a path from the root) or is false to ignore the file. A named file that is missing fails the load: app.spaLoadingTemplate file not found: app/loader.html; an empty file writes nothing.
<style>
.spinner { width: 2rem; height: 2rem; border: 3px solid #ccc; border-top-color: #0b5fff; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
</style>
<div class="spinner"></div>
app.spaLoader is the element around the template, written as <div id="__hamur_loader">…</div> by default: tag is a lower-case HTML element name that is not void or raw text, attrs are written escaped after id (which is Hamur's: app.spaLoader.attrs.id is set by Hamur), and location is "body" (default: right after the app root, so the root's CSS and the template's do not meet) or "within" (inside the root). The template is your own HTML, written as it is and never escaped.
import { defineConfig } from "hamur"
export default defineConfig({
framework: "react",
ssr: false,
app: {
spaLoadingTemplate: "app/spa-loading-template.html",
spaLoader: { tag: "div", attrs: { role: "status", "aria-label": "Loading" }, location: "body" },
},
})
- Only a shell has a loader; a rendered page has content. A script-free page has none.
- The client removes the element once the first page is painted, also when that page is the error page. If the client script never runs, the loader stays, which is the right thing to see for a shell that cannot start (see Supported browsers).
hamur devwrites it too, and the static preset writes it into200.html.- The template is yours, so with
server.cspan inline<script>or<style>in it needs'unsafe-inline': Hamur adds no nonce or hash to it. A class from a linked stylesheet needs none. - Errors:
app.spaLoader.location must be "body" or "within" (got "top"),app.spaLoader.tag must be a lower-case HTML element name that is not void or raw text (got "img").
React options
Three keys are for the React adapter only: react.strictMode, react.identifierPrefix and experimental.reactCompiler. They are on the Configuration page, with their errors.
Supported browsers
A production page needs import maps: Chrome 89, Firefox 108 and Safari 16.4 or later. The chunk names depend only on their own code (the import map is what lets one chunk import another by a stable key), and a legacy build would bring back the deploys that rename every file. So there is no legacy build, no plugin-legacy equivalent and no "browser too old" message.
What an older browser gets:
- A page that has HTML shows it: the server rendered it, and the browser reads it. In a browser without import maps the entry script fails to resolve
#hamur-chunk/entry, so no client script runs, and the page's links are followed by full loads. - A shell page (
ssr: false) stays on its loading template, since nothing replaces it.
To support such a browser, load es-module-shims in its polyfill mode, which adds import maps to browsers that run modules but lack them. Copy the file into public/ and add it to the head.
bun add -d es-module-shims
cp node_modules/es-module-shims/dist/es-module-shims.js public/es-module-shims.js
import { defineConfig } from "hamur"
export default defineConfig({
framework: "react",
app: { head: { script: [{ src: "/es-module-shims.js", async: "" }] } },
})
Hamur does not test this in an old browser. The polyfill's README lists edge cases, among them that it does not polyfill a dynamic import() in a module that runs natively, and a Content Security Policy must allow its script; read it before you rely on the recipe.