Registry / devops / clean-css-cnwhy

clean-css-cnwhy

JSON →
library3.4.7jsnpmunverified

A fast and efficient Node.js library for minifying CSS files. Version 3.4.7 (stable) with moderate release cadence. Key differentiators: one of the best compression rates per benchmarks, supports advanced optimizations like restructuring, merging, and shorthand compacting, CLI and API available, compatibility modes for IE7/8. Compared to csso, it offers more configuration options but may be slightly slower.

npm install clean-css-cnwhy
INSTALL
IMPORT
SIG · CLEAN-CSS-CNWHY
C
clean-css-cnwhy
devopsjavascriptv3.4.7
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
const CleanCSS = require('clean-css');
import CleanCSS from 'clean-css';
clean-css v3 does not ship ESM; use CommonJS require. For newer versions (v4+), ES module imports are available.
minify
const CleanCSS = require('clean-css'); new CleanCSS().minify(source).styles;
require('clean-css').minify(source);
minify is an instance method, not a static method. You must instantiate CleanCSS first.
constructor options
new CleanCSS({ compatibility: 'ie8', level: 2 }).minify(source);
new CleanCSS().minify(source, { compatibility: 'ie8' });
Options are passed to the constructor, not to minify(). In v3, use object literal with options like 'compatibility', 'keepBreaks', etc.

Shows basic usage: require, instantiate, minify a CSS string, and output minified result.

const CleanCSS = require('clean-css'); const source = 'a { font-weight: bold; } h1 { color: red; }'; const minified = new CleanCSS({}).minify(source).styles; console.log(minified); // 'a{font-weight:bold}h1{color:red}'
Debug
Known issues
breakingIn clean-css v3, the minify() method returns an object with 'styles' property, not a string.
fix
Access minified.styles instead of treating the result as a string.
affects: 3.x
deprecatedIn v4+, the API changed to promise-based and options restructuring. v3 API is deprecated.
fix
Upgrade to new API: const output = await new CleanCSS().minify(source);
affects: >=4.0
gotchaThe CLI command is 'cleancss', not 'clean-css'.
fix
Use 'cleancss' as the command in terminal.
affects: all
gotchaThe 'compatibility' option only supports 'ie7' or 'ie8' in v3, not newer browsers.
fix
Use 'ie8' for legacy compatibility, or omit for standard mode.
affects: 3.x
Errors
Common errors & fixes
TypeError: cleanCss.minify is not a function
Calling minify on the required module directly without instantiation.
fix
new CleanCSS().minify(source);
ReferenceError: CleanCSS is not defined
ES module import in a CommonJS environment without transpilation.
fix
Use require('clean-css') or use a bundler for ES imports.
Unexpected token: punc ())
Using source maps with invalid input or missing source map generation.
fix
Ensure source map options are correctly passed to constructor.
Upgrade
Version history
3.4.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
clean-css-cnwhy — npm install clean-css-cnwhy · libregistry