Skip to content

Instantly share code, notes, and snippets.

@laracasts
Last active February 10, 2024 10:57
Show Gist options
  • Save laracasts/8659865 to your computer and use it in GitHub Desktop.
Save laracasts/8659865 to your computer and use it in GitHub Desktop.
Example Laravel-specific Gulpfile from Laracasts.com
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 minifyCSS = require('gulp-minify-css')
var coffee = require('gulp-coffee');
var exec = require('child_process').exec;
var sys = require('sys');
// Where do you store your Sass files?
var sassDir = 'app/assets/sass';
// Which directory should Sass compile to?
var targetCSSDir = 'public/css';
// Where do you store your CoffeeScript files?
var coffeeDir = 'app/assets/coffee';
// Which directory should CoffeeScript compile to?
var targetJSDir = 'public/js';
// Compile Sass, autoprefix CSS3,
// and save to target CSS directory
gulp.task('css', function () {
return gulp.src(sassDir + '/main.sass')
.pipe(sass({ style: 'compressed' }).on('error', gutil.log))
.pipe(autoprefix('last 10 version'))
.pipe(gulp.dest(targetCSSDir))
.pipe(notify('CSS minified'))
});
// Handle CoffeeScript compilation
gulp.task('js', function () {
return gulp.src(coffeeDir + '/**/*.coffee')
.pipe(coffee().on('error', gutil.log))
.pipe(gulp.dest(targetJSDir))
});
// Run all PHPUnit tests
gulp.task('phpunit', function() {
exec('phpunit', function(error, stdout) {
sys.puts(stdout);
});
});
// Keep an eye on Sass, Coffee, and PHP files for changes...
gulp.task('watch', function () {
gulp.watch(sassDir + '/**/*.sass', ['css']);
gulp.watch(coffeeDir + '/**/*.coffee', ['js']);
gulp.watch('app/**/*.php', ['phpunit']);
});
// What tasks does running gulp trigger?
gulp.task('default', ['css', 'js', 'phpunit', 'watch']);
@JeffreyWay
Copy link

Though using gulp.run has been deprecated, as of v3.5.

@zanmoskotevc
Copy link

@mikeerickson that's similiar to what I have, thanks! :)

@mikeerickson
Copy link

FYI, I have written a gulp-phpunit plugin and it should be available in nom in the next day or so. This version makes it plain simple to call :-)

param1 = path to php binary
param2 = options (currently only contains debug flag, will be expanded in future) [optional]

gulp.task('phpunit', function() {
var options = {debug: false};
gulp.src('./app/tests/*.php').pipe(unit('./vendor/bin/phpunit',options));
});

@mikeerickson
Copy link

@jeffrey My plugin does not use gulp.run so works with all versions of gulp (including current 3.5)

@zanmoskotevc Have a look at the gulp-phpunit plugin which should be active tomorrow.

@mikeerickson
Copy link

The gulp-phpunit plugin is now available on nom

https://npmjs.org/package/gulp-phpunit

npm install --save-dev gulp-phpunit

@niallobrien
Copy link

@JeffreyWay Use gulp-plumber to catch those errors.

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