Skip to content

feat: add @bongo/tailwind plugin - #96

Merged
lukeed merged 3 commits into
mainfrom
feat/tailwind
Nov 3, 2026
Merged

lukeed merged 3 commits into
mainfrom
feat/tailwind

Conversation

@lukeed

@lukeed lukeed commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds @bongo/tailwind, which builds Tailwind CSS v4 stylesheets from the class names of the pages that bongo renders, not from a scan of source files.

Core: $build.classes and utils.classes()

  • With $build.classes: true, bongo collects the class names in the class attributes of each page as it renders it, with entities decoded.
  • The names of each page are in the memo, in the shared table of the placeholder lists, so a page that a build keeps still adds its names. An incremental build makes the same CSS as a fresh build.
  • Loaders of assets/ read the union, sorted, with utils.classes(). A loader of content/ that calls it fails the build, since no page has rendered yet.
  • Loader.Utilities gets classes(). Hand-written utilities, as in tests, need it.

Plugin: @bongo/tailwind

  • A css loader. It builds a stylesheet that imports tailwindcss or uses a Tailwind at-rule, and leaves others as they are.
  • A stylesheet that only applies or references utilities, such as a CSS module with @reference and @apply, builds with no candidates. It can then build while a page renders, for $assets.classes(), before any page has its classes.
  • The candidates are utils.classes(), the scripts in the folder of the stylesheet (a script can add a class that no page has yet), and each @source. source(...) and source(none) work as in Tailwind.
  • A class that a template prints in one branch only is in the CSS only when a page renders that branch. The words of the text never become utilities.
  • shouldRewriteUrls keeps each url() of an inlined stylesheet relative to the stylesheet that bongo builds, so fonts from packages such as @fontsource work.
  • Added to bump.json and the publish steps of CI. actions/checkout goes to v7.0.1; its breaking change applies only to pull_request_target and workflow_run, which CI does not use.
  • Docs: a plugin page, $build.classes in Config, utils.classes() in Loaders, and a pointer from CSS.

npm trusted publishing must be set up for @bongo/tailwind before the first release that includes it.

Performance

$build.classes off, the default: bun run bench site incremental, main against this branch, in both orders.

step main branch branch main
site, wall 2.37 s 2.36 s 2.38 s 2.36 s
site, peak RSS 511 MB 570 MB 524 MB 523 MB
no change 246 ms 248 ms 242 ms 234 ms
title edit 348 ms 346 ms 331 ms 330 ms

The RSS of 570 MB is in the range of main across runs (485–616 MB); a third pair gave 555 MB on main and 533 MB on the branch. No change.

$build.classes on, on the bench site: a fresh build takes +190 to +260 ms (about 10%) for 10,000 pages, which have many highlighted code blocks and thus many class attributes. The scan is all of it: the same build with a scan that returns nothing matches the build without one. A scan that searches with indexOf or a sticky regex was slower in the build, so the scan stays one regex, and splits each distinct value once. The memo grows by 8 KB.

Against Tailwind as a separate step before bongo build, on a small site (29 pages, a large shared design system): the plugin build was 1.88 ± 0.36 and 1.32 ± 0.30 times faster, in both orders, with the same CSS, 170 KB minified.

Test plan

  • Class scan: quotes, bare values, case, entities, and attributes that only end in class
  • utils.classes(): a fresh build, off by default, kept and deleted pages in bongo build and bongo dev, a build in a new process, and a loader of content/ that calls it
  • Plugin: a CSS module with @apply, through $assets.classes() and <bongo:style>
  • Plugin: rendered classes and not text, scripts and @source, url() of an inlined stylesheet, a stylesheet without Tailwind, and a class from a new page in the next build
  • bongo dev: a class added to a layout reaches the served CSS after the rebuild
  • Docs build, and seolint passes
  • bun run build, bun test, bunx tsc -p ., bunx tsc -p build

With $build.classes, bongo collects the class names in the class
attributes of each page as it renders, keeps them in the memo with
the placeholder lists, and gives their union to loaders of assets/
as utils.classes(). A plugin can then build CSS from the classes
that pages render, with no scan of source files.
Builds each stylesheet that uses Tailwind from utils.classes(),
the scripts next to it, and its @source paths. Each url() is
rewritten for the stylesheet that bongo builds, so fonts from
packages keep working. Adds the package to bump.json and the
publish steps, and moves actions/checkout to v7.0.1.
A CSS module with @reference and @apply builds while a page renders,
for $assets.classes(), before any page has its classes. The plugin
read utils.classes() for every stylesheet, so the build failed there,
though the same module built through <bongo:style>. It now reads the
classes of the pages only for a stylesheet that writes utilities.
@lukeed lukeed changed the title feat: add @bongo/tailwind feat: add @bongo/tailwind plugin Nov 3, 2026
@lukeed
lukeed merged commit d54591f into main Nov 3, 2026
4 checks passed
@lukeed
lukeed deleted the feat/tailwind branch November 3, 2026 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant