Repository navigation
feat: add @bongo/tailwind plugin - #96
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.classesandutils.classes()$build.classes: true, bongo collects the class names in theclassattributes of each page as it renders it, with entities decoded.assets/read the union, sorted, withutils.classes(). A loader ofcontent/that calls it fails the build, since no page has rendered yet.Loader.Utilitiesgetsclasses(). Hand-written utilities, as in tests, need it.Plugin:
@bongo/tailwindcssloader. It builds a stylesheet that importstailwindcssor uses a Tailwind at-rule, and leaves others as they are.@referenceand@apply, builds with no candidates. It can then build while a page renders, for$assets.classes(), before any page has its classes.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(...)andsource(none)work as in Tailwind.shouldRewriteUrlskeeps eachurl()of an inlined stylesheet relative to the stylesheet that bongo builds, so fonts from packages such as@fontsourcework.bump.jsonand the publish steps of CI.actions/checkoutgoes to v7.0.1; its breaking change applies only topull_request_targetandworkflow_run, which CI does not use.$build.classesin Config,utils.classes()in Loaders, and a pointer from CSS.npm trusted publishing must be set up for
@bongo/tailwindbefore the first release that includes it.Performance
$build.classesoff, the default:bun run bench site incremental,mainagainst this branch, in both orders.The RSS of 570 MB is in the range of
mainacross runs (485–616 MB); a third pair gave 555 MB onmainand 533 MB on the branch. No change.$build.classeson, 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 manyclassattributes. The scan is all of it: the same build with a scan that returns nothing matches the build without one. A scan that searches withindexOfor 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
classutils.classes(): a fresh build, off by default, kept and deleted pages inbongo buildandbongo dev, a build in a new process, and a loader ofcontent/that calls it@apply, through$assets.classes()and<bongo:style>@source,url()of an inlined stylesheet, a stylesheet without Tailwind, and a class from a new page in the next buildbongo dev: a class added to a layout reaches the served CSS after the rebuildseolintpassesbun run build,bun test,bunx tsc -p .,bunx tsc -p build