Mojolicious::Plugin::AssetPack - Compress and convert css, less, sass, javascript and coffeescript files
0.12
In your application:
use Mojolicious::Lite; plugin 'AssetPack'; # define assets: $moniker => @real_assets app->asset('app.js' => '/js/foo.js', '/js/bar.js', '/js/baz.coffee'); app->asset('app.css' => '/css/foo.less', '/css/bar.scss', '/css/main.css'); # you can combine with assets from web app->asset('bundle.js' => ( 'http://cdnjs.cloudflare.com/ajax/libs/es5-shim/2.3.0/es5-shim.js', 'http://cdnjs.cloudflare.com/ajax/libs/es5-shim/2.3.0/es5-sham.js', 'http://code.jquery.com/jquery-1.11.0.js', '/js/myapp.js', )); app->start;
In your template:
%= asset 'app.js' %= asset 'app.css'
Or if you need to add the tags manually:
% for my $asset (asset->get('app.js')) { %= javascript $asset % }
See also "register".
If true, convert the assets each time they're expanded, instead of once at application start (useful for development). Has no effect when "minify" is enabled.
This plugin will compress scss, less, css, javascript and coffeescript with the help of external applications on startup. The result will be one file with all the sources combined. This file is stored in "Packed directory".
The files in the packed directory will have a checksum added to the filename which will ensure broken browsers request a new version once the file is changed. Example:
<script src="/packed/app-ed6d968e39843a556dbe6dad8981e3e0.js">
This is done using "process".
This plugin will expand the input files to multiple script or link tags which makes debugging and development easier.
This is done using "expand".
TIP! Make morbo watch your less/sass files as well:
$ morbo -w lib -w templates -w public/sass
You can also set the "MOJO_ASSETPACK_NO_CACHE" environment variable to 1 to convert your less/sass/coffee files each time their asset directive is expanded (only works when "minify" is disabled).
This library tries to find default preprocessors for less, scss, js, coffee and css.
NOTE! The preprocessors require optional dependencies to function properly. Check out "detect" in Mojolicious::Plugin::AssetPack::Preprocessors for more details.
You can also define your own preprocessors:
app->asset->preprocessors->add(js => sub { my($assetpack, $text, $file) = @_; $$text = "// yikes!\n" if 5 < rand 10; });
Set this to true if the assets should be minified.
Holds a Mojolicious::Plugin::AssetPack::Preprocessors object.
Holds the path to the firectory where packed files can be written. It defaults to "mojo-assetpack" directory in temp unless a static directory is writeable.
Deprecated.
$self->add($moniker => @rel_files);
Used to define new assets aliases. This method is called when the asset() helper is called on the app.
asset()
$bytestream = $self->expand($c, $moniker);
This method will return one tag for each asset defined by the "$moniker".
Will also run "less", "sass" or "coffee" on the files to convert them to css or js, which the browser understands. (With "MOJO_ASSETPACK_NO_CACHE" enabled, this is done each time on expand; with it disabled, this is done once when the asset is added.)
The returning bytestream will contain style or script tags.
@files = $self->get($moniker);
Returns a list of files which the moniker point to. The list will only contain one file if the $moniker is minified.
$moniker
$self->process($moniker => @files);
This method use "process" in Mojolicious::Plugin::AssetPack::Preprocessors to convert and/or minify the sources pointed at by $moniker.
The result file will be stored in "Packed directory".
plugin 'AssetPack', { minify => $bool, # compress assets no_autodetect => $bool, # disable preprocessor autodetection };
Will register the compress helper. All arguments are optional.
compress
"minify" will default to true if "mode" in Mojolicious is "production".
Copyright (C) 2014, Jan Henning Thorsen.
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
Jan Henning Thorsen - jhthorsen@cpan.org
jhthorsen@cpan.org
Alexander Rymasheusky
Per Edin - info@peredin.com
info@peredin.com
Viktor Turskyi
To install Mojolicious::Plugin::AssetPack, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::AssetPack
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::AssetPack
For more information on module installation, please visit the detailed CPAN module installation guide.