Skip to content

Commit

Permalink
fixed css minification implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jleeson committed Sep 25, 2024
1 parent a718f4b commit abd78c4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ export default (options = {}) => {
const minifyCSS = (content) => {
content = content.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\/|[\r\n\t]+/g, ""); // Remove comments and newlines
content = content.replace(/ {2,}/g, " "); // Replace multiple spaces with one
content = content.replace(/ ([{:}]) /g, "$1"); // Remove space around braces and colons
content = content.replace(/([{:}])\s+/g, "$1"); // Remove space after { and other braces
content = content.replace(/(:)(?!\s)/g, "$1 "); // Ensure a space after colon in property declarations
content = content.replace(/([;,]) /g, "$1"); // Remove space after semicolons and commas
content = content.replace(/ !/g, "!"); // Remove space before !
content = content.replace(/\[([^\]]*?)\]/g, (match, p1) => `[${p1.replace(/\s*:\s*/g, ": ").replace(/\s*([=<>^$|~])\s*/g, "$1").trim()}]`); // Preserve spaces inside attribute selectors (inside [])
content = content.replace(/\s*([{};])\s*/g, "$1"); // Remove spaces around `{`, `}`, and `;`
content = content.replace(/([a-zA-Z0-9_-])\s*(:[a-zA-Z])/g, "$1 $2"); // Add space before pseudo-classes
content = content.replace(/([a-zA-Z0-9_-]+):\s*([^;"{}]+(?:;|$))/g, "$1:$2"); // Remove spaces in property declarations
return content;
};


return {
name: "import-css",

Expand Down

0 comments on commit abd78c4

Please sign in to comment.