Componette

Componette

srigi

srigi / webloader-require-filter

Sprockets directive plugin (filter) for janmarek/webloader

download-cloud-line composer require srigi/webloader-require-filter

srigi/webloader-require-filter

Build Status Latest Stable Version Composer Downloads

This is a plugin for janmarek/webloader which adds availability to interpret sprockets directives in you Javascript and Coffeescript files. It is based on rafacgarciaa/php-lilo.

Lilo is a fast engine that allow you scan a file to extract a dependency graph using a subset of Sprockets directives. Following directives are supported:

//= require
//= require_directory
//= require_tree

For more information about them please visit Sprockets.

Usage (javascript)

In your javascript files, write Sprockets-style comments to indicate dependencies, e.g.

//= require ../bower_components/jquery/dist/jquery.js

If you want to bring in a whole folder of files, use

//= require_tree libs

Please note, that sprocket directives must be at the top of the javascript file!

//= require ../bower_components/jquery/dist/jquery.js

;(function($) {
  // your code

}(jQuery))

Installation (Webloader)

Install this package via Composer:

composer require srigi/webloader-require-filter

Configure Webloader to use filter:

services:
    requireFilter: Srigi\Webloader\Filters\RequireFilter

extensions:
    webloader:
        js:
            default:
                sourceDir: %wwwDir%/../assets/scripts
                joinFiles: not(%debugMode%)
                fileFilters:
                    - @requireFilter
                watchFiles:
                    - {files: ["*.js"], from: %wwwDir%/../assets/scripts}

By default webloader-require-filter works with Javascript files. You can also process Coffeescript files, just configure service:

services:
    requireFilter: Srigi\Webloader\Filters\RequireFilter(['js', 'coffee'])

Currently webloader-require-filter seach dependencies in sourceDir of the processed file. Don't forget to setup sourceDir in your webloader configuration!

Credits

  • Lilo, a file concatenation tool for PHP inspired by Sprockets
  • Sprockets, Rack-based asset packaging system

No release at this moment. Try to create first one.

price-tag-2-line

Badges

guide-fill

Dependencies

php (>= 5.3)
Componette Componette felix@nette.org