How to execute CSSO command line CSS minifier on node.js

I'm trying to use CSSO command line on node.js.

Sadly, I can't understand how to just be able of call csso command.

Check this page for CSSO's documentation: https://github.com/css/csso#33-from-the-command-line

I've followed documentation page's steps downloading CSSO using NPM. And it's already installed because I can do a require("csso").justDoIt("....."), but this isn't fine for me, because I need to execute it in a command line since I require this CSS minifier during some Visual Studio build process.


Note that a solution wouldn't be use other compressor, because I've tried YUI, AjaxMin and other ones having command line interfaces, and those don't merge duplicated classes, identifiers and selectors into a single one.

Thank you in advance!!!

The csso file in the bin folder basically just calls the /csso/lib/csso.js file, so you should be able to patch your requirements around something like;

node /path/to/csso/lib/csso.js -i -o

Untested, it may require some working of variables but that should get you started on a solution!

use node's child process

var spawn = require('child_process').spawn,
csso  = spawn('csso/bin/csso', ['test.css']);

csso.stdout.on('data', function (data) {
  console.log('stdout: ' + data);
});