purgecss is a tool for removing unused css classes from source files. It's particularly useful for functional css frameworks like tachyons, where it's normal to only use a tiny fraction of available classes. This gist contains example code you could use to add purgecss to a shadow-cljs build.
- make sure to
yarn add purgecss
first - usage is
(hooks/purge-css {:css-source __ :js-globs __ :out-dir __})
:css-source
is the path to the original, bloated CSS file (from project root). This is ideally in a source directory, ornode_modules
as in this example. This cannot be the public path where the css is ultimately read.:js-globs
is a string / vector of strings, indicating which files to read as input. These should be all of your compiled javascript bundles which contain your views.purgecss
does a brute-force parse of all these files, extracting all the strings to figure out which classnames are definitely not used.:public-dir
is the public directory where you want the purged CSS file to be written (it will have the same name as the original).
In dev mode, the source CSS file is simply copied to the :public-dir
. In release mode, only classes used by your build are included.