CLI
PurgeCSS is available via a CLI. You can use the CLI by itself or with a configuration file.

Installation

1
npm i -g purgecss
Copied!

Usage

To see the available options for the CLI: purgecss --help
1
purgecss --css <css> --content <content> [option]
2
3
Options:
4
--con, --content glob of content files [array]
5
-c, --config configuration file [string]
6
-o, --out Filepath directory to write purified css files to [string]
7
-w, --whitelist List of classes that should not be removed
8
[array] [default: []]
9
-h, --help Show help [boolean]
10
-v, --version Show version number [boolean]
Copied!
The options available through the CLI are similar to the ones available with a configuration file. You can also use the CLI with a configuration file.

--css

1
purgecss --css css/app.css css/palette.css --content src/index.html
Copied!

--content

You can specify content that should be analyzed by PurgeCSS with an array of filenames or globs. These files can be HTML, Pug, Blade, etc.
1
purgecss --css css/app.css --content src/index.html src/**/*.js
Copied!

--config

You can use the CLI with a configuration file. Use --config or -c with the path to the config file.
1
purgecss --config ./purgecss.config.js
Copied!

--out

By default, the CLI outputs the result in the console. If you wish to return the CSS as files, specify the directory to write the purified CSS files to.
1
purgecss --css css/app.css --content src/index.html src/**/*.js --out build/css/
Copied!

--whitelist

If you wish to prevent PurgeCSS from removing a specific CSS selector, you can whitelist it.
1
purgecss --css css/app.css --content src/index.html --whitelist classnameToWhitelist
Copied!

Example

You can see an example here.
Last modified 2yr ago