This repository demonstrates a common, yet often subtle, bug related to Tailwind CSS's @apply
directive and its interaction with CSS purging during production builds. The issue occurs when classes used within the @apply
directive are removed by the purge process, resulting in unexpected styling behavior in the production environment.
The @apply
directive provides a convenient way to reuse styles, but if the underlying utility classes are purged, the entire style definition will be lost. This is particularly problematic because the styling might appear correct during development (when purging isn't active), making the bug hard to detect until the production build is generated.
npm install
to install dependencies.npm run build
to build the application with purging enabled.The solution involves ensuring the utility classes used in the @apply
directive aren't purged, this can be achieved by:
purge
configuration.safelist
to keep classes from being purged.@apply
in such scenarios and directly using the classes.