Registry / devops / esbuild-plugin-purgecss-2

esbuild-plugin-purgecss-2

JSON →
library1.0.1jsnpmunverified

An esbuild plugin for PurgeCSS that allows passing content (HTML/CSS) directly to the plugin configuration. Stable version 1.0.1 as of 2024. Based on the original esbuild-plugin-purgecss but with the added ability to specify content paths via plugin options, enabling tree-shaking of unused CSS during esbuild bundles. Supports glob patterns for content files. Ships TypeScript types, requires Node.js 10+, and works with esbuild v0.8+. A lightweight alternative to heavier PostCSS setups for CSS purging.

devopsserialization
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

ESM-only exports; requires "type": "module" in package.json for CJS projects. For CommonJS, use dynamic import().

import purgecssPlugin2 from 'esbuild-plugin-purgecss-2'

CJS require returns the plugin function directly, not as named export.

const purgecssPlugin2 = require('esbuild-plugin-purgecss-2')

Type-only import for TypeScript users; available in v1.0.0+.

import type { PurgecssPluginOptions } from 'esbuild-plugin-purgecss-2'

Demonstrates usage with esbuild build configuration, glob content paths, and plugin installation.

const glob = require('glob-all'); const purgecssPlugin2 = require('esbuild-plugin-purgecss-2'); require('esbuild').build({ entryPoints: ['src/app.js'], bundle: true, outfile: 'dist/app.js', plugins: [ purgecssPlugin2({ content: glob.sync([ './*.html', './views/**/*.html', './src/**/*.js', ]), }), ], }).catch(() => process.exit(1));
Debug
Known footguns
breakingThe package uses ESM-only exports; using require() directly will fail unless you use dynamic import or set "type": "module".
deprecatedThe original esbuild-plugin-purgecss is unmaintained; this fork adds content pass-through but may not receive updates.
gotchaGlob patterns must match files that are accessible at build time; ensure path correctness to avoid empty content.
gotchaThe plugin only runs on CSS output from esbuild; if your CSS is imported via JS (e.g., import './style.css'), ensure esbuild handles CSS.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
9 hits · last 30 days
gptbot
3
ahrefsbot
3
claudebot
3
Resources