I was just looking into purgecss, and I couldn’t find much on it in relation to elm. How does it detect the classes in your elm files? Just regex-ing through the files?
Finds (with a regex) if the class exists in these files: postcss.config.js#L7 (the class extractor works for Tailwind classes, that includes : and / characters)
Note that in elm-batteries, purgecss is only used for production builds, saving some build time in local development: postcss.config.js#L12
Known limitations and alternatives:
purgecss won’t find and preserve classes created dynamically. Alternatively, we can explicitly whitelist class and tag names: postcss.config.js#L26
class names found in unused Elm functions will be preserved. Alternatively, and when removing dead code from sources is not an option, we could inspect the .js production build.
That’s pretty cool, I guess the possibility of including a class by mistake (i.e having a variable or function somewhere of the same name) is more than offset by how simple and predictable it is.
Thanks for making this, as a non-JS person most of these tools are new to me. I’m learning a lot from just browsing through your template and finding out what the build does.
Exactly The main motivation is to use CSS framework like Tailwind (that has thousands of utility classes like bg-gray-500, border-l-4…) while controlling the size of the production css.
I have another question: What is the reason for using rtfeldman/elm-css if you’re using tailwind? Do you want to mix tailwind classes with the option to do something custom here and there?