Skip to content
Sprockets directive plugin (filter) for janmarek/webloader
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
.travis.yml
LICENSE
README.md
composer.json

README.md

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
You can’t perform that action at this time.