Skip to Content
Reference

Frontend output

What tifa build puts in dist/

Path Contents
dist/assets/ The browser bundle that Vite builds, with client.ts as the entry (app-<hash>.js), shared chunks (chunk-<hash>.js), one stylesheet with all the CSS of the app (style-<hash>.css), and the fonts and images that CSS references. Vite inlines small ones as data URLs. The images and other files the bodies of content collections refer to are here too, as <name>-<hash>.<ext>, never inlined. The syntax target comes from the config option build.target (default es2020: one ECMAScript version plus any number of browsers with versions, such as es2019,chrome90,safari14). Split by route: the entry holds the root Layout and all other code every page loads, and every other page.tsx and layout.tsx is a chunk of its own that loads the first time its route is needed, see Route modules in the browser. Each JavaScript, CSS, HTML, JSON, SVG, XML and WebAssembly file of 1024 bytes or more also gets a <name>.gz at gzip's best level, unless gzip does not make it smaller. The server sends it in place of the file, see Compression
dist/ssr.js The SSR bundle, with server.ts as the entry: one ES module file with every npm package inside, and no imports or exports left. It holds no CSS: a plain stylesheet, a .css file imported for its side effect, is an empty module there, which neither Vite's CSS step nor a plugin such as Tailwind's compiles. A CSS module and a stylesheet imported with ?inline, ?url or ?raw are built as in the browser bundle. Each VM evaluates it as a module, so it runs in strict mode and may use top-level await (see Top-level await and strict mode). The build then compiles it once with the engine, as the server does at start, without running it: code the server could not compile, such as a with statement that rolldown keeps from a CommonJS file, fails the build with its place in the source file. This takes about 0.12 s for examples/shop on an Apple M4. Packages resolve to their main files (module, then main), and conditional exports to the worker, import, module and default conditions. Their browser files are not used: many take what the browser has, such as self or window, which beastjs lacks. To use the browser build of a package on the server, import its file by path. The syntax target is fixed at ES2022 (the version beastjs runs as is. Lowering it only slows rendering, and raising it may emit syntax beastjs does not support). Page code that imports a Node module fails the build. For npm packages the build only warns: it lists the places where the bundle may still load a module at run time, with require or import(), giving the source file, line, column and package, since a server render that reaches one fails in beastjs. To find them it reads a minified copy of the final code in which typeof require is "undefined" wherever the code does not declare its own require. So a require in dead code, such as an if (false) branch, or behind a typeof require test, as in typeof require === 'function' ? require(name) : fallback, gets no warning: beastjs has no require and takes the other branch. The list is a hint. It may name code no render reaches, such as a branch a package picks by typeof process (debug does this), a require inside try/catch, or one the code assigns to. It may miss a require in an eval string, in code that sets globalThis.require and deletes it again, or in code a later plugin adds. A place no source maps to, such as the import of a Node module, is given in ssr.js. A define writes the head tags of the browser bundle into __TIFA_ASSETS__
dist/ssr.js.map The source map of the SSR bundle, without a copy of the sources. The server reads the file when it loads the bundle, and decodes it on the first error of that bundle, a failed prewarm included, to give the places of the stack trace in the source files, with paths relative to the application root. A map it cannot read in full is not used, and the places stay in ssr.js. Its size depends on the app: for examples/shop it is about 1.9 MB, a bit under twice ssr.js. It is embedded in the program with the rest of dist/. To leave it out, set environments.ssr.build.sourcemap to false in vite.config.ts: the program of examples/shop is then about 1.9 MB smaller, and the warnings of the build and the render errors give places in ssr.js. A build that writes no ssr.js.map removes the one an earlier build left, which would be of other code: tifa dev keeps .tifa/dist between builds. The server reads only this file, so with inline the map in ssr.js is not used
dist/public/ A plain copy of the folder that the config option build.public points to (default public), for files that need a fixed name (see Static files). Files and folders whose names start with a dot are not copied, except .well-known and the paths listed in build.public_dotfiles. tifa build prints the names it left out. A symbolic link in it, or the folder itself being one, is followed: a link to a file is copied as that file, a link to a folder is copied with what is in it. A link that leads back into a folder being copied, or to nothing, fails the build. Absent if that folder does not exist. build.json lists the content hash of each file in it, which becomes its ETag
dist/content.json For an app with content collections: the entries of every collection that are not drafts, with the fields of content.Entry, the translation key, the file of the body and its headings, and the front matter as JSON. The program reads it before OnStart, see Content
dist/content/ The body of each entry as HTML, <collection>/<language>/<ID>.html (without the language folder for a collection without languages). entry.Body() reads the file. The server does not serve it, and the build writes no .gz for it. The files a body refers to are in dist/assets/
dist/build.json {buildId, head, preload, public}. head is the HTML that loads the browser bundle, taken from Vite's manifest: the stylesheet, a modulepreload link for each chunk the entry imports, and the entry script. preload lists the files each route module needs beyond head, see Preloading the chunks of a page. The build ID is a hash of every other file in dist/ but inputs.json (names included). File names and contents each carry a length prefix, so different file trees cannot produce the same bytes. The same input gives the same ID. public is the content hash of each file of dist/public/ by its path there, the first 16 bytes of its SHA-256 in hex, absent without public files and under tifa dev
dist/inputs.json What the build was made from: the first 16 bytes of the SHA-256 of each file, in hex, by its path relative to the application root. The files are the modules of the SSR bundle and of the browser bundle outside node_modules (pages, Layouts, components, also those that render only in the browser, stylesheets and the generated modules in .tifa/), and the files a Vite plugin says the build depends on, such as a stylesheet that another one imports and the files Tailwind scans for class names, and the local files the Vite config imports. When the build cannot read that list from Rolldown, it still succeeds with a warning, and inputs.json says the list is incomplete and why (incomplete, with the Rolldown version), so tifatest.StartPages fails with that reason until Tifa is upgraded. Under tifa dev the browser gets its modules from Vite, so only those of the SSR bundle are listed (a stylesheet it imports, but not one that stylesheet imports or the files Tailwind scans, as the SSR bundle leaves the CSS out), package.json, the lock file, the Vite config, tsconfig.json, tifa.yaml, the public files and the files of content/. It also lists the public directory and content/, so a file added to either since the build counts as changed, as does a project file that appears. The same holds for the files of every _locales folder of app/, also in a folder that is new since the build, and inputs.json lists the ones the build read. tifa build and tifa dev write it, the build ID leaves it out, and tifatest.StartPages compares it with the files as they are to fail a test whose front end is older than its sources (see Testing)

