Skip to content

Instantly share code, notes, and snippets.

@VictorKid
Created May 22, 2016 14:21
Show Gist options
  • Save VictorKid/1947f3b2ccb5f22e55a35362197cf1ca to your computer and use it in GitHub Desktop.
Save VictorKid/1947f3b2ccb5f22e55a35362197cf1ca to your computer and use it in GitHub Desktop.
gulp file example
var gulp = require('gulp');
var cp = require('child_process');
gulp.task('default', ['build:client', 'watch'], function () {
gulp.start('server:spawn');
});
gulp.task('watch', function () {
gulp.watch('src/*.js', ['build:client']);
gulp.watch('server.js', ['server:restart']);
});
gulp.task('build:client', function (cb) {
cp.spawn('webpack', {stdio: 'inherit'})
.on('exit', function () {
cb();
});
});
gulp.task('build:server', function () {
console.log('server');
});
gulp.task('server:spawn', function () {
spawnServer();
});
gulp.task('server:restart', function () {
killServer();
spawnServer();
});
var _p;
function spawnServer () {
if (_p) {
_p.kill();
}
_p = cp.spawn('node', ['server.js'], {
stdio: 'inherit'
});
}
function killServer () {
if (_p) {
_p.kill();
}
}
process.on('exit', function () {
killServer();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment