From: Nigel Metheringham Date: Sun, 4 Jul 2010 13:20:30 +0000 (+0100) Subject: JS and CSS minify addition X-Git-Tag: exim-4_89_1~119 X-Git-Url: https://git.exim.org/exim-website.git/commitdiff_plain/296dcdc148c40473ee48be93a9a8325ef947ea55 JS and CSS minify addition --- diff --git a/script/gen.pl b/script/gen.pl index c964689..4c545f5 100755 --- a/script/gen.pl +++ b/script/gen.pl @@ -1,9 +1,12 @@ #!/usr/bin/perl use strict; use warnings; +use CSS::Minifier::XS; use File::Copy; use File::Find; +use File::Slurp; use File::Spec; +use JavaScript::Minifier::XS; use XML::LibXML; use XML::LibXSLT; @@ -52,10 +55,21 @@ sub do_web { ## Skip if the file hasn't changed (mtime based) return if -f "$opt{docroot}/$path" && ( stat("$opt{tmpl}/web/$path") )[9] == ( stat("$opt{docroot}/$path") )[9]; - ## Copy - print "Copying to : docroot:/$path\n"; - copy( "$opt{tmpl}/web/$path", "$opt{docroot}/$path" ) or die "$path: $!"; - + if ( $path =~ /(.+)\.css$/ ) { + print "CSS to : docroot:/$path\n"; + my $content = read_file("$opt{tmpl}/web/$path"); + write_file( "$opt{docroot}/$path", CSS::Minifier::XS::minify($content) ); + } + elsif ( $path =~ /(.+)\.js$/ ) { + print "JS to : docroot:/$path\n"; + my $content = read_file("$opt{tmpl}/web/$path"); + write_file( "$opt{docroot}/$path", JavaScript::Minifier::XS::minify($content) ); + } + else { + ## Copy + print "Copying to : docroot:/$path\n"; + copy( "$opt{tmpl}/web/$path", "$opt{docroot}/$path" ) or die "$path: $!"; + } ## Set mtime utime( time, ( stat("$opt{tmpl}/web/$path") )[9], "$opt{docroot}/$path" ); }