Created
September 6, 2015 23:25
-
-
Save ORESoftware/3db001fd37bb46860afc to your computer and use it in GitHub Desktop.
Gulpfile for project
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 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