Registry / http-networking / cssnano

cssnano

JSON →
library7.1.7jsnpmunverified

A modular CSS minifier built on top of PostCSS, version 7.1.7. It optimizes CSS by removing whitespace, comments, duplicated rules, and applying transformations like merging rules, converting values, and minifying selectors. Release cadence is frequent with monthly patch releases. Key differentiators: modular design with presets (default, advanced, etc.), extensive plugin ecosystem, and deep PostCSS integration. Supports Node.js >=18.12.0, ships TypeScript declarations, and requires postcss@^8.5.10 as a peer dependency.

npm install cssnano
INSTALL
IMPORT
SIG · CSSNANO
C
cssnano
http-networkingjavascriptv7.1.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.

cssnano
import cssnano from 'cssnano';
const { default: cssnano } = require('cssnano');
Default export since version 7; used as a PostCSS plugin. For CJS, use require('cssnano').default.
defaultPreset
import { defaultPreset } from 'cssnano';
import defaultPreset from 'cssnano/presets/default';
Named export for the default preset since v7.
advancedPreset
import { advancedPreset } from 'cssnano';
const advancedPreset = require('cssnano/presets/advanced');
Named export for the advanced preset; also available as a named export from the main entry.

Demonstrates using cssnano as a PostCSS plugin to minify CSS with the default preset.

import postcss from 'postcss'; import cssnano from 'cssnano'; const input = 'h1 { color: red; color: red; }'; postcss([cssnano({ preset: 'default' })]) .process(input, { from: undefined }) .then(result => { console.log(result.css); // outputs: 'h1{color:red}' });
Debug
Known issues
breakingv7 changed the import path for presets; previously available as cssnano/presets/default, now exported as named exports from main entry.
fix
Use import { defaultPreset } from 'cssnano' instead of require('cssnano/presets/default').
affects: >=7.0.0
deprecatedThe 'safe' preset is deprecated and will be removed in a future version, use 'default' or 'advanced' with explicit options.
fix
Replace preset: 'safe' with preset: 'default' and adjust options if needed.
affects: >=5.0.0
gotchacssnano requires a from option in postcss.process when using a preset that relies on source maps; otherwise can fail silently.
fix
Always provide from: 'input.css' (or undefined) in the postcss options.
affects: >=4.0.0
breakingNode.js engine requirement increased to ^18.12.0 || ^20.9.0 || >=22.0 in v7, dropping support for Node 14 and 16.
fix
Upgrade Node.js to a supported version (18, 20, 22+).
affects: >=7.0.0
deprecatedThe 'postcss-discard-unused' and 'postcss-merge-idents' plugins are deprecated and will be removed; their functionality may be merged into core.
fix
Avoid relying on these plugins; use the main cssnano package without them.
affects: >=6.0.0
gotchaWhen using cssnano in a build tool like webpack with css-loader, ensure cssnano is applied after all other PostCSS plugins to maximize optimization.
fix
Place cssnano last in the PostCSS plugins array.
affects: >=5.0.0
Errors
Common errors & fixes
Error: PostCSS plugin cssnano requires PostCSS 8.0.0 or higher.
Mismatched postcss version; cssnano v7 requires postcss@^8.5.10.
fix
Run 'npm install postcss@^8.5.10' to upgrade postcss.
TypeError: cssnano is not a function
CommonJS require() returns an object with default property; need to call .default.
fix
Use const cssnano = require('cssnano').default; or switch to ESM import.
Error: Cannot find module 'cssnano/presets/default'
Import path changed in v7; presets now export from main entry.
fix
Use import { defaultPreset } from 'cssnano'; instead.
Warning: unknown preset 'safe'
The 'safe' preset was removed in recent versions.
fix
Use preset: 'default' instead.
Upgrade
Version history
7.1.7latest on npm
Audit
Dependencies
postcssrequiredpeer dependency; cssnano is a PostCSS plugin
Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
1
Resources