jboysen / laravel-gcc
Use Google Closure Compiler to minify javascript files in Laravel 4.
Requires
- php: >=5.3.0
- illuminate/support: >=4.0
- neeckeloo/closure-compiler-php: dev-master
Requires (Dev)
- mockery/mockery: dev-master
- orchestra/testbench: 2.0.*
README
This Laravel4 package adds a view-helper javascript_compiled()
to minimize a single javascript file or bundles of
several javascript files. Everything is done using Google Closure Compiler.
Installation
Install it via Composer by adding the following to your composer.json
-file (the asterix can be changed to an exact version):
"jboysen/laravel-gcc": "1.*"
NOTE: if you get this error: zendframework/zend-http dev-master requires zendframework/zend-stdlib dev-master -> no matching package found.
, you might have got this error..
...and add the following to the providers
-array in your app/config/app.php
:
'Jboysen\LaravelGcc\LaravelGccServiceProvider',
Configuration
The config-file is self-explanatory: config.php
To change some of the settings, simply just run (as always) php artisan config:publish jboysen/laravel-gcc
Usage
View helper
The helper accepts either a string representing a single javascript file or an array representing several files (a bundle). A bundle will be compiled in the order given in the array.
Example #1:
// hello.blade.php
...
{{ javascript_compiled('default.js') }}
Example #2:
// hello.php
...
<?php echo javascript_compiled(array(
'jquery.js',
'default.js'
)); ?>
This helper will:
- Lookup the files given as argument to the helper.
- Create a unique filename for the compiled files based on the filenames and the last modification time of the files.
- Compile the bundle (if it's not present).
- Output a script-tag linking to the compiled file.
artisan commands
gcc:build
As compilation of several files sometimes can take time, it is better to do this "offline", that is before any users hit the web application.
php artisan gcc:build
This command will scan all files in the /app/views
-directory and find all uses of the view-helper described above, and
compile the bundles immediately, making sure the users won't experience any long response times.
gcc:clean
Remove all files from the /app/storage/laravel-gcc
-folder. This task might be useful in deployment-procedures.