From e9d91ab0f2781d78049982b1d9207c5332a2ca88 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Tue, 3 Apr 2018 16:59:15 -0400 Subject: [PATCH] Instead of replacing empty rules with comments, remove them. --- config/critters-webpack-plugin.js | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/config/critters-webpack-plugin.js b/config/critters-webpack-plugin.js index 13a452c6..6e853b53 100644 --- a/config/critters-webpack-plugin.js +++ b/config/critters-webpack-plugin.js @@ -126,25 +126,14 @@ module.exports = class CrittersWebpackPlugin { sel = sel.replace(/::?(?:[a-z-]+)([.[#~&^:*]|\s|\n|$)/gi, '$1'); return document.querySelector(sel, document) != null; }); - // If there are no matched selectors, replace the rule with a comment. + // If there are no matched selectors, remove the rule: if (rule.selectors.length===0) { - rule.type = 'comment'; - rule.comment = ''; - delete rule.selectors; - delete rule.declarations; + return false; } } - if (rule.rules) { - // Filter out comments - rule.rules = rule.rules.filter(notComment); - // If there are no remaining rules, replace the parent rule with a comment. - if (rule.rules.length===0) { - rule.type = 'comment'; - rule.comment = ''; - delete rule.rules; - } - } + // If there are no remaining rules, remove the whole rule. + return !rule.rules || rule.rules.length!==0; }); sheet = css.stringify(ast, { compress: this.options.compress!==false });