srigi / webloader-require-filter
Sprockets directive plugin (filter) for janmarek/webloader
Installs: 348
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:plugin
Requires
- php: >= 5.3
Requires (Dev)
- nette/tester: ^1.6.1
This package is not auto-updated.
Last update: 2024-12-21 20:30:22 UTC
README
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!