Mojolicious-Plugin-AssetPack 1.41

Compress and convert css, less, sass, javascript and coffeescript files


Platform: CPAN

Language: Perl

License: Artistic-2.0

View on registry:


Mojolicious::Plugin::AssetPack - Compress and convert css, less, sass, javascript and coffeescript files





  use Mojolicious::Lite;

  # Load plugin and pipes in the right order
  plugin AssetPack => {
    pipes => [qw(Less Sass Css CoffeeScript Riotjs JavaScript Combine)]

  # define asset
    # virtual name of the asset
    "app.css" => (

      # source files used to create the asset


      %= asset "app.css"
    <body><%= content %></body>


Are you already using AssetPack? You can still do so without any change. This new version was written to make it easier to maintain and also easier to extend. The new code will be "activated" by loadind this plugin with a list of pipes:

  $app->plugin(AssetPack => {pipes => [...]});

The old API require Mojolicious::Plugin::AssetPack::Backcompat to be installed.


Mojolicious::Plugin::AssetPack is Mojolicious plugin for processing static assets. The idea is that JavaScript and CSS files should be served as one minified file to save bandwidth and roundtrip time to the server.

There are many external tools for doing this, but integrating them with Mojolicious can be a struggle: You want to serve the source files directly while developing, but a minified version in production. This assetpack plugin will handle all of that automatically for you.

The actual processing is delegated to "pipe objects". Please see "Pipes" in Mojolicious::Plugin::AssetPack::Guides::Tutorial for a complete list.



It is possible to set environment variables to change the behavior of AssetPack:


    Set this environment variable to get more debug to STDERR. Currently you can set it to a value between 0 and 3, where 3 provides the most debug.


    Set this environment variable if you want to delay processing the assets until they are requested. This can be very useful while developing when the assets are changed frequently.


There are some optional modules you might want to install:



  $self = $app->asset;
  $self = $c->asset;
  $bytestream = $c->asset($topic, @args);
  $bytestream = $c->asset("app.css", media => "print");

asset() is the main entry point to this plugin. It can either be used to access the Mojolicious::Plugin::AssetPack instance or as a tag helper.

The helper name "asset" can be customized by specifying "helper" when registering the plugin.

See Mojolicious::Plugin::AssetPack::Guides::Tutorial for more details.



  $bool = $self->minify;
  $self = $self->minify($bool);

Set this to true to combine and minify the assets. Defaults to false if "mode" in Mojolicious is "development" and true otherwise.

See "Application mode" in Mojolicious::Plugin::AssetPack::Guides::Tutorial for more details.


  $route = $self->route;
  $self = $self->route($route);

A Mojolicious::Routes::Route object used to serve assets. The default route responds to HEAD and GET requests and calls serve_asset() on "store" to serve the asset.

The default route will be built and added to the application when "process" is called the first time.

See "ASSETS FROM CUSTOM DOMAIN" in Mojolicious::Plugin::AssetPack::Guides::Cookbook for an example on how to customize this route.


  $obj = $self->store;
  $self = $self->store(Mojolicious::Plugin::AssetPack::Store->new);

Holds a Mojolicious::Plugin::AssetPack::Store object used to locate, store and serve assets.


  $self = $self->tag_for(sub { my ($asset, $c, \%args, @attrs) = @_; });
  $code = $self->tag_for;

Holds a sub reference that returns a Mojo::Bytestream object containing the markup required to render an asset.

$asset is a Mojolicious::Plugin::AssetPack::Asset object, $c is an Mojolicious::Controller object and @attrs can contain a list of HTML attributes. %args currently contains:


  $ua = $self->ua;

Holds a Mojo::UserAgent which can be used to fetch assets either from local application or from remote web servers.



  $obj = $self->pipe($name);
  $obj = $self->pipe("Css");

Will return a registered pipe by $name or undef if none could be found.


  $self = $self->process($topic => @assets);
  $self = $self->process($definition_file);

Used to process assets. A $definition_file can be used to define $topic and @assets in a seperate file. See "Process assets" in Mojolicious::Plugin::AssetPack::Guides::Tutorial for more details.

$definition_file defaults to "assetpack.def".


  $collection = $self->processed($topic);

Can be used to retrieve a Mojo::Collection object, with zero or more Mojolicious::Plugin::AssetPack::Asset objects. Returns undef if $topic is not defined with "process".


  $self->register($app, \%config);

Used to register the plugin in the application. %config can contain:

  • helper

    Name of the helper to add to the application. Default is "asset".

  • pipes

    This argument is mandatory and need to contain a complete list of pipes that is needed. Example:

      $app->plugin(AssetPack => {pipes => [qw(Sass Css Combine)]);

    See "Pipes" in Mojolicious::Plugin::AssetPack::Guides::Tutorial for a complete list of available pipes.

  • proxy

    A hash of proxy settings. Set this to 0 to disable proxy detection. Currently only "no_proxy" is supported, which will set which requests that should bypass the proxy (if any proxy is detected). Default is to bypass all requests to localhost.

    See "detect" in Mojo::UserAgent::Proxy for more infomation.


"GUIDES", Mojolicious::Plugin::AssetPack::Asset, Mojolicious::Plugin::AssetPack::Pipe and Mojolicious::Plugin::AssetPack::Store.


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 - [email protected]

Alexander Rymasheusky

Mark Grimes - [email protected]

Per Edin - [email protected]

Viktor Turskyi


1.41 March 15, 2017
1.40 February 05, 2017
1.39 January 25, 2017
1.38 January 23, 2017
1.37 January 12, 2017
1.36 January 11, 2017
1.35 January 11, 2017
1.34 January 10, 2017
1.33 January 08, 2017
1.32 January 08, 2017
See all 123 releases

Project Statistics

SourceRank 11
Dependencies 3
Dependent projects 10
Dependent repositories 0
Total releases 123
Latest release
First release
Stars 21
Forks 19
Watchers 10
Contributors 9
Repo Size: 2.68 MB

Top Contributors See all

Jan Henning Thorsen Zoffix Znet Alexander Rymasheusky Красимир Беров mvgrimes Adam Schobelock Per Edin Shane Burgess Olaf Alders

Something wrong with this page? Make a suggestion

Export .ABOUT file for this library

Last synced: 2017-03-19 03:45:20 UTC

Login to resync this project