Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gulpfile for project
var gulp = require('gulp');
var socketio = require('socket.io');
var EE = require('events').EventEmitter;
var react = require('gulp-react');
var io = socketio.listen('3002', function (err, msg) {
if (err) {
console.error(err);
}
});
io.on('connection', function (socket) {
console.log('a client connected');
socket.on('disconnect', function () {
console.log('a client disconnected');
});
});
gulp.watch('./public/static/app/js/views/**/*.js').on('change', function (file) {
var reconciledPath = reconcilePathForRequireJS(file); //you need to do some work to reconcile RequireJS paths with your front-end app
var ee = transpileJSX();
ee.on('error', function (err) {
io.sockets.emit('.jsx transform error', JSON.stringify(err))
});
ee.on('end', function () {
io.sockets.emit('hot-reload (.jsx)', reconciledPath);
});
});
function transpileJSX() {
var ee = new EE();
gulp.src('./public/static/app/js/views/**/*.js')
.pipe(react({harmony: false})).on('error', function (err) { //we absolutely need error handling, so front-end doesn't croak if we make mistakes writing our JSX
ee.emit('error',err);
})
.pipe(gulp.dest('./public/static/app/js/jsx')).on('error', function (err) {
ee.emit('error',err);
}).on('end', function () {
ee.emit('end');
});
return ee;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.