Registry / devops / css-classes-minifier

css-classes-minifier

JSON →
library1.0.1jsnpmunverified

A build-time utility that renames CSS class names to shorter generated strings, reducing HTML/CSS/JS bundle size. v1.0.1 is the latest stable version (no release cadence documented). Key differentiator: focuses specifically on class name minification rather than general CSS minification, with support for prefix/suffix/whitelist and glob-based file selection. Limitations include inability to handle dynamically concatenated class names (e.g., template literals). Alternative: css-minimizer-webpack-plugin or purgecss for more comprehensive CSS optimization.

npm install css-classes-minifier
INSTALL
IMPORT
SIG · CSS-CLASSES-MINIFI
C
css-classes-minifier
devopsjavascriptv1.0.1
harness data pending
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.

default
import cssClassesMinifier from 'css-classes-minifier';
const cssClassesMinifier = require('css-classes-minifier');
Package is ESM-only. CommonJS require will fail.
cssClassesMinifier
await cssClassesMinifier({ files: ['*.js'], css: ['*.css'] });
The default export is an async function. Options object is required.

Minifies CSS class names in JS/HTML files and replaces them in CSS files, adding prefix and suffix, excluding a whitelist.

import cssClassesMinifier from 'css-classes-minifier'; (async () => { await cssClassesMinifier({ files: ['src/**/*.js', 'src/**/*.html'], css: ['src/**/*.css'], prefix: 'x-', suffix: '-min', whitelist: ['keep-this'] }); console.log('Class renaming complete.'); })();
Debug
Known issues
gotchaDynamic class names (e.g., `className={cls ?? 'default'}`) are not recognized and may be skipped or incorrectly renamed.
fix
Ensure all class names are literal strings without concatenation or template variables.
affects: >=1.0.0
gotchaThe tool only searches for classes in CSS files specified by the `css` param and also replaces in `files` param; if a CSS file is not included in `css`, classes inside it will not be replaced.
fix
Include all CSS files in both `files` and `css` parameters.
affects: >=1.0.0
gotchaThe regular expression used to find class names may incorrectly match within strings that are not actual CSS class usage (e.g., in comments or other contexts).
fix
Use a build tool with proper AST parsing for more reliable class renaming.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: cssClassesMinifier is not a function
Using CommonJS require('css-classes-minifier') which returns undefined because the package is ESM-only.
fix
Use import statement: import cssClassesMinifier from 'css-classes-minifier';
Cannot find module 'css-classes-minifier'
Package not installed or incorrect import path.
fix
Run: npm install css-classes-minifier
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
css-classes-minifier — npm install css-classes-minifier · libregistry