Mojolic...setPack(3)

hey bestie πŸ’– this is the Mojolicious::Plugin::AssetPack page β€” yes, the one filed under Mojolic...setPack(3) in User Contributed Perl Documentation. It's giving β€œcompress and convert CSS, Less, Sass, JavaScript and CoffeeScript files” and honestly it ate.

🌸 NAME 🌸

Mojolicious::Plugin::AssetPack β€” Compress and convert CSS, Less, Sass, JavaScript and CoffeeScript files. That's the whole vibe, no cap.

✨ SYNOPSIS ✨

okay so here's the quickstart, bestie. Two flavors:

Application

use Mojolicious::Lite;

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

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

    # source files used to create the asset
    "sass/bar.scss",
    "https://github.com/Dogfalo/materialize/blob/master/sass/materialize.scss",
  )
);

Template

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

πŸ’… DESCRIPTION πŸ’…

Mojolicious::Plugin::AssetPack is a 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.

Your application creates and refers to an asset by its topic (virtual asset name). The process of building actual assets from their components is delegated to pipe objects.

πŸŽ€ GUIDES πŸŽ€

  • Mojolicious::Plugin::AssetPack::Guides::Tutorial β€” the tutorial gives an introduction to how AssetPack can be used.
  • Mojolicious::Plugin::AssetPack::Guides::Developing β€” the β€œdeveloping” guide gives insight on how to do effective development with AssetPack, plus more details about the internals in this plugin.
  • Mojolicious::Plugin::AssetPack::Guides::Cookbook β€” the cookbook has various recipes on how to cook with AssetPack.

πŸ¦‹ HELPERS πŸ¦‹

asset

$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.

πŸ‘‘ ATTRIBUTES πŸ‘‘

minify

$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.

route

$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.

store

$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.

tag_for

Deprecated. Use "renderer" in Mojolicious::Plugin::AssetPack::Asset instead.

ua

$ua = $self->ua;

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

πŸ”₯ METHODS πŸ”₯

pipe

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

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

process

$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 separate file.

$definition_file defaults to "assetpack.def".

processed

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

Can be used to retrieve a Mojo::Collection object, with zero or more Mojolicious::Plugin::AssetPack::Asset objects.

register

$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 needs to contain a complete list of pipes that is needed. Example:
$app->plugin(AssetPack => {pipes => [qw(Sass Css Combine)]);
  • 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 information.

🌈 SEE ALSO 🌈

Mojolicious::Plugin::Webpack.

Copyright (C) 2020, 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
  • Mark Grimes - "mgrimes@cpan.org"
  • Per Edin - "info@peredin.com"
  • Viktor Turskyi

okay that's the whole page, bestie 🫢 it's from User Contributed Perl Documentation, built for perl v5.42.0, dated 2024-12-12, and filed as Mojolic...setPack(3). mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from