* Refactors CLI `--debug` to use these stats too.
* Moves `originalSize` field into `stats` one.
* Adds simplified and much faster empty elements removal.
* Adds missing `@import` processing to our benchmark (run via `npm run bench`).
* Fixed issue [#138](https://github.com/GoalSmashers/clean-css/issues/138) - makes CleanCSS interface OO.
+* Fixed issue [#145](https://github.com/GoalSmashers/clean-css/issues/145) - debug mode in library too.
* Fixed issue [#157](https://github.com/GoalSmashers/clean-css/issues/157) - gets rid of `removeEmpty` option.
* Fixed issue [#159](https://github.com/GoalSmashers/clean-css/issues/159) - escaped quotes inside content.
* Fixed issue [#162](https://github.com/GoalSmashers/clean-css/issues/162) - strip quotes from Base64 encoded URLs.
* `noRebase` - whether to skip URLs rebasing
* `noAdvanced` - set to true to disable advanced optimizations - selector & property merging, reduction, etc.
* `selectorsMergeMode` - `ie8` for IE8 compatibility mode, `*` for merging all (default)
+* `debug` - set to true to get minification statistics under `stats` property (see `test/custom-test.js` for examples)
### What are the clean-css' dev commands?
if (commands.selectorsMergeMode)
cleanOptions.selectorsMergeMode = commands.selectorsMergeMode;
if (commands.debug)
- options.debug = true;
+ cleanOptions.debug = true;
if (commands.args.length > 0) {
var source = commands.args[0];
options.source = source;
}
function minify(data) {
- var minified;
var minifier = new CleanCSS(cleanOptions);
+ var minified = minifier.minify(data);
- if (options.debug) {
- var start = process.hrtime();
- minified = minifier.minify(data);
- var taken = process.hrtime(start);
-
- console.error('Minification time: %dms', ~~(taken[0] * 1e3 + taken[1] / 1e6));
- console.error('Compression efficiency: %d%', ~~((1 - minified.length / CleanCSS.originalSize) * 100));
- } else {
- minified = minifier.minify(data);
+ if (cleanOptions.debug) {
+ console.error('Minification time: %dms', minifier.stats.timeSpent);
+ console.error('Compression efficiency: %d%', ~~(minifier.stats.efficiency * 100));
}
return minified;
module.exports = function(options) {
var lineBreak = process.platform == 'win32' ? '\r\n' : '\n';
+ var stats = {};
options = options || {};
options.keepBreaks = options.keepBreaks || false;
options.processImport = true;
var minify = function(data) {
- this.originalSize = data.length;
+ var startedAt;
+ if (options.debug) {
+ startedAt = process.hrtime();
+ stats.originalSize = data.length;
+ }
var replace = function() {
if (typeof arguments[0] == 'function')
});
// trim spaces at beginning and end
- return data.trim();
+ data = data.trim();
+
+ if (options.debug) {
+ var elapsed = process.hrtime(startedAt);
+ stats.timeSpent = ~~(elapsed[0] * 1e3 + elapsed[1] / 1e6);
+ stats.efficiency = 1 - data.length / stats.originalSize;
+ stats.minifiedSize = data.length;
+ }
+
+ return data;
};
return {
lineBreak: lineBreak,
options: options,
- minify: minify
+ minify: minify,
+ stats: stats
};
};
'should process CSS correctly': function(process) {
assert.equal(process('a{ color: #f00; }'), 'a{color:red}');
}
+ },
+ 'no debug': {
+ topic: function() {
+ var minifier = new CleanCSS();
+ minifier.minify('a{ color: #f00 }');
+ return minifier;
+ },
+ 'should not populate stats hash': function(minifier) {
+ assert.deepEqual({}, minifier.stats);
+ }
+ },
+ 'debug': {
+ topic: function() {
+ var minifier = new CleanCSS({ debug: true });
+ minifier.minify('a{ color: #f00 }');
+ return minifier;
+ },
+ 'should give time taken': function(minifier) {
+ assert.isNumber(minifier.stats.timeSpent);
+ },
+ 'should give original size': function(minifier) {
+ assert.equal(minifier.stats.originalSize, 16);
+ },
+ 'should give minified size': function(minifier) {
+ assert.equal(minifier.stats.minifiedSize, 12);
+ },
+ 'should give efficiency': function(minifier) {
+ assert.equal(minifier.stats.efficiency, 0.25);
+ }
}
}).export(module);