1Mojolicious::Plugin::AsUsseetrPaCcokn(t3r)ibuted Perl DoMcoujmoelnitcaitoiuosn::Plugin::AssetPack(3)
2
3
4
6 Mojolicious::Plugin::AssetPack - Compress and convert CSS, Less, Sass,
7 JavaScript and CoffeeScript files
8
10 Application
11 use Mojolicious::Lite;
12
13 # Load plugin and pipes in the right order
14 plugin AssetPack => {pipes => [qw(Less Sass Css CoffeeScript Riotjs JavaScript Combine)]};
15
16 # define asset
17 app->asset->process(
18 # virtual name of the asset
19 "app.css" => (
20
21 # source files used to create the asset
22 "sass/bar.scss",
23 "https://github.com/Dogfalo/materialize/blob/master/sass/materialize.scss",
24 )
25 );
26
27 Template
28 <html>
29 <head>
30 %= asset "app.css"
31 </head>
32 <body><%= content %></body>
33 </html>
34
36 Mojolicious::Plugin::AssetPack is a Mojolicious plugin for processing
37 static assets. The idea is that JavaScript and CSS files should be
38 served as one minified file to save bandwidth and roundtrip time to the
39 server.
40
41 There are many external tools for doing this, but integrating them with
42 Mojolicious can be a struggle: You want to serve the source files
43 directly while developing, but a minified version in production. This
44 assetpack plugin will handle all of that automatically for you.
45
46 Your application creates and refers to an asset by its topic (virtual
47 asset name). The process of building actual assets from their
48 components is delegated to "pipe objects".
49
51 Mojolicious::Plugin::AssetPack::Guides::Tutorial
52 The tutorial will give an introduction to how AssetPack can be used.
53
54 Mojolicious::Plugin::AssetPack::Guides::Developing
55 The "developing" guide will give insight on how to do effective
56 development with AssetPack and more details about the internals in
57 this plugin.
58
59 Mojolicious::Plugin::AssetPack::Guides::Cookbook
60 The cookbook has various receipes on how to cook with AssetPack.
61
63 asset
64 $self = $app->asset;
65 $self = $c->asset;
66 $bytestream = $c->asset($topic, @args);
67 $bytestream = $c->asset("app.css", media => "print");
68
69 "asset()" is the main entry point to this plugin. It can either be used
70 to access the Mojolicious::Plugin::AssetPack instance or as a tag
71 helper.
72
73 The helper name "asset" can be customized by specifying "helper" when
74 registering the plugin.
75
77 minify
78 $bool = $self->minify;
79 $self = $self->minify($bool);
80
81 Set this to true to combine and minify the assets. Defaults to false if
82 "mode" in Mojolicious is "development" and true otherwise.
83
84 route
85 $route = $self->route;
86 $self = $self->route($route);
87
88 A Mojolicious::Routes::Route object used to serve assets. The default
89 route responds to HEAD and GET requests and calls serve_asset() on
90 "store" to serve the asset.
91
92 The default route will be built and added to the application when
93 "process" is called the first time.
94
95 store
96 $obj = $self->store;
97 $self = $self->store(Mojolicious::Plugin::AssetPack::Store->new);
98
99 Holds a Mojolicious::Plugin::AssetPack::Store object used to locate,
100 store and serve assets.
101
102 tag_for
103 Deprecated. Use "renderer" in Mojolicious::Plugin::AssetPack::Asset
104 instead.
105
106 ua
107 $ua = $self->ua;
108
109 Holds a Mojo::UserAgent which can be used to fetch assets either from
110 local application or from remote web servers.
111
113 pipe
114 $obj = $self->pipe($name);
115 $obj = $self->pipe("Css");
116
117 Will return a registered pipe by $name or "undef" if none could be
118 found.
119
120 process
121 $self = $self->process($topic => @assets);
122 $self = $self->process($definition_file);
123
124 Used to process assets. A $definition_file can be used to define $topic
125 and @assets in a separate file.
126
127 $definition_file defaults to "assetpack.def".
128
129 processed
130 $collection = $self->processed($topic);
131
132 Can be used to retrieve a Mojo::Collection object, with zero or more
133 Mojolicious::Plugin::AssetPack::Asset objects.
134
135 register
136 $self->register($app, \%config);
137
138 Used to register the plugin in the application. %config can contain:
139
140 • helper
141
142 Name of the helper to add to the application. Default is "asset".
143
144 • pipes
145
146 This argument is mandatory and need to contain a complete list of
147 pipes that is needed. Example:
148
149 $app->plugin(AssetPack => {pipes => [qw(Sass Css Combine)]);
150
151 • proxy
152
153 A hash of proxy settings. Set this to 0 to disable proxy detection.
154 Currently only "no_proxy" is supported, which will set which requests
155 that should bypass the proxy (if any proxy is detected). Default is
156 to bypass all requests to localhost.
157
158 See "detect" in Mojo::UserAgent::Proxy for more information.
159
161 Mojolicious::Plugin::Webpack.
162
164 Copyright (C) 2020, Jan Henning Thorsen
165
166 This program is free software, you can redistribute it and/or modify it
167 under the terms of the Artistic License version 2.0.
168
170 Jan Henning Thorsen - "jhthorsen@cpan.org"
171
172 Alexander Rymasheusky
173
174 Mark Grimes - "mgrimes@cpan.org"
175
176 Per Edin - "info@peredin.com"
177
178 Viktor Turskyi
179
180
181
182perl v5.36.0 2022-07-22 Mojolicious::Plugin::AssetPack(3)