Vite writes no source maps for the browser bundle. If the app sets build.sourcemap in its vite.config.ts, the .map files land in dist/assets/ and are served like any other asset, and they hold the source of the app.

The build prints what Vite and Rolldown warn about the app's own code. Tifa turns off two notes an app cannot act on: Rolldown's PLUGIN_TIMINGS list of the slowest plugin callbacks, and Vite's chunk size warning below 1000 kB for the browser bundle, which Tifa makes one file on purpose. A browser entry past 1000 kB still gets the warning. An app can set build.chunkSizeWarningLimit or build.rolldownOptions.checks in its own Vite config to change either.

The SSR bundle starts by importing runtime/host.js, which adds what beastjs lacks: TextEncoder/TextDecoder, AbortController, Headers, Response, queueMicrotask, atob, btoa, DOMException, structuredClone, crypto.getRandomValues, crypto.randomUUID, AsyncLocalStorage and a console that prints nothing (under tifa dev, to the log) and throws on error. Before running bundle modules, the SSR loader registers URL and URLSearchParams of the engine (github.com/liustack/beastjs/url, which parses in Go), Go functions for fresh random bytes and for the async context of the engine, an object that promise jobs carry, in which AsyncLocalStorage keeps its stores. crypto and AsyncLocalStorage are therefore ready for dependencies that use them at module load time. Cloning runs entirely in JS, using intrinsic brand checks and Error.isError, without reading private engine fields. It does not provide crypto.subtle, fetch or Request. What the server render has lists everything a page finds there. The script is prebundled into the program, so apps do not need to install the packages it is made from. How it is built and why two of those packages are patched: The host script.

The Tifa plugin adapts many npm packages in the SSR bundle, such as React DOM, TanStack Router, i18next and the libraries that style and draw components, so they render faster in beastjs. It finds the code it changes by its form or its text, not by the version of the package, so pnpm update does not break the build. When a release changes that code, the build prints a warning with the package version and the file, and leaves that code as it is. Pages still render, only more slowly. A React DOM release whose string renderer the plugin has not read in full gets a warning that says so, and pages render the same and take longer. Every such warning starts with tifa rewrite not recognized: , so grep finds them all. The changes to React DOM keep each line of its files where it was, so the stack trace of a render error gives the lines of React DOM as they are in node_modules. There is no setting to turn the changes off: none of them changes the HTML, except the key of a server action, which Tifa does not have. What each change does, and how a maintainer reviews a new release: SSR bundle rewrites.

Packages may import Node modules, which beastjs does not have. The plugin gives each static import of a Node module by a dependency a stand-in module of its own. It exports the names Node gives that module, asked of the Node that runs the build, and every other name the importer asks for, each a function whose every use throws an error that names the export, the module and the package (see Packages that import Node modules). The stand-ins have no side effects, so the names no code uses leave the bundle, and the build warns of the modules whose stand-ins are left. An import of node:async_hooks gets the AsyncLocalStorage and AsyncResource of the host instead, and one that asks for nothing else gets no stand-in and no warning. A require or an import() of a Node module stays as it is, and the build warns of it. Page code that imports a Node module fails the build.