DEV Community

Sergio Daniel Xalambrí
Sergio Daniel Xalambrí

Posted on • Originally published at sergiodxa.com

Purge unused CSS with TailwindCSS

TailwindCSS now comes with built-in support to purge the unused CSS, to use this creeate, if you don't already have, a tailwind.config.js file in your project root, inside it export an object, using CommonJS syntax, and there define a property purge with an array of the globs to use to find which files are using Tailwind.

module.exports = {
  purge: [
    "./src/**/*.{ts,tsx}"
  ],
};
Enter fullscreen mode Exit fullscreen mode

In our example we are searching for any .ts or .tsx file inside any level of folders inside the src folder in the root.

We could also disable it by passing false instead of an array.

module.exports = {
  purge: false
};
Enter fullscreen mode Exit fullscreen mode

This is helpful if we are purging them using another tool.

Discussion (0)