Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

postcss-csso

lahmatiy89.8kMIT6.0.1

PostCSS plugin to minify CSS using CSSO

css, minifier, minify, compress, optimisation, csso, postcss, plugin

readme

NPM version Build Status Coverage Status Twitter

postcss-csso

PostCSS plugin to minify CSS using CSSO (a CSS minifier with structural optimizations).

Under the hood, the plugin converts PostCSS AST into CSSO's AST, optimises it and converts back. The plugin uses PostCSS's input AST nodes (or their clones) on back convertation, so the shape of the original PostCSS's nodes is preserved after the compression in most cases (e.g. properties added by other plugins aren't lost). This approach makes it possible to achieve great performance and correct source maps generation.

The performance of postcss-csso is approximately the same as CSSO has itself (see CSSO numbers in minifiers comparison table).

If you have any difficulties with the output of this plugin, please use the CSSO tracker.

Install

npm install postcss-csso

Usage

import postcss from 'postcss';
import csso from 'postcss-csso';
// CommonJS:
// const csso = require('postcss-csso');

postcss([
    csso
])
    .process('.a { color: #FF0000; } .b { color: rgba(255, 0, 0, 1) }')
    .then((result) => {
        console.log(result.css);
        // .a,.b{color:red}
    });

Plugin takes the same options as compress() method of CSSO with no exception.

postcss([
    csso({ restructure: false })
])
    .process('.a { color: #FF0000; } .b { color: rgba(255, 0, 0, 1) }')
    .then((result) => {
        console.log(result.css);
        // .a{color:red}.b{color:red}
    });

Using in postcss.config.js:

import csso from 'postcss-csso';

export const plugins = [
    csso({
        restructure: false
    })
];

License

MIT

changelog

6.0.1 (August 11, 2022)

  • Bumped csso to 5.0.5 which fixes various bugs

6.0.0 (December 14, 2021)

  • Changed supported versions of Node.js to ^12.20.0, ^14.13.0 and >=15.0.0
  • Converted to ES modules, CommonJS is supported as well (dual module)
  • Bumped csso to 5.0

5.0.1 (April 5, 2021)

  • Fixed order of compression processing to perform when everything else is finished (@onigoetz, #20)

5.0.0 (October 5, 2020)

  • Migrated to postcss@^8.0.0, dropped support for earlier versions
  • Dropped support for Node.js < 10.12
  • Removed explicit requires of postcss
  • Dropped process method in export

4.0.0 (November 2, 2019)

  • Dropped support for Node.js < 8.0
  • Added support for postcss ^7.0
  • Moved postcss to peer dependencies
  • Bumped csso to ^4.0

3.0.0 (October 12, 2017)

2.0.0 (March 14, 2017)

1.1.2 (May 8, 2016)

  • Fix CSS parse error handling (#5)

1.1.1 (April 12, 2016)

  • Fix exception when PostCSS at-rule node has no params (#4)

1.1.0 (April 7, 2016)

1.0.1 (March 19, 2016)

  • Refactoring and minor fixes

1.0.0 (March 16, 2016)

  • Initial release