* Fixed issue [#756](https://github.com/jakubpawlowicz/clean-css/issues/756) - adds disabling font-weight optimizations.
* Fixed issue [#758](https://github.com/jakubpawlowicz/clean-css/issues/758) - ignores rules with empty selector.
* Fixed issue [#767](https://github.com/jakubpawlowicz/clean-css/issues/767) - disables remote `@import` inlining by default.
+* Fixed issue [#785](https://github.com/jakubpawlowicz/clean-css/issues/785) - adds `@font-face` de-duplication.
* Fixed issue [#791](https://github.com/jakubpawlowicz/clean-css/issues/791) - resolves imports in-memory if possible.
* Fixed issue [#801](https://github.com/jakubpawlowicz/clean-css/issues/801) - smarter `@import` inlining.
* Fixed issue [#817](https://github.com/jakubpawlowicz/clean-css/issues/817) - makes `off` disable rounding.
var mergeNonAdjacentBySelector = require('./merge-non-adjacent-by-selector');
var mergeNonAdjacentByBody = require('./merge-non-adjacent-by-body');
var restructure = require('./restructure');
+var removeDuplicateFontAtRules = require('./remove-duplicate-font-at-rules');
var removeDuplicateMediaQueries = require('./remove-duplicate-media-queries');
var mergeMediaQueries = require('./merge-media-queries');
case Token.BLOCK:
removeEmpty(token[2]);
isEmpty = token[2].length === 0;
+ break;
+ case Token.AT_RULE_BLOCK:
+ isEmpty = token[2].length === 0;
}
if (isEmpty) {
mergeAdjacent(tokens, context);
}
+ removeDuplicateFontAtRules(tokens, context);
+
if (context.options.mediaMerging) {
removeDuplicateMediaQueries(tokens, context);
var reduced = mergeMediaQueries(tokens, context);
--- /dev/null
+var serializeAll = require('../writer/one-time').all;
+
+var Token = require('../tokenizer/token');
+
+var FONT_FACE_SCOPE = '@font-face';
+
+function removeDuplicateFontAtRules(tokens) {
+ var fontAtRules = [];
+ var token;
+ var key;
+ var i, l;
+
+ for (i = 0, l = tokens.length; i < l; i++) {
+ token = tokens[i];
+
+ if (token[0] != Token.AT_RULE_BLOCK && token[1][0][1] != FONT_FACE_SCOPE) {
+ continue;
+ }
+
+ key = serializeAll([token]);
+
+ if (fontAtRules.indexOf(key) > -1) {
+ token[2] = [];
+ } else {
+ fontAtRules.push(key);
+ }
+ }
+}
+
+module.exports = removeDuplicateFontAtRules;
--- /dev/null
+var vows = require('vows');
+var optimizerContext = require('../test-helper').optimizerContext;
+
+vows.describe('remove duplicate @font-face at-rules')
+ .addBatch(
+ optimizerContext('advanced on', {
+ 'adjacent': [
+ '@font-face{font-family:test;src:url(fonts/test.woff2)}@font-face{font-family:test;src:url(fonts/test.woff2)}',
+ '@font-face{font-family:test;src:url(fonts/test.woff2)}'
+ ],
+ '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}'
+ ],
+ 'non-mergeable': [
+ '@font-face{font-family:test;src:url(fonts/test.woff2)}.one{color:#000}@font-face{font-family:test2;src:url(fonts/test.woff2)}',
+ '@font-face{font-family:test;src:url(fonts/test.woff2)}.one{color:#000}@font-face{font-family:test2;src:url(fonts/test.woff2)}'
+ ]
+ })
+ )
+ .addBatch(
+ optimizerContext('advanced off', {
+ 'keeps content same': [
+ '@font-face{font-family:test;src:url(fonts/test.woff2)}@font-face{font-family:test;src:url(fonts/test.woff2)}',
+ '@font-face{font-family:test;src:url(fonts/test.woff2)}@font-face{font-family:test;src:url(fonts/test.woff2)}'
+ ]
+ }, { advanced: false })
+ )
+ .export(module);