{"id":25146,"library":"cssnano","title":"cssnano","description":"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.","status":"active","version":"7.1.7","language":"javascript","source_language":"en","source_url":"https://github.com/cssnano/cssnano","tags":["javascript","css","compress","minify","optimise","optimisation","postcss","postcss-plugin","typescript"],"install":[{"cmd":"npm install cssnano","lang":"bash","label":"npm"},{"cmd":"yarn add cssnano","lang":"bash","label":"yarn"},{"cmd":"pnpm add cssnano","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; cssnano is a PostCSS plugin","package":"postcss","optional":false}],"imports":[{"note":"Default export since version 7; used as a PostCSS plugin. For CJS, use require('cssnano').default.","wrong":"const { default: cssnano } = require('cssnano');","symbol":"cssnano","correct":"import cssnano from 'cssnano';"},{"note":"Named export for the default preset since v7.","wrong":"import defaultPreset from 'cssnano/presets/default';","symbol":"defaultPreset","correct":"import { defaultPreset } from 'cssnano';"},{"note":"Named export for the advanced preset; also available as a named export from the main entry.","wrong":"const advancedPreset = require('cssnano/presets/advanced');","symbol":"advancedPreset","correct":"import { advancedPreset } from 'cssnano';"}],"quickstart":{"code":"import postcss from 'postcss';\nimport cssnano from 'cssnano';\n\nconst input = 'h1 { color: red; color: red; }';\n\npostcss([cssnano({ preset: 'default' })])\n  .process(input, { from: undefined })\n  .then(result => {\n    console.log(result.css); // outputs: 'h1{color:red}'\n  });","lang":"typescript","description":"Demonstrates using cssnano as a PostCSS plugin to minify CSS with the default preset."},"warnings":[{"fix":"Use import { defaultPreset } from 'cssnano' instead of require('cssnano/presets/default').","message":"v7 changed the import path for presets; previously available as cssnano/presets/default, now exported as named exports from main entry.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Replace preset: 'safe' with preset: 'default' and adjust options if needed.","message":"The 'safe' preset is deprecated and will be removed in a future version, use 'default' or 'advanced' with explicit options.","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Always provide from: 'input.css' (or undefined) in the postcss options.","message":"cssnano requires a from option in postcss.process when using a preset that relies on source maps; otherwise can fail silently.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Upgrade Node.js to a supported version (18, 20, 22+).","message":"Node.js engine requirement increased to ^18.12.0 || ^20.9.0 || >=22.0 in v7, dropping support for Node 14 and 16.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Avoid relying on these plugins; use the main cssnano package without them.","message":"The 'postcss-discard-unused' and 'postcss-merge-idents' plugins are deprecated and will be removed; their functionality may be merged into core.","severity":"deprecated","affected_versions":">=6.0.0"},{"fix":"Place cssnano last in the PostCSS plugins array.","message":"When using cssnano in a build tool like webpack with css-loader, ensure cssnano is applied after all other PostCSS plugins to maximize optimization.","severity":"gotcha","affected_versions":">=5.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'npm install postcss@^8.5.10' to upgrade postcss.","cause":"Mismatched postcss version; cssnano v7 requires postcss@^8.5.10.","error":"Error: PostCSS plugin cssnano requires PostCSS 8.0.0 or higher."},{"fix":"Use const cssnano = require('cssnano').default; or switch to ESM import.","cause":"CommonJS require() returns an object with default property; need to call .default.","error":"TypeError: cssnano is not a function"},{"fix":"Use import { defaultPreset } from 'cssnano'; instead.","cause":"Import path changed in v7; presets now export from main entry.","error":"Error: Cannot find module 'cssnano/presets/default'"},{"fix":"Use preset: 'default' instead.","cause":"The 'safe' preset was removed in recent versions.","error":"Warning: unknown preset 'safe'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}