The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

VERSION

0.44

SYNOPSIS

Application

  use Mojolicious::Lite;

  # load plugin
  plugin "AssetPack";

  # define assets: $moniker => @real_assets
  app->asset('app.js' => '/js/foo.js', '/js/bar.js', '/js/baz.coffee');
  app->start;

See also Mojolicious::Plugin::AssetPack::Manual::Assets for more details on how to define assets.

Template

  %= asset 'app.js'
  %= asset 'app.css'

See also Mojolicious::Plugin::AssetPack::Manual::Include for more details on how to include assets.

DESCRIPTION

Mojolicious::Plugin::AssetPack is a Mojolicious plugin which can be used to cram multiple assets of the same type into one file. This means that if you have a lot of CSS files (.css, .less, .sass, ...) as input, the AssetPack can make one big CSS file as output. This is good, since it will often speed up the rendering of your page. The output file can even be minified, meaning you can save bandwidth and browser parsing time.

The core preprocessors that are bundled with this module can handle CSS and JavaScript files, written in many languages.

MANUALS

The documentation is split up in different manuals, for more in-depth information:

ENVIRONMENT

MOJO_ASSETPACK_DEBUG

Set this to get extra debug information to STDERR from AssetPack internals.

MOJO_ASSETPACK_NO_CACHE

If true, convert the assets each time they're expanded, instead of once at application start (useful for development).

This attribute has no effect if "minify" is true.

HELPERS

asset

This plugin defined the helper asset(). This helper can be called in different ways:

  • $self = $c->asset;

    This will return the plugin instance, that you can call methods on.

  • $c->asset($moniker => @real_files);

    See "add".

  • $bytestream = $c->asset($moniker, \%args, @attr);

    Used to include an asset in a template.

ATTRIBUTES

base_url

  $str = $self->base_url;

This attribute can be used to control where to serve static assets from.

Defaults value is "/packed".

See Mojolicious::Plugin::AssetPack::Manual::CustomDomain for more details.

NOTE! You need to have a trailing "/" at the end of the string.

fallback

  $bool = $self->fallback;

Used to read "old" assets if unable to generate new.

Default is false in "development" mode and true otherwise.

See "Fallback" in Mojolicious::Plugin::AssetPack::Manual::Modes.

minify

  $bool = $self->minify;

Set this to true if the assets should be minified.

Default is false in "development" mode and true otherwise.

preprocessors

  $obj = $self->preprocessors;

Holds a Mojolicious::Plugin::AssetPack::Preprocessors object.

out_dir

  $str = $self->out_dir;

Holds the path to the directory where packed files can be written. It defaults to "mojo-assetpack-public/packed" directory in temp unless a static directory is writeable.

METHODS

add

  $self->add($moniker => @real_files);

Used to define assets.

See Mojolicious::Plugin::AssetPack::Manual::Assets for mode details.

fetch

  $path = $self->fetch($url);

This method can be used to fetch an asset and store the content to a local file. The download will be skipped if the file already exists. The return value is the absolute path to the downloaded file.

get

  @files = $self->get($moniker);

Returns a list of files which the moniker point to. The list will only contain one file if "minify" is true.

See "Full control" in Mojolicious::Plugin::AssetPack::Manual::Include for mode details.

preprocessor

  $self = $self->preprocessor($name => \%args);

Use this method to manually register a preprocessor.

See "SYNOPSIS" in Mojolicious::Plugin::AssetPack::Preprocessor::Browserify for example usage.

process

This method will be deprecated. Use "add" instead.

register

  plugin AssetPack => {
    base_url => $str,  # default to "/packed"
    fallback => $bool, # fallback to old assets
    minify   => $bool, # compress assets
    out_dir  => "/path/to/some/directory",
  };

Will register the compress helper. All arguments are optional.

COPYRIGHT AND LICENSE

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.

AUTHOR

Jan Henning Thorsen - jhthorsen@cpan.org

Alexander Rymasheusky

Per Edin - info@peredin.com

Viktor Turskyi