Sfoglia il codice sorgente

remove single-line comments if compressing CSS

Gildas 7 anni fa
parent
commit
1745b21879
1 ha cambiato i file con 11 aggiunte e 0 eliminazioni
  1. 11 0
      lib/single-file/single-file-core.js

+ 11 - 0
lib/single-file/single-file-core.js

@@ -729,6 +729,17 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 							stylesheetContent = await DomProcessorHelper.resolveImportURLs(element.textContent, this.baseURI, options);
 						}
 						const stylesheet = cssTree.parse(stylesheetContent);
+						if (options.compressCSS) {
+							const removedRules = [];
+							for (let cssRule = stylesheet.children.head; cssRule; cssRule = cssRule.next) {
+								if (cssRule.data.type == "Raw") {
+									if (cssRule.data.value.trim().startsWith("//")) {
+										removedRules.push(cssRule);
+									}
+								}
+							}
+							removedRules.forEach(cssRule => stylesheet.children.remove(cssRule));
+						}
 						this.stylesheets.get(element).stylesheet = stylesheet;
 					}
 				}));