line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Browserify; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Mojolicious::Plugin::Browserify - An Mojolicious plugin for assetpack+browserify |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
0.04 |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
L is a plugin that will register |
14
|
|
|
|
|
|
|
L in |
15
|
|
|
|
|
|
|
L. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
L is a JavaScript preprocessor which will |
18
|
|
|
|
|
|
|
allow you to use L's |
19
|
|
|
|
|
|
|
C in your JavaScript files. Here is an example JavaScript file, |
20
|
|
|
|
|
|
|
that use C to pull in L: |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
var React = require('react'); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
module.exports = React.createClass({ |
25
|
|
|
|
|
|
|
render: function() { |
26
|
|
|
|
|
|
|
return ; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
}); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 SYNOPSIS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
use Mojolicious::Lite; |
33
|
|
|
|
|
|
|
plugin "Browserify" => { |
34
|
|
|
|
|
|
|
browserify_args => [-g => "reactify"], |
35
|
|
|
|
|
|
|
environment => app->mode, # default |
36
|
|
|
|
|
|
|
extensions => [qw( js jsx )], # default is "js" |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
app->asset("app.js" => "/js/main.js"); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
get "/app" => "app_js_inlined"; |
41
|
|
|
|
|
|
|
app->start; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__DATA__ |
44
|
|
|
|
|
|
|
@@ app_js_inlined.js.ep |
45
|
|
|
|
|
|
|
%= asset "app.js" => {inline => 1} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Note! The L require both "react" and "reactify" to be installed: |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$ cd /home/projects/my-project |
50
|
|
|
|
|
|
|
$ mojo browserify install react |
51
|
|
|
|
|
|
|
$ mojo browserify install reactify |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=over 4 |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item * browserify |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
This module require L to be installed. The |
60
|
|
|
|
|
|
|
node based application can either be installed system wide or locally to |
61
|
|
|
|
|
|
|
your project. To install it locally, you can use the |
62
|
|
|
|
|
|
|
L Mojolicious command: |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# same as "npm install browserify" |
65
|
|
|
|
|
|
|
$ mojo browserify install |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
It is also possible to check installed versions using this command: |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$ mojo browserify version |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item * uglifyjs |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
L is a really good minifier. |
74
|
|
|
|
|
|
|
The test C used to create a bundle that took 324K with |
75
|
|
|
|
|
|
|
L. With C the same code takes C<156K>. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
What is the drawback? It takes a lot longer to run C, but it's |
78
|
|
|
|
|
|
|
worth it, since it will only be called in production mode. Get it with |
79
|
|
|
|
|
|
|
this command: |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$ mojo browserify install uglify-js |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=back |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
10
|
|
|
10
|
|
5760
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
10
|
|
|
|
|
30
|
|
|
10
|
|
|
|
|
50
|
|
88
|
10
|
|
|
10
|
|
12140
|
use Mojolicious::Plugin::Browserify::Processor; |
|
10
|
|
|
|
|
40
|
|
|
10
|
|
|
|
|
190
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 METHODS |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 register |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Used to register L in the |
97
|
|
|
|
|
|
|
C application. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub register { |
102
|
0
|
|
|
0
|
1
|
|
my ($self, $app, $config) = @_; |
103
|
0
|
|
|
|
|
|
my $browserify = Mojolicious::Plugin::Browserify::Processor->new($config); |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
$app->plugin("AssetPack") unless eval { $app->asset }; |
|
0
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
$browserify->environment($app->mode) unless $config->{environment}; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
for my $ext (@{$browserify->extensions}) { |
|
0
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$app->asset->preprocessors->remove($ext); |
110
|
0
|
|
|
|
|
|
$app->asset->preprocessors->add($ext => $browserify); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Copyright (C) 2014, Jan Henning Thorsen |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
119
|
|
|
|
|
|
|
the terms of the Artistic License version 2.0. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 AUTHOR |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Jan Henning Thorsen - C |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |