This repository demonstrates a common issue encountered when using Tailwind CSS with server-side rendering (SSR) frameworks like Next.js or Nuxt.js. The problem arises from Tailwind's purge functionality failing to remove all unused styles, leading to significantly larger CSS bundles than expected. This is particularly noticeable with dynamically generated classNames.
The bug results in bloated CSS output because Tailwind CSS cannot accurately identify all the classes that are actually used during SSR. This is mainly because of dynamic class names which make static analysis complicated. The bug.js
file demonstrates this problem.
The bugSolution.js
file presents a solution utilizing different approaches to address this problem: more explicit class names, proper usage of purge options, and potentially adopting an alternative strategy like @apply
for specific cases.
npm install
.