line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::AssetPack::Pipe::JavaScriptPacker; |
2
|
2
|
|
|
2
|
|
1100
|
use Mojo::Base 'Mojolicious::Plugin::AssetPack::Pipe'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
3
|
2
|
|
|
2
|
|
345
|
use Mojolicious::Plugin::AssetPack::Util qw(diag load_module DEBUG); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
129
|
|
4
|
2
|
|
|
2
|
|
1209
|
use JavaScript::Packer; |
|
2
|
|
|
|
|
20735
|
|
|
2
|
|
|
|
|
989
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
my $packer = JavaScript::Packer->init(); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has config => sub { |
9
|
|
|
|
|
|
|
my $self = shift; |
10
|
|
|
|
|
|
|
my $config = $self->assetpack->config || $self->assetpack->config({}); |
11
|
|
|
|
|
|
|
$config->{JavaScriptPacker} ||= {}; |
12
|
|
|
|
|
|
|
}; |
13
|
|
|
|
|
|
|
has minify_opts => sub { { %{shift->config->{minify_opts} ||= {}}, } };# |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub process { |
16
|
4
|
|
|
4
|
1
|
941
|
my ($self, $assets) = @_; |
17
|
4
|
|
|
|
|
16
|
my $store = $self->assetpack->store; |
18
|
|
|
|
|
|
|
|
19
|
4
|
100
|
|
|
|
40
|
return unless $self->assetpack->minify; |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
|
|
19
|
my $file; |
22
|
|
|
|
|
|
|
return $assets->each( |
23
|
|
|
|
|
|
|
sub { |
24
|
2
|
|
|
2
|
|
18
|
my ($asset, $index) = @_; |
25
|
2
|
|
|
|
|
20
|
my $attrs = $asset->TO_JSON; |
26
|
2
|
|
|
|
|
159
|
$attrs->{key} = 'js-min'; |
27
|
2
|
|
|
|
|
4
|
$attrs->{minified} = 1; |
28
|
|
|
|
|
|
|
|
29
|
2
|
50
|
33
|
|
|
8
|
return if $asset->format ne 'js' || $asset->minified; |
30
|
0
|
0
|
|
|
|
|
return $asset->content($file)->minified(1) |
31
|
|
|
|
|
|
|
if $file = $store->load($attrs); |
32
|
0
|
0
|
|
|
|
|
return unless length(my $content = $asset->content); |
33
|
0
|
|
|
|
|
|
DEBUG && diag "Minify javascript=[%s] with checksum=[%s] and minify_opts=[@{[ %{$self->minify_opts} ]}]", $asset->url, $asset->checksum, ; |
34
|
0
|
|
|
|
|
|
$packer->minify(\$content, $self->minify_opts); |
35
|
0
|
|
|
|
|
|
$asset->content($store->save(\$content, $attrs))->minified(1); |
36
|
|
|
|
|
|
|
} |
37
|
2
|
|
|
|
|
16
|
); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |