Created
May 22, 2016 14:21
-
-
Save VictorKid/1947f3b2ccb5f22e55a35362197cf1ca to your computer and use it in GitHub Desktop.
gulp file example
This file contains hidden or 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 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