Last active
October 31, 2015 19:41
-
-
Save austinlyons/a42692aec12d4db121ba to your computer and use it in GitHub Desktop.
Gulp task to speed up universal React development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var babel = require('gulp-babel'); | |
var gutil = require('gulp-util'); | |
var webpack = require('webpack'); | |
var webpackConfig = require('./webpack.config'); | |
// transpile each file from ES6 to ES5 | |
// so that we can use the components in Node | |
gulp.task('babel-server', function() { | |
return gulp.src('./components/*.jsx') | |
.pipe(babel()) | |
.on('error', gutil.log) | |
.pipe(gulp.dest('./es5-lib')); | |
}); | |
// transpile from ES6 to ES5 | |
// and then bundle for client | |
gulp.task('babel-client', function () { | |
var myConfig = Object.create(webpackConfig); | |
// run webpack | |
webpack(myConfig, function(err, stats) { | |
if (err) throw new gutil.PluginError('webpack', err); | |
gutil.log('[webpack]', stats.toString({ | |
colors: true, | |
progress: true | |
})); | |
}); | |
}); | |
gulp.task('watch', function() { | |
gulp.watch('./components/*.jsx', ['babel-server', 'babel-client']); | |
}); | |
gulp.task('default', ['watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment