]> iEval git - gruntmaster-page.git/commitdiff
Use zopfli if available
authorMarius Gavrilescu <marius@ieval.ro>
Wed, 22 Apr 2015 07:22:45 +0000 (10:22 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Wed, 22 Apr 2015 07:22:45 +0000 (10:22 +0300)
Makefile.PL
make_static.PL

index 2bf04acdec3d5716f8d3ad3295299548f7f3a0b8..0d62f051a36ec7c488287160e5b42f48530bee42 100644 (file)
@@ -31,6 +31,7 @@ WriteMakefile(
                   warnings    0
 
                   File::Slurp                      0
+                  File::Which                      0
                   Gruntmaster::Data                0
                   HTML::Element::Library           0
                   HTML::TreeBuilder                0
index 3374f5cf2a61c7769cb1a5718bd76ef657386ee6..9fd5bcaf62916cb024ac8c59c07f7030a2ff1772 100644 (file)
@@ -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/,, <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;
This page took 0.025691 seconds and 4 git commands to generate.