Registry / devops / purgecss-webpack-plugin

purgecss-webpack-plugin

JSON →
library8.0.0jsnpmunverified

Webpack plugin to remove unused CSS using PurgeCSS. Version 8.0.0 (released 2025) is current stable; requires webpack 5 and ships TypeScript definitions. Key differentiators: supports mini-css-extract-plugin, dynamic paths via function for watch mode, safelist/blocklist options, and 'only' option to limit processing to specific entry points. Compatible with PurgeCSS configuration but excludes 'css' and 'content' options. Breaking changes in v8.0.0: reverted import pattern for PostCSS plugin back to default import. Release cadence: major versions every 1-2 years.

npm install purgecss-webpack-plugin
INSTALL
IMPORT
SIG · PURGECSS-WEBPACK-P
P
purgecss-webpack-plugin
devopsjavascriptv8.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PurgeCSSPlugin
import { PurgeCSSPlugin } from 'purgecss-webpack-plugin'
const PurgeCSSPlugin = require('purgecss-webpack-plugin')
ESM default is not available; named export only. CommonJS require works but destructure from .default? Use named import.
PurgeCSSPlugin (type)
import type { PurgeCSSPlugin } from 'purgecss-webpack-plugin'
TypeScript users can import the type for annotations. No default type export.
WebpackPluginInstance (type)
import { PurgeCSSPlugin } from 'purgecss-webpack-plugin'; const plugin: WebpackPluginInstance = new PurgeCSSPlugin({ paths: [] });
Although PurgeCSSPlugin conforms to Webpack's plugin interface, its type does not extend WebpackPluginInstance; you may need to cast or use inline types.

Basic webpack configuration with PurgeCSSPlugin and mini-css-extract-plugin to remove unused CSS.

const path = require('path'); const glob = require('glob'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const { PurgeCSSPlugin } = require('purgecss-webpack-plugin'); const PATHS = { src: path.join(__dirname, 'src') }; module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: path.join(__dirname, 'dist'), }, module: { rules: [ { test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader'], }, ], }, plugins: [ new MiniCssExtractPlugin({ filename: '[name].css' }), new PurgeCSSPlugin({ paths: glob.sync(`${PATHS.src}/**/*`, { nodir: true }), }), ], };
Debug
Known issues
breakingIn v8.0.0, the import pattern for the PostCSS plugin changed back to default import.
fix
Use import purgeCSSPlugin from '@fullhuman/postcss-purgecss' instead of named import.
affects: >=8.0.0
gotchaThe plugin does NOT accept 'css' or 'content' options from PurgeCSS; use 'paths' instead.
fix
Provide file paths via the 'paths' option (or a function returning paths).
affects: >=1.0.0
deprecatedWhitelist option was replaced by safelist in v3.0.0.
fix
Replace whitelist with safelist (standard, deep, greedy).
affects: >=3.0.0 <3.0.0
gotchaWhen using the 'only' option, the entry point names must match those generated by webpack's splitChunks – case-sensitive.
fix
Ensure entry names in 'only' array exactly match output chunk names.
affects: >=1.0.0
gotchaIf paths are provided as a function, it must return an array of strings and is called on each compilation; avoid asynchronous generation inside the function.
fix
Use synchronous glob patterns or pre-collect paths outside the webpack config.
affects: >=1.0.0
breakingv5.0.0 dropped support for Node.js < 12 and webpack < 5.
fix
Upgrade Node.js to >=12 and webpack to >=5.
affects: >=5.0.0
gotchaThe plugin does not automatically track file changes in watch mode unless the 'paths' option is a function or glob patterns are reevaluated.
fix
Pass a function to 'paths' that recalculates the file list on each compilation.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'purgecss-webpack-plugin'
Package not installed or missing from node_modules.
fix
Run: npm install purgecss-webpack-plugin --save-dev
TypeError: PurgeCSSPlugin is not a constructor
Using default import instead of named import (CommonJS).
fix
Use const { PurgeCSSPlugin } = require('purgecss-webpack-plugin');
ValidationError: Invalid options object. PurgeCSSPlugin has been initialized using an options object that does not match the API schema.
Incorrect option name (e.g., 'whitelist' instead of 'safelist').
fix
Use 'safelist' instead of deprecated 'whitelist'.
Error: No files found from the passed PurgeCSS options
The 'paths' option resolved to an empty array or no matching files.
fix
Check glob pattern; ensure files exist and paths are correct.
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): ModuleParseError: Module parse failed: Unexpected token
PurgeCSS plugin runs before CSS is extracted; ensure MiniCssExtractPlugin is placed before PurgeCSSPlugin in plugins array.
fix
Order plugins: [new MiniCssExtractPlugin(), new PurgeCSSPlugin()]
Upgrade
Version history
8.0.0latest on npm
Audit
Dependencies
webpackrequiredpeer dependency – required to run the plugin, must be >=5.0.0
mini-css-extract-pluginoptionalcommonly used together; the plugin requires extracted CSS files to purge
globoptionaltypically needed to specify file paths for content analysis
Agent activity
27 hits · last 30 days
node
24
Amazon
1
Resources