Skip to content

Instantly share code, notes, and snippets.

@nicolashery
Created October 20, 2014 17:06
Show Gist options
  • Save nicolashery/8e6baed6d3fd6bcde8d5 to your computer and use it in GitHub Desktop.
Save nicolashery/8e6baed6d3fd6bcde8d5 to your computer and use it in GitHub Desktop.
Gulpfile for JSHint on a React app with watch, JSX error logging, and cache
var gulp = require('gulp');
var react = require('gulp-react');
var jshint = require('gulp-jshint');
var cache = require('gulp-cached');
var jsFiles = [
'src/**/*.js',
'test/**/*.js',
'*.js'
];
gulp.task('jshint', function() {
var stream = gulp.src(jsFiles)
.pipe(cache('jshint'))
.pipe(react())
.on('error', function(err) {
console.error('JSX ERROR in ' + err.fileName);
console.error(err.message);
this.end();
})
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
if (process.env.CI) {
stream = stream.pipe(jshint.reporter('fail'));
}
return stream;
});
gulp.task('jshint-watch', ['jshint'], function(cb){
console.log('Watching files for changes...');
gulp.watch(jsFiles, ['jshint']);
});
gulp.task('default', ['jshint']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment