Previous: (olive-css sizes), Up: API
Content-aware pruning of the generated stylesheet. The pruner scans a directory of built HTML for the utility classes that are actually used, parses the compiled stylesheet into nested blocks, and keeps only the rules whose selectors match a used class.
Every path and search option is a Guile parameter, so a build can be
customized with parameterize instead of editing this module:
(parameterize ((artifact-path "_site") (base-stylesheet-path "resources/css/olive.min.css") (output-css-target "app.min.css")) (tree-shake))
The command-line front-end lives in scripts/olive-css-tree-shaking.scm.
Default value:
"public"
Default value:
"resources/css/olive.min.css"
Default value:
"olive.min.css"
Default value:
(".html" ".htm")
Default value:
(".git")
Escape NAME the way a CSS selector escapes it, e.g. "hover:bg-white" becomes "hover\:bg-white".
Return the (escaped) class names referenced by the ‘class’ attributes of the HTML file at FILE-PATH.
Parse the sequence of blocks at one nesting level of S.
Recursively traverse BASE-DIR to find every unique CSS class name used in the files matching ‘scanned-file-types’. Returns a list of escaped class names, e.g. ’bg-apple-green-100\/50’ or ’hover\:bg-white’.
Serialize a list of parsed blocks back into minified CSS text.
Prune the stylesheet at STYLESHEET (default: ‘base-stylesheet-path’) down to the classes used under DIRECTORY (default: ‘artifact-path’), writing the result to TARGET (default: ‘output-css-target’) inside that directory.
Returns an association list describing the run: the input stylesheet, the destination written, the number of used classes and the byte sizes before and after pruning.
Return a minified stylesheet containing only the rules relevant to USED.
Previous: (olive-css sizes), Up: API