Skip to content

Instantly share code, notes, and snippets.

@bkonkle
Created April 7, 2015 18:12
Show Gist options
  • Save bkonkle/cb0abc09af20ce115583 to your computer and use it in GitHub Desktop.
Save bkonkle/cb0abc09af20ce115583 to your computer and use it in GitHub Desktop.
Simple JSX compile task
var args = require('../utils').args;
var debug = require('gulp-debug');
var gulp = require('gulp');
var gutil = require('gulp-util');
var notifier = require('node-notifier');
var path = require('path');
var plumber = require('gulp-plumber');
var react = require('gulp-react');
var production = (args.env === 'production');
var base = args['base-dir'] + '/src/main/webapp/js';
var destination = args['build-directory'] + '/' + args['build-final-name'] + '/js';
gulp.task('compile-jsx', function() {
var source = base + '/**/*.jsx';
return gulp.src(source, {base: base})
// In development, report errors but don't disconnect the stream
.pipe(production ? gutil.noop() : plumber(function (err) {
// Output to the log
gutil.log('JSX ERROR in ' + gutil.colors.magenta(path.basename(err.fileName)) + ':', err.message);
// Pop up a desktop notification
notifier.notify({
'title': 'JSX error in ' + path.basename(err.fileName),
'message': err.message
});
}))
// Compile the JSX to plain JS
.pipe(react())
.pipe(debug({title: 'compile-jsx:', minimal: true, count: true}))
// Output to the build directory, using 'jsmin' in production
.pipe(gulp.dest(destination));
});
gulp.task('watch-jsx', ['compile-jsx'], function() {
var source = base + '/**/*.jsx';
return gulp.watch(source, ['compile-jsx']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment