```bash
cleancss -O2 one.css
-cleancss -O2 mediaMerging:off;restructuring:off;semanticMerging:on;shorthandCompacting:off one.css
-cleancss -O2 all:off;duplicateRulesRemoving:on one.css
-# `adjacentRulesMerging` controls adjacent rules merging; defaults to `on`
-# `duplicateFontRulesRemoving` controls duplicate `@font-face` removing; defaults to `on`
-# `duplicateMediaRemoving` controls duplicate `@media` removing; defaults to `on`
-# `duplicateRulesRemoving` controls duplicate rules removing; defaults to `on`
-# `mediaMerging` controls `@media` merging; defaults to `on`
-# `nonAdjacentRulesMerging` controls non-adjacent rule merging; defaults to `on`
-# `nonAdjacentRulesReducing` controls non-adjacent rule reducing; defaults to `on`
-# `restructuring` controls content restructuring; defaults to `off`
-# `semanticMerging` controls semantic merging; defaults to `off`
-# `shorthandCompacting` controls shorthand compacting; defaults to `on`
+cleancss -O2 mergeMedia:off;restructureRules:off;mergeSemantically:on;compactShorthands:off one.css
+cleancss -O2 all:off;removeDuplicateRules:on one.css
+# `compactShorthands` controls shorthand compacting; defaults to `on`
+# `mergeAdjacentRules` controls adjacent rules merging; defaults to `on`
+# `mergeMedia` controls `@media` merging; defaults to `on`
+# `mergeNonAdjacentRules` controls non-adjacent rule merging; defaults to `on`
+# `mergeSemantically` controls semantic merging; defaults to `off`
+# `reduceNonAdjacentRules` controls non-adjacent rule reducing; defaults to `on`
+# `removeDuplicateFontRules` controls duplicate `@font-face` removing; defaults to `on`
+# `removeDuplicateMediaBlocks` controls duplicate `@media` removing; defaults to `on`
+# `removeDuplicateRules` controls duplicate rules removing; defaults to `on`
+# `restructureRules` controls rule restructuring; defaults to `off`
```
### How to use clean-css API?
new CleanCSS({
level: {
1: {
- all: false // sets all values to `false`
+ all: false, // sets all values to `false`
tidySelectors: true // turns on optimizing selectors
}
}
new CleanCSS({
level: {
2: {
- adjacentRulesMerging: true, // controls adjacent rules merging; defaults to true
- duplicateFontRulesRemoving: true, // controls duplicate `@font-face` removing; defaults to true
- duplicateMediaRemoving: true, // controls duplicate `@media` removing; defaults to true
- duplicateRulesRemoving: true, // controls duplicate rules removing; defaults to true
- mediaMerging: true, // controls `@media` merging; defaults to true
- nonAdjacentRulesMerging: true, // controls non-adjacent rule merging; defaults to true
- nonAdjacentRulesReducing: true, // controls non-adjacent rule reducing; defaults to true
- restructuring: false, // controls content restructuring; defaults to false
- semanticMerging: false, // controls semantic merging; defaults to false
- shorthandCompacting: true, // controls shorthand compacting; defaults to true
+ compactShorthands: true, // controls shorthand compacting; defaults to true
+ mergeAdjacentRules: true, // controls adjacent rules merging; defaults to true
+ mergeMedia: true, // controls `@media` merging; defaults to true
+ mergeNonAdjacentRules: true, // controls non-adjacent rule merging; defaults to true
+ mergeSemantically: false, // controls semantic merging; defaults to false
+ reduceNonAdjacentRules: true, // controls non-adjacent rule reducing; defaults to true
+ removeDuplicateFontRules: true, // controls duplicate `@font-face` removing; defaults to true
+ removeDuplicateMediaBlocks: true, // controls duplicate `@media` removing; defaults to true
+ removeDuplicateRules: true, // controls duplicate rules removing; defaults to true
+ restructureRules: false // controls rule restructuring; defaults to false
}
}
});
new CleanCSS({
level: {
1: {
- all: false // sets all values to `false`
- duplicateRulesRemoving: true // turns on removing duplicate rules
+ all: false, // sets all values to `false`
+ removeDuplicateRules: true // turns on removing duplicate rules
}
}
});
All level 2 optimizations are dispatched [here](https://github.com/jakubpawlowicz/clean-css/blob/master/lib/selectors/advanced.js#L59), and this is what they do:
* `recursivelyOptimizeBlocks` - does all the following operations on a block (think `@media` or `@keyframe` at-rules);
-* `recursivelyOptimizeProperties` - optimizes properties in rulesets and "flat at-rules" (like @font-face) by splitting them into components (e.g. `margin` into `margin-(*)`), optimizing, and rebuilding them back. You may want to use `shorthandCompacting` option to control whether you want to turn multiple (long-hand) properties into a shorthand ones;
+* `recursivelyOptimizeProperties` - optimizes properties in rulesets and "flat at-rules" (like @font-face) by splitting them into components (e.g. `margin` into `margin-(*)`), optimizing, and rebuilding them back. You may want to use `compactShorthands` option to control whether you want to turn multiple (long-hand) properties into a shorthand ones;
* `removeDuplicates` - gets rid of duplicate rulesets with exactly the same set of properties (think of including the same Sass / Less partial twice for no good reason);
* `mergeAdjacent` - merges adjacent rulesets with the same selector or rules;
* `reduceNonAdjacent` - identifies which properties are overridden in same-selector non-adjacent rulesets, and removes them;
console.log('');
console.log(' Level 2 optimizations:');
console.log(' %> cleancss -O2 one.css');
- console.log(' %> cleancss -O2 mediaMerging:off;restructuring:off;semanticMerging:on;shorthandCompacting:off one.css');
- console.log(' %> cleancss -O2 all:off;duplicateRulesRemoving:on one.css');
- console.log(' %> # `adjacentRulesMerging` controls adjacent rules merging; defaults to `on`');
- console.log(' %> # `duplicateFontRulesRemoving` controls duplicate `@font-face` removing; defaults to `on`');
- console.log(' %> # `duplicateMediaRemoving` controls duplicate `@media` removing; defaults to `on`');
- console.log(' %> # `duplicateRulesRemoving` controls duplicate rules removing; defaults to `on`');
- console.log(' %> # `mediaMerging` controls `@media` merging; defaults to `on`');
- console.log(' %> # `nonAdjacentRulesMerging` controls non-adjacent rule merging; defaults to `on`');
- console.log(' %> # `nonAdjacentRulesReducing` controls non-adjacent rule reducing; defaults to `on`');
- console.log(' %> # `restructuring` controls content restructuring; defaults to `off`');
- console.log(' %> # `semanticMerging` controls semantic merging; defaults to `off`');
- console.log(' %> # `shorthandCompacting` controls shorthand compacting; defaults to `on`');
+ console.log(' %> cleancss -O2 mergeMedia:off;restructureRules:off;mergeSemantically:on;compactShorthands:off one.css');
+ console.log(' %> cleancss -O2 all:off;removeDuplicateRules:on one.css');
+ console.log(' %> # `compactShorthands` controls shorthand compacting; defaults to `on`');
+ console.log(' %> # `mergeAdjacentRules` controls adjacent rules merging; defaults to `on`');
+ console.log(' %> # `mergeMedia` controls `@media` merging; defaults to `on`');
+ console.log(' %> # `mergeNonAdjacentRules` controls non-adjacent rule merging; defaults to `on`');
+ console.log(' %> # `mergeSemantically` controls semantic merging; defaults to `off`');
+ console.log(' %> # `reduceNonAdjacentRules` controls non-adjacent rule reducing; defaults to `on`');
+ console.log(' %> # `removeDuplicateFontRules` controls duplicate `@font-face` removing; defaults to `on`');
+ console.log(' %> # `removeDuplicateMediaBlocks` controls duplicate `@media` removing; defaults to `on`');
+ console.log(' %> # `removeDuplicateRules` controls duplicate rules removing; defaults to `on`');
+ console.log(' %> # `restructureRules` controls rule restructuring; defaults to `off`');
process.exit();
});
}
}
- if (withCompacting && context.options.level[OptimizationLevel.Two].shorthandCompacting) {
+ if (withCompacting && context.options.level[OptimizationLevel.Two].compactShorthands) {
compactOverrides(_properties, context.options.compatibility, validator);
compactShorthands(_properties, validator);
}
var Token = require('../../tokenizer/token');
function mergeMediaQueries(tokens, context) {
- var semanticMerging = context.options.level[OptimizationLevel.Two].semanticMerging;
+ var mergeSemantically = context.options.level[OptimizationLevel.Two].mergeSemantically;
var candidates = {};
var reduced = [];
var traversedProperties = extractProperties(tokens[from]);
from += delta;
- if (semanticMerging && allSameRulePropertiesCanBeReordered(movedProperties, traversedProperties)) {
+ if (mergeSemantically && allSameRulePropertiesCanBeReordered(movedProperties, traversedProperties)) {
continue;
}
function mergeNonAdjacentByBody(tokens, context) {
var options = context.options;
- var semanticMerging = options.level[OptimizationLevel.Two].semanticMerging;
+ var mergeSemantically = options.level[OptimizationLevel.Two].mergeSemantically;
var adjacentSpace = options.compatibility.selectors.adjacentSpace;
var mergeablePseudoClasses = options.compatibility.selectors.mergeablePseudoClasses;
var mergeablePseudoElements = options.compatibility.selectors.mergeablePseudoElements;
if (token[0] != Token.RULE)
continue;
- if (token[2].length > 0 && (!semanticMerging && unsafeSelector(serializeRules(token[1]))))
+ if (token[2].length > 0 && (!mergeSemantically && unsafeSelector(serializeRules(token[1]))))
candidates = {};
- if (token[2].length > 0 && semanticMerging && isBemElement(token))
+ if (token[2].length > 0 && mergeSemantically && isBemElement(token))
removeAnyUnsafeElements(token, candidates);
var candidateBody = serializeBody(token[2]);
recursivelyOptimizeBlocks(tokens, context);
recursivelyOptimizeProperties(tokens, context);
- if (levelOptions.duplicateRulesRemoving) {
+ if (levelOptions.removeDuplicateRules) {
removeDuplicates(tokens, context);
}
- if (levelOptions.adjacentRulesMerging) {
+ if (levelOptions.mergeAdjacentRules) {
mergeAdjacent(tokens, context);
}
- if (levelOptions.nonAdjacentRulesReducing) {
+ if (levelOptions.reduceNonAdjacentRules) {
reduceNonAdjacent(tokens, context);
}
- if (levelOptions.nonAdjacentRulesMerging && levelOptions.nonAdjacentRulesMerging != 'body') {
+ if (levelOptions.mergeNonAdjacentRules && levelOptions.mergeNonAdjacentRules != 'body') {
mergeNonAdjacentBySelector(tokens, context);
}
- if (levelOptions.nonAdjacentRulesMerging && levelOptions.nonAdjacentRulesMerging != 'selector') {
+ if (levelOptions.mergeNonAdjacentRules && levelOptions.mergeNonAdjacentRules != 'selector') {
mergeNonAdjacentByBody(tokens, context);
}
- if (levelOptions.restructuring && levelOptions.adjacentRulesMerging && withRestructuring) {
+ if (levelOptions.restructureRules && levelOptions.mergeAdjacentRules && withRestructuring) {
restructure(tokens, context);
mergeAdjacent(tokens, context);
}
- if (levelOptions.restructuring && !levelOptions.adjacentRulesMerging && withRestructuring) {
+ if (levelOptions.restructureRules && !levelOptions.mergeAdjacentRules && withRestructuring) {
restructure(tokens, context);
}
- if (levelOptions.duplicateFontRulesRemoving) {
+ if (levelOptions.removeDuplicateFontRules) {
removeDuplicateFontAtRules(tokens, context);
}
- if (levelOptions.duplicateMediaRemoving) {
+ if (levelOptions.removeDuplicateMediaBlocks) {
removeDuplicateMediaQueries(tokens, context);
}
- if (levelOptions.mediaMerging) {
+ if (levelOptions.mergeMedia) {
reduced = mergeMediaQueries(tokens, context);
for (i = reduced.length - 1; i >= 0; i--) {
level2Optimize(reduced[i][2], context, false);
tidySelectors: true
};
DEFAULTS[OptimizationLevel.Two] = {
- adjacentRulesMerging: true,
- duplicateFontRulesRemoving: true,
- duplicateMediaRemoving: true,
- duplicateRulesRemoving: true,
- mediaMerging: true,
- nonAdjacentRulesMerging: true,
- nonAdjacentRulesReducing: true,
- restructuring: false,
- semanticMerging: false,
- shorthandCompacting: true
+ compactShorthands: true,
+ mergeAdjacentRules: true,
+ mergeMedia: true,
+ mergeNonAdjacentRules: true,
+ mergeSemantically: false,
+ reduceNonAdjacentRules: true,
+ removeDuplicateFontRules: true,
+ removeDuplicateMediaBlocks: true,
+ removeDuplicateRules: true,
+ restructureRules: false
};
var ALL_KEYWORD_1 = '*';
keepBreaks: true,
level: {
2: {
- restructuring: true
+ restructureRules: true
}
}
}).minify(data.input, this.callback.bind(null, data));
keepBreaks: true,
level: {
2: {
- restructuring: true
+ restructureRules: true
}
},
sourceMap: true
'minifying via CLI': {
'topic': function (data) {
exec(
- '__DIRECT__=1 ./bin/cleancss -b -O2 restructuring:on ' + (isIE7Mode ? '-c ie7 ' : '') + path.join(dir, filename),
+ '__DIRECT__=1 ./bin/cleancss -b -O2 restructureRules:on ' + (isIE7Mode ? '-c ie7 ' : '') + path.join(dir, filename),
{ maxBuffer: 500 * 1024 },
this.callback.bind(null, data)
);
})
})
.addBatch({
- 'enable restructuring optimizations': pipedContext('div{margin-top:0}.one{margin:0}.two{display:block;margin-top:0}', '-O2 restructuring:on', {
+ 'enable restructuring optimizations': pipedContext('div{margin-top:0}.one{margin:0}.two{display:block;margin-top:0}', '-O2 restructureRules:on', {
'should do basic optimizations only': function (error, stdout) {
assert.equal(stdout, '.two,div{margin-top:0}.one{margin:0}.two{display:block}');
}
}
})
.addBatch({
- '@media merging': pipedContext('@media screen{a{color:red}}@media screen{a{display:block}}', '-O2 mediaMerging:off', {
+ '@media merging': pipedContext('@media screen{a{color:red}}@media screen{a{display:block}}', '-O2 mergeMedia:off', {
'gets right result': function (error, stdout) {
assert.equal(stdout, '@media screen{a{color:red}}@media screen{a{display:block}}');
}
})
.addBatch({
'shorthand compacting': {
- 'of (yet) unmergeable properties': pipedContext('a{background:url(image.png);background-color:red}', '-O2 shorthandCompacting:off', {
+ 'of (yet) unmergeable properties': pipedContext('a{background:url(image.png);background-color:red}', '-O2 compactShorthands:off', {
'gets right result': function (error, stdout) {
assert.equal(stdout, 'a{background:url(image.png);background-color:red}');
}
assert.equal(stdout, '.a{margin:0}.b{margin:10px;padding:0}.c{margin:0}');
}
}),
- 'enabled': pipedContext('.a{margin:0}.b{margin:10px;padding:0}.c{margin:0}', '-O2 semanticMerging:on', {
+ 'enabled': pipedContext('.a{margin:0}.b{margin:10px;padding:0}.c{margin:0}', '-O2 mergeSemantically:on', {
'should output right data': function (error, stdout) {
assert.equal(stdout, '.a,.c{margin:0}.b{margin:10px;padding:0}');
}
'.one{color:red;margin:0}.two{color:red}.one{margin:0}',
'.one,.two{color:red}.one{margin:0}'
]
- }, { level: { 2: { restructuring: true } } })
+ }, { level: { 2: { restructureRules: true } } })
)
.addBatch(
optimizerContext('units - IE8 compatibility', {
},
'restructuring - on': {
'topic': function () {
- new CleanCSS({ level: { 2: { restructuring: true } } }).minify('div{margin-top:0}.one{margin:0}.two{display:block;margin-top:0}', this.callback);
+ new CleanCSS({ level: { 2: { restructureRules: true } } }).minify('div{margin-top:0}.one{margin:0}.two{display:block;margin-top:0}', this.callback);
},
'gets right output': function (minified) {
assert.equal(minified.styles, '.two,div{margin-top:0}.one{margin:0}.two{display:block}');
},
'restructuring - off': {
'topic': function () {
- return new CleanCSS({ level: { 2: { restructuring: false } } }).minify('div{margin-top:0}.one{margin:0}.two{display:block;margin-top:0}');
+ return new CleanCSS({ level: { 2: { restructureRules: false } } }).minify('div{margin-top:0}.one{margin:0}.two{display:block;margin-top:0}');
},
'gets right output': function (minified) {
assert.equal(minified.styles, 'div{margin-top:0}.one{margin:0}.two{display:block;margin-top:0}');
},
'semantic merging - on': {
'topic': function () {
- return new CleanCSS({ level: { 2: { semanticMerging: true } } }).minify('.a{margin:0}.b{margin:10px;padding:0}.c{margin:0}');
+ return new CleanCSS({ level: { 2: { mergeSemantically: true } } }).minify('.a{margin:0}.b{margin:10px;padding:0}.c{margin:0}');
},
'gets right output': function (minified) {
assert.equal(minified.styles, '.a,.c{margin:0}.b{margin:10px;padding:0}');
compatibility: compat,
level: {
2: {
- mediaMerging: true,
- restructuring: true,
- semanticMerging: false,
- shorthandCompacting: true
+ mergeMedia: true,
+ restructureRules: true,
+ mergeSemantically: false,
+ compactShorthands: true
}
}
};
compatibility: compat,
level: {
2: {
- mediaMerging: false,
- restructuring: false,
- semanticMerging: false,
- shorthandCompacting: false
+ mergeMedia: false,
+ restructureRules: false,
+ mergeSemantically: false,
+ compactShorthands: false
}
}
};
compatibility: compat,
level: {
2: {
- shorthandCompacting: true
+ compactShorthands: true
}
}
};
compatibility: compat,
level: {
2: {
- shorthandCompacting: true
+ compactShorthands: true
}
}
};
'.one{color:red}@media print{.two{display:block}}.three{color:red}',
'.one,.three{color:red}@media print{.two{display:block}}'
],
- }, { level: { 2: { restructuring: true } } })
+ }, { level: { 2: { restructureRules: true } } })
)
.addBatch(
optimizerContext('with level 2 off but only adjacentRuleMerging on', {
'a{background:url(image.png)}a{display:block;width:75px;background-repeat:no-repeat}',
'a{background:url(image.png);display:block;width:75px;background-repeat:no-repeat}',
],
- }, { level: { 2: { all: false, adjacentRulesMerging: true } } })
+ }, { level: { 2: { all: false, mergeAdjacentRules: true } } })
)
.addBatch(
optimizerContext('with level 2 off', {
'@media (max-width:1px){.block{margin:1px}}.block__element{margin:2px}@media (max-width:1px){.block--modifier{margin:3px}}',
'.block__element{margin:2px}@media (max-width:1px){.block{margin:1px}.block--modifier{margin:3px}}'
]
- }, { level: { 2: { semanticMerging: true } } })
+ }, { level: { 2: { mergeSemantically: true } } })
)
.addBatch(
optimizerContext('with level 2 off', {
'@media screen{a{color:red}}@media screen{a{display:block}}',
'@media screen{a{color:red}}@media screen{a{display:block}}'
]
- }, { level: { 2: { mediaMerging: false } } })
+ }, { level: { 2: { mergeMedia: false } } })
)
.export(module);
}, { level: 2 })
)
.addBatch(
- optimizerContext('with level 2 off but nonAdjacentRulesMerging on', {
+ optimizerContext('with level 2 off but mergeNonAdjacentRules on', {
'of element selectors': [
'p{color:red}div{display:block}span{color:red}',
'p,span{color:red}div{display:block}'
]
- }, { level: { 2: { all: false, nonAdjacentRulesMerging: true } } })
+ }, { level: { 2: { all: false, mergeNonAdjacentRules: true } } })
)
.addBatch(
- optimizerContext('with level 2 off but nonAdjacentRulesMerging set to selector', {
+ optimizerContext('with level 2 off but mergeNonAdjacentRules set to selector', {
'of element selectors': [
'p{color:red}div{display:block}span{color:red}',
'p{color:red}div{display:block}span{color:red}'
]
- }, { level: { 2: { all: false, nonAdjacentRulesMerging: 'selector' } } })
+ }, { level: { 2: { all: false, mergeNonAdjacentRules: 'selector' } } })
)
.addBatch(
optimizerContext('with level 2 off', {
'.block1__element{color:#000}.block1__element--modifier{color:red}.block2{color:#000;display:block;width:100%}'
// '.block1__element,.block2{color:#000}.block1__element--modifier{color:red}.block2{display:block;width:100%}' - pending #588
]
- }, { level: { 2: { restructuring: true, semanticMerging: true } } })
+ }, { level: { 2: { restructureRules: true, mergeSemantically: true } } })
)
.addBatch(
optimizerContext('IE8 compatibility', {
}, { level: 2 })
)
.addBatch(
- optimizerContext('with level 2 off but nonAdjacentRulesMerging on', {
+ optimizerContext('with level 2 off but mergeNonAdjacentRules on', {
'of element selectors': [
'.one{color:red}.two{color:#fff}.one{font-weight:400}',
'.one{color:red;font-weight:400}.two{color:#fff}'
]
- }, { level: { 2: { all: false, nonAdjacentRulesMerging: true } } })
+ }, { level: { 2: { all: false, mergeNonAdjacentRules: true } } })
)
.addBatch(
- optimizerContext('with level 2 off but nonAdjacentRulesMerging set to body', {
+ optimizerContext('with level 2 off but mergeNonAdjacentRules set to body', {
'of element selectors': [
'.one{color:red}.two{color:#fff}.one{font-weight:400}',
'.one{color:red}.two{color:#fff}.one{font-weight:400}'
]
- }, { level: { 2: { all: false, nonAdjacentRulesMerging: 'body' } } })
+ }, { level: { 2: { all: false, mergeNonAdjacentRules: 'body' } } })
)
.addBatch(
optimizerContext('level 2 off', {
'a{padding:10px;margin:0;color:red}.one{color:red}a,p{color:red;padding:0}.one,a{color:#fff}',
'a{margin:0}a,p{color:red;padding:0}.one,a{color:#fff}'
]
- }, { level: { 2: { restructuring: true } } })
+ }, { level: { 2: { restructureRules: true } } })
)
.addBatch(
optimizerContext('level 2 on and aggressive merging off', {
'a{padding:10px;margin:0;color:red}.one{color:red}a,p{color:red;padding:0}',
'.one,a,p{color:red}a{padding:10px;margin:0}a,p{padding:0}'
]
- }, { aggressiveMerging: false, level: { 2: { restructuring: true } } })
+ }, { aggressiveMerging: false, level: { 2: { restructureRules: true } } })
)
.addBatch(
- optimizerContext('level 2 off but nonAdjacentRulesReducing on', {
+ optimizerContext('level 2 off but reduceNonAdjacentRules on', {
'non-adjacent with multi selectors': [
'a{padding:10px;margin:0;color:red}.one{color:red}a,p{color:red;padding:0}',
'a{margin:0;color:red}.one{color:red}a,p{color:red;padding:0}'
]
- }, { level: { 2: { all: false, nonAdjacentRulesReducing: true } } })
+ }, { level: { 2: { all: false, reduceNonAdjacentRules: true } } })
)
.addBatch(
optimizerContext('level 2 off', {
}, { level: 2 })
)
.addBatch(
- optimizerContext('level 2 off but duplicateFontRulesRemoving on', {
+ optimizerContext('level 2 off but removeDuplicateFontRules on', {
'non-adjacent': [
'@font-face{font-family:test;src:url(fonts/test.woff2)}.one{color:red}@font-face{font-family:test;src:url(fonts/test.woff2)}',
'@font-face{font-family:test;src:url(fonts/test.woff2)}.one{color:red}'
]
- }, { level: { 2: { all: false, duplicateFontRulesRemoving: true } } })
+ }, { level: { 2: { all: false, removeDuplicateFontRules: true } } })
)
.addBatch(
optimizerContext('level 2 off', {
}, { level: 2 })
)
.addBatch(
- optimizerContext('level 2 off but duplicateMediaRemoving on', {
+ optimizerContext('level 2 off but removeDuplicateMediaBlocks on', {
'non-adjacent': [
'@media screen{a{color:red}}@media print{a{color:#fff}}@media screen{a{color:red}}',
'@media print{a{color:#fff}}@media screen{a{color:red}}'
]
- }, { level: { 2: { all: false, duplicateMediaRemoving: true } } })
+ }, { level: { 2: { all: false, removeDuplicateMediaBlocks: true } } })
)
.addBatch(
optimizerContext('level 2 off', {
'@media screen{a{color:red}}@media screen{div{color:red}}',
'@media screen{a{color:red}}@media screen{div{color:red}}'
]
- }, { level: { 2: { mediaMerging: false } } })
+ }, { level: { 2: { mergeMedia: false } } })
)
.export(module);
'a{color:red}div{color:blue}a{color:red}',
'div{color:#00f}a{color:red}'
]
- }, { level: { 2: { all: false, duplicateRulesRemoving: true } } })
+ }, { level: { 2: { all: false, removeDuplicateRules: true } } })
)
.addBatch(
optimizerContext('level 2 off', {
'.one{border-color:#000;border-bottom-color:rgb(0,0,0,.2)}.two{border-color:#fff;border-bottom-color:rgb(0,0,0,.2)}',
'.one{border-color:#000;border-bottom-color:rgb(0,0,0,.2)}.two{border-color:#fff;border-bottom-color:rgb(0,0,0,.2)}'
]
- }, { level: { 2: { restructuring: true } } })
+ }, { level: { 2: { restructureRules: true } } })
)
.addBatch(
optimizerContext('level 2 off', {
},
'has level 2 options': function (levelOptions) {
assert.deepEqual(levelOptions['2'], {
- adjacentRulesMerging: true,
- duplicateFontRulesRemoving: true,
- duplicateMediaRemoving: true,
- duplicateRulesRemoving: true,
- mediaMerging: true,
- nonAdjacentRulesMerging: true,
- nonAdjacentRulesReducing: true,
- restructuring: false,
- semanticMerging: false,
- shorthandCompacting: true
+ compactShorthands: true,
+ mergeAdjacentRules: true,
+ mergeMedia: true,
+ mergeNonAdjacentRules: true,
+ mergeSemantically: false,
+ reduceNonAdjacentRules: true,
+ removeDuplicateFontRules: true,
+ removeDuplicateMediaBlocks: true,
+ removeDuplicateRules: true,
+ restructureRules: false
});
}
},
},
'has level 2 options': function (levelOptions) {
assert.deepEqual(levelOptions['2'], {
- adjacentRulesMerging: true,
- duplicateFontRulesRemoving: true,
- duplicateMediaRemoving: true,
- duplicateRulesRemoving: true,
- mediaMerging: true,
- nonAdjacentRulesMerging: true,
- nonAdjacentRulesReducing: true,
- restructuring: false,
- semanticMerging: false,
- shorthandCompacting: true
+ compactShorthands: true,
+ mergeAdjacentRules: true,
+ mergeMedia: true,
+ mergeNonAdjacentRules: true,
+ mergeSemantically: false,
+ reduceNonAdjacentRules: true,
+ removeDuplicateFontRules: true,
+ removeDuplicateMediaBlocks: true,
+ removeDuplicateRules: true,
+ restructureRules: false
});
}
},
},
'a hash with all keyword for level 2': {
'topic': function () {
- return optimizationLevelFrom({ 1: { specialComments: 0 }, 2: { all: false, mediaMerging: true } });
+ return optimizationLevelFrom({ 1: { specialComments: 0 }, 2: { all: false, mergeMedia: true } });
},
'has all options': function (levelOptions) {
assert.deepEqual(Object.keys(levelOptions), ['0', '1', '2']);
},
'has level 2 options': function (levelOptions) {
assert.deepEqual(levelOptions['2'], {
- adjacentRulesMerging: false,
- duplicateFontRulesRemoving: false,
- duplicateMediaRemoving: false,
- duplicateRulesRemoving: false,
- mediaMerging: true,
- nonAdjacentRulesMerging: false,
- nonAdjacentRulesReducing: false,
- restructuring: false,
- semanticMerging: false,
- shorthandCompacting: false
+ compactShorthands: false,
+ mergeAdjacentRules: false,
+ mergeMedia: true,
+ mergeNonAdjacentRules: false,
+ mergeSemantically: false,
+ reduceNonAdjacentRules: false,
+ removeDuplicateFontRules: false,
+ removeDuplicateMediaBlocks: false,
+ removeDuplicateRules: false,
+ restructureRules: false
});
}
},
'a hash with * keyword for level 2': {
'topic': function () {
- return optimizationLevelFrom({ 1: { specialComments: 0 }, 2: { '*': false, mediaMerging: true } });
+ return optimizationLevelFrom({ 1: { specialComments: 0 }, 2: { '*': false, mergeMedia: true } });
},
'has all options': function (levelOptions) {
assert.deepEqual(Object.keys(levelOptions), ['0', '1', '2']);
},
'has level 2 options': function (levelOptions) {
assert.deepEqual(levelOptions['2'], {
- adjacentRulesMerging: false,
- duplicateFontRulesRemoving: false,
- duplicateMediaRemoving: false,
- duplicateRulesRemoving: false,
- mediaMerging: true,
- nonAdjacentRulesMerging: false,
- nonAdjacentRulesReducing: false,
- restructuring: false,
- semanticMerging: false,
- shorthandCompacting: false
+ compactShorthands: false,
+ mergeAdjacentRules: false,
+ mergeMedia: true,
+ mergeNonAdjacentRules: false,
+ mergeSemantically: false,
+ reduceNonAdjacentRules: false,
+ removeDuplicateFontRules: false,
+ removeDuplicateMediaBlocks: false,
+ removeDuplicateRules: false,
+ restructureRules: false
});
}
},
},
'a hash with options as strings with boolean values': {
'topic': function () {
- return optimizationLevelFrom({ 2: 'mediaMerging:false;semanticMerging:true' });
+ return optimizationLevelFrom({ 2: 'mergeMedia:false;mergeSemantically:true' });
},
'has all options': function (levelOptions) {
assert.deepEqual(Object.keys(levelOptions), ['0', '1', '2']);
},
'has level 2 options': function (levelOptions) {
assert.deepEqual(levelOptions['2'], {
- adjacentRulesMerging: true,
- duplicateFontRulesRemoving: true,
- duplicateMediaRemoving: true,
- duplicateRulesRemoving: true,
- mediaMerging: false,
- nonAdjacentRulesMerging: true,
- nonAdjacentRulesReducing: true,
- restructuring: false,
- semanticMerging: true,
- shorthandCompacting: true
+ compactShorthands: true,
+ mergeAdjacentRules: true,
+ mergeMedia: false,
+ mergeNonAdjacentRules: true,
+ mergeSemantically: true,
+ reduceNonAdjacentRules: true,
+ removeDuplicateFontRules: true,
+ removeDuplicateMediaBlocks: true,
+ removeDuplicateRules: true,
+ restructureRules: false
});
}
},
'a hash with options as strings with boolean values as on/off': {
'topic': function () {
- return optimizationLevelFrom({ 2: 'mediaMerging:off;semanticMerging:on' });
+ return optimizationLevelFrom({ 2: 'mergeMedia:off;mergeSemantically:on' });
},
'has all options': function (levelOptions) {
assert.deepEqual(Object.keys(levelOptions), ['0', '1', '2']);
},
'has level 2 options': function (levelOptions) {
assert.deepEqual(levelOptions['2'], {
- adjacentRulesMerging: true,
- duplicateFontRulesRemoving: true,
- duplicateMediaRemoving: true,
- duplicateRulesRemoving: true,
- mediaMerging: false,
- nonAdjacentRulesMerging: true,
- nonAdjacentRulesReducing: true,
- restructuring: false,
- semanticMerging: true,
- shorthandCompacting: true
+ compactShorthands: true,
+ mergeAdjacentRules: true,
+ mergeMedia: false,
+ mergeNonAdjacentRules: true,
+ mergeSemantically: true,
+ reduceNonAdjacentRules: true,
+ removeDuplicateFontRules: true,
+ removeDuplicateMediaBlocks: true,
+ removeDuplicateRules: true,
+ restructureRules: false
});
}
},
'a hash with options as strings with all keyword': {
'topic': function () {
- return optimizationLevelFrom({ 2: 'all:false;mediaMerging:true;semanticMerging:true' });
+ return optimizationLevelFrom({ 2: 'all:false;mergeMedia:true;mergeSemantically:true' });
},
'has all options': function (levelOptions) {
assert.deepEqual(Object.keys(levelOptions), ['0', '1', '2']);
},
'has level 2 options': function (levelOptions) {
assert.deepEqual(levelOptions['2'], {
- adjacentRulesMerging: false,
- duplicateFontRulesRemoving: false,
- duplicateMediaRemoving: false,
- duplicateRulesRemoving: false,
- mediaMerging: true,
- nonAdjacentRulesMerging: false,
- nonAdjacentRulesReducing: false,
- restructuring: false,
- semanticMerging: true,
- shorthandCompacting: false
+ compactShorthands: false,
+ mergeAdjacentRules: false,
+ mergeMedia: true,
+ mergeNonAdjacentRules: false,
+ mergeSemantically: true,
+ reduceNonAdjacentRules: false,
+ removeDuplicateFontRules: false,
+ removeDuplicateMediaBlocks: false,
+ removeDuplicateRules: false,
+ restructureRules: false
});
}
},
'a hash with options as strings with * keyword': {
'topic': function () {
- return optimizationLevelFrom({ 2: '*:false;mediaMerging:true;semanticMerging:true' });
+ return optimizationLevelFrom({ 2: '*:false;mergeMedia:true;mergeSemantically:true' });
},
'has all options': function (levelOptions) {
assert.deepEqual(Object.keys(levelOptions), ['0', '1', '2']);
},
'has level 2 options': function (levelOptions) {
assert.deepEqual(levelOptions['2'], {
- adjacentRulesMerging: false,
- duplicateFontRulesRemoving: false,
- duplicateMediaRemoving: false,
- duplicateRulesRemoving: false,
- mediaMerging: true,
- nonAdjacentRulesMerging: false,
- nonAdjacentRulesReducing: false,
- restructuring: false,
- semanticMerging: true,
- shorthandCompacting: false
+ compactShorthands: false,
+ mergeAdjacentRules: false,
+ mergeMedia: true,
+ mergeNonAdjacentRules: false,
+ mergeSemantically: true,
+ reduceNonAdjacentRules: false,
+ removeDuplicateFontRules: false,
+ removeDuplicateMediaBlocks: false,
+ removeDuplicateRules: false,
+ restructureRules: false
});
}
},
'level 2 optimizations': {
'new property in restructuring': {
'topic': function () {
- return new CleanCSS({ level: { 2: { restructuring: true } }, sourceMap: true }).minify('a{color:#000}div{color:red}.one{display:block}.two{display:inline;color:red}');
+ return new CleanCSS({ level: { 2: { restructureRules: true } }, sourceMap: true }).minify('a{color:#000}div{color:red}.one{display:block}.two{display:inline;color:red}');
},
'has right output': function (minified) {
assert.equal(minified.styles, 'a{color:#000}.two,div{color:red}.one{display:block}.two{display:inline}');