Registry / serialization / csso
library5.0.5jsnpmunverified

CSSO (CSS Optimizer) is a CSS minifier that performs cleaning (removing redundancies), compression (replacing with shorter forms), and restructuring (merging declarations/rules) to reduce CSS file size. Version 5.0.5 (latest stable) supports ESM and CommonJS dual module, CSS Selectors Level 4, and ships TypeScript definitions. It is built on CSSTree for AST parsing and manipulation. Compared to other minifiers like clean-css, CSSO offers structural optimizations beyond simple compression. Maintained actively with frequent releases.

npm install csso
INSTALL
IMPORT
SIG · CSSO
C
csso
serializationjavascriptv5.0.5
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.

minify
✓ import { minify } from 'csso';
✗ const { minify } = require('csso');
ESM is recommended; CommonJS also supported via require().
syntax
✓ import { syntax } from 'csso';
✗ const syntax = require('csso/syntax');
The 'syntax' object provides CSSTree API. Access via 'csso/syntax' entry point available since v5.0.1.
compress
✓ import { compress } from 'csso/syntax';
✗ import { compress } from 'csso';
compress() is not exported from the main csso entry. Use 'csso/syntax' for step-by-step AST manipulation.
parse
✓ import { parse } from 'csso/syntax';
✗ import syntax from 'csso';
parse() is part of the CSSTree API available via 'csso/syntax'.
generate
✓ import { generate } from 'csso/syntax';
✗ const { generate } = require('csso/syntax');
ESM import preferred; generate() converts AST back to CSS string.

Demonstrates two ways to use CSSO: simple minify() call and step-by-step AST compression via syntax module.

import { minify } from 'csso'; const inputCSS = ` .test { color: #ff0000; font-weight: bold; } .test { color: green; } `; const result = minify(inputCSS); console.log(result.css); // Output: .test{color:green;font-weight:bold} // Step-by-step with syntax import { parse, compress, generate } from 'csso/syntax'; const ast = parse(inputCSS); const compressed = compress(ast); const outputCSS = generate(compressed.ast); console.log(outputCSS); // Same output
csso --version
Debug
Known issues
breakingCSSO v5 is ESM by default; CommonJS is supported but requires Node.js >=12.20.0 and using require().
fix
Use import syntax or ensure your project supports CommonJS with require('csso').
affects: >=5.0.0
breakingNode.js versions <12.20.0, <14.13.0, <15.0.0 are not supported in v5.
fix
Upgrade Node.js to ^12.20.0, ^14.13.0, or >=15.0.0.
affects: >=5.0.0
deprecatedCSSO v4 is no longer maintained; upgrade to v5 for latest features and security fixes.
fix
npm install csso@latest
affects: >=4.0.0 <5.0.0
gotchaCSSO does not guarantee API stability behind the 'syntax' field; it may change with CSSTree updates.
fix
If relying on syntax API, consider using CSSTree directly.
affects: *
gotchaWhen using 'csso/syntax', the compress() function returns an object with .ast property, not the AST directly.
fix
Use const compressedAst = compress(ast).ast;
affects: >=5.0.0
gotchaThe default export only provides minify(); other functions like compress/parse/generate are under 'csso/syntax'.
fix
Import from 'csso/syntax' for step-by-step AST manipulation.
affects: >=5.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/csso/dist/csso.js from /path/to/app.js not supported.
Trying to require() the ESM bundle instead of CommonJS entry.
fix
Use import or require('csso') which automatically resolves to CommonJS.
TypeError: csso.minify is not a function
Using default import instead of named import: import csso from 'csso' yields the module object, not minify directly.
fix
Use import { minify } from 'csso';
Cannot find module 'csso/syntax'
csso/syntax was added in v5.0.1; trying to use it with an older version.
fix
Update to csso@5.0.1 or later. npm install csso@latest
Upgrade
Version history
5.0.5latest on npm
Audit
Dependencies
css-treerequiredCSSO uses CSSTree for CSS parsing, AST traversal, and CSS generation. Required at runtime.
Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources