X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=make_static.PL;h=9fd5bcaf62916cb024ac8c59c07f7030a2ff1772;hb=8e3f7d1e659c971fe718b6dccd0b904ed2c0d35a;hp=0c4396036d0fc6c4805a89685ef1b175f7bf1173;hpb=5eae1f77a18ef8273f3a0cd6d4af8c19a4986880;p=plack-app-gruntmaster.git diff --git a/make_static.PL b/make_static.PL index 0c43960..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; @@ -71,7 +76,7 @@ for (, ) { } } -my $js_mtime = -M 'static/js.js' // 0; +my $js_mtime = -M 'static/js/all.js' // 0; for () { if (!$js_mtime || $js_mtime > -M) { make_js;