From: Marius Gavrilescu Date: Wed, 22 Apr 2015 07:22:45 +0000 (+0300) Subject: Use zopfli if available X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=fa8b7f99072328f6a9855cd0b300691405a09ec1;p=gruntmaster-page.git Use zopfli if available --- diff --git a/Makefile.PL b/Makefile.PL index 2bf04ac..0d62f05 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -31,6 +31,7 @@ WriteMakefile( warnings 0 File::Slurp 0 + File::Which 0 Gruntmaster::Data 0 HTML::Element::Library 0 HTML::TreeBuilder 0 diff --git a/make_static.PL b/make_static.PL index 3374f5c..9fd5bca 100644 --- a/make_static.PL +++ b/make_static.PL @@ -6,6 +6,7 @@ use CSS::Minifier::XS qw/minify/; use Digest::SHA qw/sha256_base64/; use IO::Compress::Gzip qw/gzip/; use File::Slurp qw/read_file write_file edit_file_lines/; +use File::Which; use List::Util qw/first/; mkdir 'static'; @@ -14,7 +15,15 @@ mkdir 'static/js'; sub gzip_file { my ($file) = @_; - gzip $file => "$file.gz", -Level => 9, Minimal => 1; + my $zopfli = which 'zopfli'; + system $zopfli => $file if $zopfli; + gzip $file => "$file.gz", -Level => 9, Minimal => 1 unless $zopfli; +} + +sub write_gzfile { + my ($file, @content) = @_; + write_file $file, @content; + gzip_file $file } sub read_css_into_blocks { @@ -49,18 +58,14 @@ sub make_css { } } - for my $name (keys %css) { - write_file "static/css/$name.css", minify $css{$name}; - gzip_file "static/css/$name.css" - } + write_gzfile "static/css/$_.css", minify $css{$_} for keys %css } sub make_js { system java => -jar => 'compiler.jar', qw,-O SIMPLE --create_source_map static/js/js.map --js_output_file static/js/all.js --language_in ECMASCRIPT6_STRICT --language_out ECMASCRIPT5_STRICT --source_map_location_mapping js/|/static/js/,, ; my $js = read_file 'static/js/all.js'; - write_file 'static/js/all.js', '//# sourceMappingURL=/static/js/js.map', "\n", $js; + write_gzfile 'static/js/all.js', '//# sourceMappingURL=/static/js/js.map', "\n", $js; system 'cp', '-rp', 'js', 'static/'; - gzip_file 'static/js/all.js'; } my $css_mtime = -M 'static/css/slate.css' // 0;