Registry / serialization / clean-css

clean-css

JSON →
library5.3.3jsnpmunverified

A well-tested, fast and efficient CSS minifier for Node.js and browsers. Version 5.3.3 (stable) is released with patch updates over v5.3 (latest major). Clean-css outperforms many alternatives (cssnano, csso) in benchmarks, offering fine-grained optimization levels (0-2), compatibility modes (IE, standards), and source map support. It uses a highly modular plugin system and supports CLI, JavaScript API, and streaming. Engines require Node >= 10.0.

npm install clean-css
INSTALL
IMPORT
SIG · CLEAN-CSS
C
clean-css
serializationjavascriptv5.3.3
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.

CleanCSS
import CleanCSS from 'clean-css'
import { CleanCSS } from 'clean-css'
The library exports a default class; named import does not work. For CommonJS: const CleanCSS = require('clean-css').
CleanCSS (CommonJS)
const CleanCSS = require('clean-css')
const { CleanCSS } = require('clean-css')
Default export. Destructuring from require is incorrect.
minify
const CleanCSS = require('clean-css'); const output = new CleanCSS(options).minify(input)
CleanCSS.minify(input, options)
minify() is an instance method, not static.

Basic usage: instantiate CleanCSS with options, call minify() on a CSS string, and log the minified output.

const CleanCSS = require('clean-css'); const input = `body { font-size: 16px; color: red; }`; const options = { level: 2 }; const output = new CleanCSS(options).minify(input); console.log(output.styles); // Expected: "body{font-size:16px;color:red}"
cleancss --version
Debug
Known issues
breakingSwitched to ES module exports. CommonJS require() no longer works.
fix
Use dynamic import or ensure package is CJS-compatible. For v5, CommonJS require still works, but future versions may drop it.
affects: >=5.0.0
deprecatedReturn type changed from object with .styles to object with .styles (removed .sourceMap, .errors, .warnings in same object).
fix
Check output.styles instead of output.minified; errors in output.errors array.
affects: >=5.0.0
gotchaminify() is synchronous. For large files, use Promise interface with .minify() returns a Promise if option 'returnPromise' is true.
fix
Set options.returnPromise = true and await the call.
affects: >=4.0.0
gotchaCSS custom properties (variables) not optimized by default.
fix
Use level 1's variableValueOptimizers option to enable variable optimization.
affects: <5.3.0
breakingLevel 2 optimizations no longer merge selectors from different media queries by default.
fix
Set options.level[2].mergeMedia = true to restore old behavior.
affects: >=4.0.0
deprecatedSemantic merge option removed.
fix
Use Level 2 'restructureRules' or 'mergeSemantically' options (check docs).
affects: >=5.0.0
Errors
Common errors & fixes
Cannot find module 'clean-css'
clean-css not installed or incorrect import path.
fix
Run 'npm install clean-css' and use 'require('clean-css')' or 'import CleanCSS from 'clean-css''.
CleanCSS is not a constructor
Using import { CleanCSS } instead of import CleanCSS (default import).
fix
Use 'import CleanCSS from 'clean-css'' or CommonJS require.
output.minified is undefined
In v5+, output object key is 'styles' not 'minified'.
fix
Access 'output.styles' instead of 'output.minified'.
TypeError: Cannot read property 'styles' of undefined
minify() might have thrown error or invalid input.
fix
Call minify on a valid CSS string; check output.errors for details.
Upgrade
Version history
5.3.3latest on npm
Audit
Dependencies
source-mapoptionalSource map generation requires the source-map module. Optional if source maps not needed.
Agent activity
7 hits · last 30 days
node
4
Amazon
1
OpenAI (training)
1
Resources
clean-css — npm install clean-css · libregistry