Download the PHP package dotsunited/bundlefu without Composer
On this page you can find all versions of the php package dotsunited/bundlefu. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dotsunited/bundlefu
More information about dotsunited/bundlefu
Files in dotsunited/bundlefu
Package bundlefu
Short Description BundleFu is a PHP 5.3+ library which bundles multiple css/javascript files into a big package and sends it out at once
License MIT
Homepage https://github.com/dotsunited/BundleFu
Informations about the package bundlefu
BundleFu
BundleFu is a PHP 5.3+ library which bundles multiple css/javascript files into a big package and sends it out at once.
It is highly inspired by the Ruby on Rails plugin bundle-fu.
In short, it turns this:
Into this:
Features
- Automatically detects modifications to your css and javascript files and regenerates the bundles automatically.
- Bundle contents can be modified by filters for css url rewriting to avoid broken images, code minification and compression etc. (A Google Closure Compiler filter using the Service API comes with the library).
Installation
BundleFu can be installed using the Composer tool. You can either add dotsunited/bundlefu
to the dependencies in your composer.json, or if you want to install BundleFu as standalone, go to the main directory and run:
You can then use the composer-generated autoloader to access the BundleFu classes:
Usage
Configure a Bundle instance:
Alternatively, you can pass an options array to the constructor (or use the method setOptions
later):
Use the instance to bundle your files in your templates:
Output the bundle <script>
and <link>
tags wherever you want:
Using the Factory
You can also use a factory to create bundle instances. The advantage is, that the factory can hold global options (like bypass
and doc_root
) which are shared across all created bundles:
You can pass specific options to the createBundle
method (global factory options will be overwritten):
The factory also lets you define name aliases for filters. You can then define the string alias for the css_filter
and js_filter
options instead of passing a filter instance:
Filters
You can manipulate the loaded css/javascript files and the bundled css/javascript code with filters. Filters are classes which implement DotsUnited\BundleFu\Filter\FilterInterface
.
You can add filters like this:
If you need multiple filters, you can use DotsUnited\BundleFu\Filter\FilterChain
like this:
Default filters
BundleFu provides the following filters out of the box.
CssUrlRewriteFilter
The DotsUnited\BundleFu\Filter\CssUrlRewriteFilter
rewrites relative URLs in your CSS file to avoid broken image references:
ClosureCompilerServiceFilter
This filter compiles javascript code with the Google Closure Compiler using the Service API.
Simply add the DotsUnited\BundleFu\Filter\ClosureCompilerServiceFilter
filter and your javascript bundles will be automatically compiled:
CallbackFilter
The DotsUnited\BundleFu\Filter\CallbackFilter
can filter by using any PHP callback. If you want to compress your CSS using YUI Compressor you can either write a custom filter or use the following code leveraging the Callback
filter:
Notes
- All content inside of
$bundle->start()
and$bundle->end()
will be lost. Be sure to only put css/javascript includes inside of the block. -
Scripts/stylesheets are detected by parsing the output and looking for include files. HTML comments are ignored, so if you comment out a script like this:
the comment will be ignored and the file will be bundled anyways. Be sure to comment out via PHP:
-
External dependencies via querystring loading will not work:
Instead, you'll need to include each javascript file as normal.
License
BundleFu is released under the MIT License.