Created
January 11, 2015 13:04
-
-
Save mlampret/b8de70ad27fe850f8298 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use Getopt::Std; | |
sub main { | |
my $rh_args={}; | |
getopts('o:i:',$rh_args); | |
unless (-f $rh_args->{i}) { | |
die "Input file $rh_args->{i} not found"; | |
} | |
my $css=`cat $rh_args->{i}`; | |
my $length_before=length($css); | |
$css=~s!\r?\n! !isg; | |
$css=~s!\s+! !isg; | |
$css=~s!\s{\s*!{!isg; | |
$css=~s!}\s+!}!isg; | |
$css=~s!:\s+!:!isg; | |
$css=~s!;\s+!;!isg; | |
$css=~s!/\*.+?\*/!!isg; | |
my $length_after=length($css); | |
if ($rh_args->{o}) { | |
print "Writing compacted css to $rh_args->{o}\n"; | |
open(FILE,">$rh_args->{o}") or die "can't open file $rh_args->{o}"; | |
print FILE $css; | |
close(FILE); | |
} else { | |
print "No output file specified.. comparison only\n"; | |
} | |
print "Size before: $length_before\n"; | |
print "Size after: $length_after\n"; | |
} | |
main; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: ./css_compressor -i input.css -o output.css