Comparing version 1.0.4 to 1.0.5
import * as cssTree from "css-tree"; | ||
import fs from "fs"; | ||
import CleanCSS from "clean-css"; | ||
import { generateObfuscatedNames } from "./class-name-generator.js"; | ||
import { generateClassMap } from "./class-map.js"; | ||
import { getStylesFromHtmlStyleTags } from "./html-functions.js"; | ||
import { minify } from "csso"; | ||
/** | ||
@@ -76,3 +76,2 @@ * Extract class names from CSS content | ||
export function replaceClassNamesInCSS(content, classMap, cssOptions) { | ||
const { sourceMap, minify } = cssOptions; | ||
// Parse the CSS content into an AST | ||
@@ -95,7 +94,8 @@ const ast = cssTree.parse(content); | ||
// Minify the CSS content | ||
if (minify) { | ||
const minifyResult = new CleanCSS({ | ||
sourceMap, | ||
}).minify(newContent); | ||
newContent = minifyResult.styles; | ||
if (cssOptions.minify) { | ||
newContent = minify(newContent, { | ||
restructure: cssOptions.restructure, | ||
forceMediaMerge: cssOptions.forceMediaMerge, | ||
comments: false, | ||
}).css; | ||
} | ||
@@ -102,0 +102,0 @@ return newContent; |
@@ -38,7 +38,2 @@ import { SkipRule } from "./js-functions.js"; | ||
/** | ||
* Whether to generate source maps | ||
* @default true | ||
*/ | ||
sourceMap: boolean; | ||
/** | ||
* Whether to shuffle class names | ||
@@ -55,2 +50,16 @@ * @default true | ||
minify?: boolean; | ||
/** | ||
* Whether to restructure the CSS with CSSO for maximum compression | ||
* @default true | ||
*/ | ||
restructure?: boolean; | ||
/** | ||
* Whether to force media merge with CSSO | ||
* @default true | ||
*/ | ||
forceMediaMerge?: boolean; | ||
/** | ||
* Whether to extract class names from style tags found in HTML files | ||
* @default true | ||
*/ | ||
extractClassesFromHtml?: boolean; | ||
@@ -57,0 +66,0 @@ }; |
@@ -13,6 +13,7 @@ import merge from "lodash.merge"; | ||
css: { | ||
sourceMap: true, | ||
shuffle: false, | ||
minify: true, | ||
extractClassesFromHtml: true, | ||
restructure: true, | ||
forceMediaMerge: true, | ||
}, | ||
@@ -19,0 +20,0 @@ js: { |
@@ -12,3 +12,3 @@ import { Command, Option } from "commander"; | ||
const booleanParser = (val) => val === "true"; | ||
program.version("1.0.4").name("breezify"); | ||
program.version("1.0.5").name("breezify"); | ||
program | ||
@@ -25,5 +25,2 @@ .command("do") | ||
.option("--css.ignoreClassPatterns <ignoreClassPatterns...>", "RegExp patterns to ignore") | ||
.addOption(new Option("--css.sourceMap <sourceMap>", "generate source maps") | ||
.choices(booleanChoices) | ||
.argParser(booleanParser)) | ||
.addOption(new Option("--css.shuffle <shuffle>", "shuffle class names") | ||
@@ -33,5 +30,11 @@ .choices(booleanChoices) | ||
.option("--css.prefix <prefix>", "prefix to add to class names") | ||
.addOption(new Option("--css.minify <minify>", "minify the output CSS") | ||
.addOption(new Option("--css.minify <minify>", "minify the output CSS with CSSO") | ||
.choices(booleanChoices) | ||
.argParser(booleanParser)) | ||
.addOption(new Option("--css.restructure <restructure>", "restructure the output CSS with CSSO") | ||
.choices(booleanChoices) | ||
.argParser(booleanParser)) | ||
.addOption(new Option("--css.forceMediaMerge <forceMediaMerge>", "force media merge with CSSO") | ||
.choices(booleanChoices) | ||
.argParser(booleanParser)) | ||
.addOption(new Option("--css.extractClassesFromHtml <extractClassesFromHtml>", "whether to extract class names from style tags found in HTML files") | ||
@@ -38,0 +41,0 @@ .choices(booleanChoices) |
{ | ||
"name": "breezify", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "A tool for minifying CSS class names", | ||
@@ -50,5 +50,5 @@ "author": "Gleb Gorokhov <theververy@gmail.com>", | ||
"chalk": "^5.3.0", | ||
"clean-css": "^5.3.3", | ||
"commander": "^12.0.0", | ||
"css-tree": "^2.3.1", | ||
"csso": "^5.0.5", | ||
"glob": "^10.3.10", | ||
@@ -64,3 +64,3 @@ "html-minifier": "^4.0.0", | ||
"devDependencies": { | ||
"@types/clean-css": "^4.2.11", | ||
"@types/csso": "^5.0.4", | ||
"@types/css-tree": "^2.3.6", | ||
@@ -67,0 +67,0 @@ "@types/html-minifier": "^4.0.5", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65303
1157
+ Addedcsso@^5.0.5
+ Addedcss-tree@2.2.1(transitive)
+ Addedcsso@5.0.5(transitive)
+ Addedmdn-data@2.0.28(transitive)
- Removedclean-css@^5.3.3
- Removedclean-css@5.3.3(transitive)