csso
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
css-tree | 2.2.1 | 266.42 kB | MIT | prod | 1 |
CSSO, or CSS Optimizer, is an npm package used to minify CSS. Minification is performed through three types of transformations: cleaning (removal of redundants), compression (replacement with shorter forms), and restructuring (merging of declarations, rules, etc.). As a result, the output CSS is significantly reduced in size, enhancing web page load speeds and overall performance.
Using CSSO is fairly straightforward. First, you need to install the package via npm using the command npm install csso
. Once installed, you can implement CSSO in your JavaScript files. Here's an example of how it's typically used:
import { minify } from 'csso';
const minifiedCss = minify('.test { color: #ff0000; }').css;
console.log(minifiedCss);
// Output: .test{color:red}
You can also import CSSO using CommonJS:
const { minify } = require('csso');
const minifiedCss = minify('.test { color: #ff0000; }').css;
console.log(minifiedCss);
// Output: .test{color:red}
CSSO can also be used to minify CSS step by step:
import { syntax } from 'csso';
const ast = syntax.parse('.test { color: #ff0000; }');
const compressedAst = syntax.compress(ast).ast;
const minifiedCss = syntax.generate(compressedAst);
console.log(minifiedCss);
// Output: .test{color:red}
Detailed documentation for CSSO, including various functions, options, and usage examples, can be found on the CSSTree GitHub repository. The documentation provides insight into how the package parses CSS into AST, performs AST traversal, and generates AST back to CSS. The repository also contains information on related projects, APIs, source maps, usage data, and more.