Repository navigation
feat: add $assets.classes for CSS modules - #88
Merged
Merged
Conversation
CSS modules shipped hashed class names that no page could read. $assets.classes() compiles the module as its <bongo:style> will, and the bundle takes over that compile, so it runs once. A page that reads the classes renders again when the module or its imports change. A class that composes others now gives all of their names. The loader utilities move to module level, so $assets keeps no build alive.
A missing asset read 'Missing "x" asset!, rendering ...' once the build named the page.
$assets.classes read and hashed the module file on each call, so a layout that reads it did so for every page. Each module now compiles and hashes once a build, as LightningCSS reads it.
LightningCSS lists only the classes that a class composes directly. A class that composes one that composes another missed the last one's names, and so its styles.
LightningCSS gives the classes of a CSS module in a new order each run. The build hashes that map to tell if a page must render again, so each page that linked a CSS module rendered on every build, with no change.
A script import that did not resolve was only a warning, so the script shipped the import as written and failed in the browser. The bundler tests now reset the registry before each test, as another test file can leave a registration behind.
The CSS page had no section on plain @import, on composing a class of another CSS module, or on scripts that import a stylesheet.
$assets.classes for CSS modules
The file name alone now decides if a stylesheet is a CSS module. With `global`, a .module.css file shipped its classes as written, while $assets.classes() gave the hashed names, and nothing failed.
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
CSS modules shipped hashed class names that no page could read. This adds
$assets.classes(), and fixes the bugs that came up on the way.Features
$assets.classes(filename)returns the class names of a.module.cssfile, as its<bongo:style>ships them. It compiles the module on first use, and the bundle takes over that compile, so each module compiles once a build. It hashes what it read, so a page that reads the classes renders again when the module or its imports change. A file that is not a.module.cssfails the build.Fixes
acomposesbcomposesc).asset!, rendering …; the!is gone.Docs
/css/: new sections on@import, composing a class of another module, and scripts that import a stylesheet. The CSS modules section shows$assets.classes().<bongo:script>: new Imports section.$assets.classesin Variables, the incremental build rules in CLI, and the readme.Notes
$assetsof compiled partials keeps no build alive (build: the last build stays in memory after build() returns #59).externaloption.@imports gets a hash, but is not in$assets.classes(). The docs say to compose it, or to link plain CSS with its own<bongo:style>.Performance
bun run benchonmainand on this branch, plushyperfineruns on the 10k-page bench site, on an M1 Max.main$assets.classes()on every page, fresh build$assets.classes()on every page, no-change buildThe output of the bench site is byte for byte the same (sha256
749c3b333f7eb60d). Without modules, the differences follow the order of the runs, not the code. I ran the samemaincode in the repo and in a worktree: system time differs by about 15% by location alone, so it is not from this branch. No bench row, since speed without modules is the same.Test plan
bun run build,bun test(899 pass),bunx tsc -p .,bunx tsc -p buildclasses(), unresolved and URL imports--minify, in an output file, a new class reaches the page after an edit, a no-change build renders no page, errors name the missing or non-module file, an unresolved import fails the buildbongo dev: an edit to a module adds a class to the served page, and it matches the served stylesheet