Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 13:55
Show Gist options
  • Save isimmons/8701121 to your computer and use it in GitHub Desktop.
Save isimmons/8701121 to your computer and use it in GitHub Desktop.
gulpfile for gulp.js + Laravel: Compile sass/coffee, run phpunit tests, livereload css, js, and blade templates
See dev dependencies
Compiles sass to compressed css with autoprefixing
Compiles coffee to javascript
Livereloads on changes to coffee, sass, and blade templates
Runs PHPUnit tests
Watches sass, coffee, blade, and phpunit
Default tasks sass, coffee, phpunit, watch
var gulp = require('gulp');
var gutil = require('gulp-util');
var notify = require('gulp-notify');
var sass = require('gulp-ruby-sass');
var autoprefix = require('gulp-autoprefixer');
var coffee = require('gulp-coffee');
var phpunit = require('gulp-phpunit');//notify requires >= v 0.0.3
var fs = require('fs'); //only used for icon file with growlNotifier
// livereload
var livereload = require('gulp-livereload');
var lr = require('tiny-lr');
var server = lr();
//uncomment for growl notify for windows users
//Specify custom icon by passing object to growl() { icon: fs.readFileSync('path_to_icon_file') }
//var growl = ('gulp-notify-growl');
//var growlNotifier = growl();
//CSS directories
var sassDir = 'app/assets/sass';
var targetCSSDir = 'public/css';
//javascript directories
var coffeeDir = 'app/assets/coffee';
var targetJSDir = 'public/js';
// blade directory
var bladeDir = 'app/views';
// Tasks
/* sass compile */
gulp.task('sass', function() {
return gulp.src(sassDir + '/main.scss')
.pipe(sass({ style: 'compressed'}).on('error', gutil.log))
.pipe(autoprefix('last 10 versions'))
.pipe(notify('CSS compiled, prefixed, and minified.'));
//growlNotifier for windows
//.pipe(notify({title: 'CSS Compiled', message: 'compiled, prefixed, and minified.', notifier: growlNotifier}));
/* coffee compile */
gulp.task('coffee', function() {
return gulp.src(coffeeDir + '/**/*.coffee')
.pipe(coffee().on('error', gutil.log))
/* Blade Templates */
gulp.task('blade', function() {
return gulp.src(bladeDir + '/**/*.blade.php')
/* PHPUnit */
gulp.task('phpunit', function() {
//notify defaults to false. If you don't want to use a notifier or worry with errors in this task leave it off
var options = {debug: false, notify: true}
.pipe(phpunit('', options)) //empty phpunit path defaults ./vendor/bin/phpunit for windows specify with double back slashes
//both notify and notify.onError will take optional notifier: growlNotifier for windows notifications
//if options.notify is true be sure to handle the error here or suffer the consequenses!
.on('error', notify.onError({
title: 'PHPUnit Failed',
message: 'One or more tests failed, see the cli for details.'
//will fire only if no error is caught
title: 'PHPUnit Passed',
message: 'All tests passed!'
/* Watcher */
gulp.task('watch', function() {
server.listen(35729, function(err) {
if(err) {console.log(err);} + '/**/*.blade.php', ['blade']); + '/**/*.scss', ['sass']); + '/**/*.coffee', ['coffee']);
});'app/**/*.php', ['phpunit']);
/* Default Task */
gulp.task('default', ['sass', 'coffee', 'phpunit', 'watch']);
Copy link

hao1987 commented Jan 28, 2015

question, im a newbie in gulp, what shall i put this file in laravel project, asset/ ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment