Registry / devops / rs-classnames-minifier

rs-classnames-minifier

JSON →
library0.1.8jsnpmunverified

Webpack plugin that minifies CSS module class names to short alphanumeric tokens (e.g., .header -> .a) to reduce HTML and CSS size by up to 20%, improving FCP. Stable v0.1.8, requires css-loader >=4.0.0. Supports caching between builds, custom prefixes, and reserved names. The minification logic is derived from next-classnames-minifier. Ships TypeScript types. Alternative to css-minimizer-webpack-plugin for CSS modules specifically.

npm install rs-classnames-minifier
INSTALL
IMPORT
SIG · RS-CLASSNAMES-MINI
R
rs-classnames-minifier
devopsjavascriptv0.1.8
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.

ClassnamesMinifier
import { ClassnamesMinifier } from 'classnames-minifier'
const ClassnamesMinifier = require('classnames-minifier')
ESM/CJS dual package; named export only.

Initializes ClassnamesMinifier with prefix and cache, then uses getLocalIdent in css-loader for minified classnames.

const path = require('path'); const ClassnamesMinifier = require('classnames-minifier').ClassnamesMinifier; const cm = new ClassnamesMinifier({ prefix: '_', reservedNames: ['_reserved'], cacheDir: path.join(__dirname, 'build/cache'), distDir: path.join(__dirname, 'build') }); module.exports = { module: { rules: [{ test: /\.module\.css$/, use: [ 'style-loader', { loader: 'css-loader', options: { modules: { getLocalIdent: cm.getLocalIdent } } } ] }] } };
Debug
Known issues
gotchaThe minifier only works with CSS modules; plain CSS files are unaffected.
fix
Ensure your CSS files use CSS modules syntax (e.g., .module.css extension) and are processed by css-loader with modules option enabled.
affects: >=0.0.0
gotchaEnabling caching requires both distDir and cacheDir; otherwise caching is disabled.
fix
Set both distDir and cacheDir in constructor options to enable persistent caching across builds.
affects: >=0.1.0
breakingBreaking: CSS modules hash may change across versions, invalidating cached class names in production
fix
Avoid relying on specific minified names being permanent; clear cache if upgrading.
affects: <0.2.0
gotchaPrefix must be included in reservedNames if you want to prevent collisions.
fix
Add the prefix (e.g., '_') to reservedNames array when instantiating ClassnamesMinifier.
affects: >=0.0.0
deprecatedpreLoader and postLoader properties are deprecated; use getLocalIdent directly.
fix
Remove preLoader/postLoader from webpack config and only use getLocalIdent in css-loader options. See docs for migration.
affects: >=0.1.5
breakingVersion 0.1.0 changed the default minification algorithm from sequential letters to base-62 short codes.
fix
If you have cached class names, clear cache and rebuild to avoid mismatches.
affects: >=0.1.0 <0.2.0
Errors
Common errors & fixes
Error: Cannot find module 'classnames-minifier'
Package not installed or named incorrectly.
fix
Run 'npm install classnames-minifier' and ensure package.json contains it.
TypeError: ClassnamesMinifier is not a constructor
Using default import instead of named import.
fix
Use 'const { ClassnamesMinifier } = require('classnames-minifier')' or 'import { ClassnamesMinifier } from 'classnames-minifier''.
Module build failed (from ./node_modules/css-loader/dist/cjs.js): Error: getLocalIdent is not a function
getLocalIdent not assigned or wrong property name.
fix
Set css-loader options.modules.getLocalIdent to cm.getLocalIdent (cm is ClassnamesMinifier instance).
Error: cacheDir must be provided for caching
Missing cacheDir option in constructor.
fix
Add cacheDir and distDir options to ClassnamesMinifier constructor.
Upgrade
Version history
0.1.8latest on npm
Audit
Dependencies
css-loaderrequiredPeer dependency: getLocalIdent integration requires css-loader >=4.0.0.
Agent activity
4 hits · last 30 days
node
4
Resources
rs-classnames-minifier — npm install rs-classnames-minifier · libregistry