Introduction

PurgeCSS is a tool to remove unused CSS. It can be used as part of your development workflow. PurgeCSS comes with a JavaScript API, a CLI, and plugins for popular build tools.

Here are a couple of ways to use PurgeCSS:

CLI

You can install the CLI in two ways. By installing PurgeCSS globally or using npx.

Install globally

npm i -g purgecss

Run PurgeCSS from the terminal:

purgecss --css <css> --content <content> [option]

Use npx

npx allows you to run the CLI locally without installing the package globally.

Install PurgeCSS as a dev dependency:

Run PurgeCSS from the terminal:

JavaScript API

Install PurgeCSS as a dev dependency:

ES6 with import

ES5 with require

Webpack

Install the Webpack plugin as a dev dependency:

Use the plugin in your Webpack config:

PostCSS

Install the PostCSS plugin as a dev dependency:

Use the plugin in your PostCSS config:

Gulp

Install the Gulp plugin as a dev dependency:

Use the plugin in your Gulpfile:

Grunt

Install the Grunt plugin as a dev dependency:

Use the plugin in your Gruntfile:

Rollup

Install the Rollup plugin as a dev dependency:

Use the plugin in your Rollup config:

Last updated