Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New CSS minifier: miniMinifier #26

Open
xem opened this issue Dec 1, 2014 · 5 comments
Open

New CSS minifier: miniMinifier #26

xem opened this issue Dec 1, 2014 · 5 comments

Comments

@xem
Copy link

xem commented Dec 1, 2014

Hello, I'd like to add my css minifier to the list, but sadly it's not node based. it's just an experiment (I tried to make a minifier as short as possible), but it has very interesting results:

given a string to minify "str", just run:

for(i=9;i--;)str=str.replace(/^\s|\s$|\/\*[^]*?\*\/|\s*;*([^\:\w.#\x27"\s*-])\s*|(:) /g,"$1$2")

(removes comments, whitespaces and semicolons)

or a little more complete:

for(i=9;i--;)str=str.replace(/([^#\d\w\(._\x27"-])((0)[a-z%]+|0(\.))|^\s|\s$|\/\*[^]*?\*\/|\s*;*([^\:\w.#)\x27"\s*-])\s*|\s(\))|(:) |[^}]*{}/gi,"$1$3$4$5$6$7").replace(/rgb\((\d+),(\d+),(\d+)\)|#[a-f0-9]{6}/gi,function(a,c,d,b){if(b)for(i in a="#",p=[c,d,b])a+=("0"+parseInt(p[i]).toString(16)).slice(-2);return(p=a[2]+a[4]+a[6])==a[1]+a[3]+a[5]?"#"+p:a})

(removes comments, whitespaces and semicolons, leading zeros, units after zero, empty rules, converts rgb colors to hex and preserve ie8 compatibility)

You'll find more info, demo and test files on: http://xem.github.io/miniMinifier/css/

If someone can help me convert this / those functions in node, that would be very nice.
(I don't know how to do it yet ^^)

Thanks!

@jakubpawlowicz
Copy link
Collaborator

Interesting thing. That's surely gonna be fast.

@XhmikosR
Copy link
Collaborator

@xem I'd be interested in this assuming you make it a module :)

@xem
Copy link
Author

xem commented Nov 10, 2019

image

... and I still don't know how to make a module :D

@XhmikosR
Copy link
Collaborator

You write your code and export it. Then add a package.json file.

Where is the code right now published?

@xem
Copy link
Author

xem commented Nov 10, 2019

the code is published here: https://github.com/xem/miniMinifier/

If it was embedded inside a function, that would be:

minify=str=>{for(i=9;i--;)str=str.replace(/([^#\d\w\(._\x27"-])((0)[a-z%]+|0(\.))|^\s|\s$|\/\*[^]*?\*\/|\s*;*([^\:\w.#)\x27"\s*-])\s*|\s(\))|(:) |[^}]*{}/gi,"$1$3$4$5$6$7").replace(/rgb\((\d+),(\d+),(\d+)\)|#[a-f0-9]{6}/gi,function(a,c,d,b){if(b)for(i in a="#",p=[c,d,b])a+=("0"+parseInt(p[i]).toString(16)).slice(-2);return(p=a[2]+a[4]+a[6])==a[1]+a[3]+a[5]?"#"+p:a});return str}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants