purgecss-webpack-plugin weekly downloads statistics
By FullHuman · npm · Webpack plugins
PurgeCSS plugin for webpack and Rspack - Remove unused css
purgecss-webpack-plugin has 52,969 recorded weekly downloads on npm, a decrease of 7.0% over the past 30 days, ranking #762 of 3,247 tracked listings.
About purgecss-webpack-plugin
purgecss-webpack-plugin
webpack and Rspack plugin to remove unused css.
Install
npm i purgecss-webpack-plugin -D
Usage
With mini-css-extract-plugin
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"),
},
optimization: {
splitChunks: {
cacheGroups: {
styles: {
name: "styles",
test: /\.css$/,
chunks: "all",
enforce: true,
},
},
},
},
module: {
rules: [
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
}),
new PurgeCSSPlugin({
paths: glob.sync(`${PATHS.src}/**/*`, { nodir: true }),
}),
],
};
With Rspack
The plugin works with Rspack as well, without webpack installed: it uses the classes of the bundler running it, and its TypeScript declarations do not depend on webpack. Use it with CssExtractRspackPlugin, or with the native CSS support of Rspack (type: "css/auto"). The tests run with Rspack 2. With Rspack 1, the used classes of CSS modules are kept from Rspack 1.1 on with CssExtractRspackPlugin, and from Rspack 1.3 on with the native CSS support; with older versions, the CSS modules are purged as in purgecss-webpack-plugin 9.0, which removes their hashed class names.
const path = require("path");
const glob = require("glob");
const { rspack } = require("@rspack/core");
const { PurgeCSSPlugin } = require("purgecss-webpack-plugin");
module.exports = {
entry: "./src/index.js",
module: {
rules: [
{
test: /\.css$/,
use: [rspack.CssExtractRspackPlugin.loader, "css-loader"],
type: "javascript/auto",
},
],
},
plugins: [
new rspack.CssExtractRspackPlugin(),
new PurgeCSSPlugin({
paths: glob.sync(`${path.join(__dirname, "src")}/**/*`, { nodir: true }),
}),
],
};
With Next.js
Next.js 16 builds with Turbopack by default, which does not run webpack plugins. Build with webpack to use the plugin: next build --webpack (and next dev --webpack), with the plugin added in the webpack function of next.config.js.
How the CSS is purged
The plugin purges the CSS assets of the chunks at the PROCESS_ASSETS_STAGE_ADDITIONAL stage of the processAssets hook, the stage of the deprecated additionalAssets hook it used before. Plugins that derive assets from the CSS at a later stage (e.g. a right-to-left copy at PROCESS_ASSETS_STAGE_DERIVED) read the purged CSS, and the CSS is purged before CSS minimizers (PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE), source map extraction and content hashing.
The content files of paths are read and their selectors extracted once per compilation, for all the CSS assets. In watch mode (--watch, webpack-dev-server, rspack dev), the content files are watched: a change to one of them triggers a new compilation, even if it is not imported by the JavaScript code, and only the files that changed since the previous compilation are read and extracted again. The directories are not watched: when paths is a function, a new file is part of the content from the next compilation on, once something else triggered it. A content file that does not exist is reported as an error of the compilation, and the compilation runs again once the file is created.
The watcher of the bundler applies its own options to the content files. When a content file is a symbolic link, e.g. a file of a workspace package linked in node_modules, the plugin watches its target as well, as the watchers do not follow symbolic links by default (watchOptions.followSymlinks). Rspack ignores the changes to the files of node_modules by default (watchOptions.ignored), the content files included.
With webpack-dev-server, the CSS is purged again when only a content file outside the module graph changed (e.g. an HTML template), but the hash of the compilation is the same, so webpack-dev-server does not tell the browser: reload the page to see the new CSS. With Rspack, the hash changes.
When the webpack devtool option generates source maps, the source maps of the purged CSS keep pointing to the original CSS files.
CSS modules
The class names of CSS modules are hashed (.modUsed becomes .card-module__modUsed--VlNeS), while the content uses the name of the export (styles.modUsed). The plugin reads the export map of each CSS module of the purged chunks and keeps the hashed class names whose export name is found in the content, along with the classes they compose. The other classes of the CSS modules are removed, like unused global classes.
The export maps are read from:
- the JavaScript module that mini-css-extract-plugin or
CssExtractRspackPlugingenerates for a CSS module (css-loaderwithmodules), with a default export or named exports; - the JavaScript code generated by the native CSS support of Rspack (
type: "css/auto"). In production, withoptimization.usedExports, Rspack only generates the exports used by the JavaScript code, possibly under mangled names: they are all kept; - the exports of the native CSS support of webpack 5.97 or later (
experiments.csswithtype: "css/auto"). With older versions, used classes of the CSS modules may be removed.…
Description from the npm listing.
- webpack-plugin
- rspack-plugin
- optimize
- optimization
- remove
- unused
- css
- html
- rules
- purge
- uncss
- purify
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (592)Similar npm Webpack plugins plugins
All 20 purgecss-webpack-plugin alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/purgecss-webpack-plugin. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.