Skip to content

Instantly share code, notes, and snippets.

@githubhy
Created March 22, 2016 01:53
Show Gist options
  • Save githubhy/b0950903534d54a98e1e to your computer and use it in GitHub Desktop.
Save githubhy/b0950903534d54a98e1e to your computer and use it in GitHub Desktop.
gulp+express+nodemon+browerSync -- Restart express server followed by liveload
'use strict';
var gulp = require('gulp');
var bs = require('browser-sync');
var nodemon = require('gulp-nodemon');
gulp.task('default', ['browser-sync'], function () {
});
gulp.task('browser-sync', ['nodemon'], function() {
bs.init(null, {
proxy: "http://localhost:3000",
port: "5000",
files: ["public/**/*.*"],
browser: "safari"
});
});
gulp.task('nodemon', function (cb) {
var started = false;
return nodemon({
env: { 'NODE_ENV': 'development' }
}).on('start', function () {
// to avoid nodemon being started multiple times
// thanks @matthisk
if (!started) {
cb();
started = true;
}
}).on('restart', function() {
setTimeout(function() {
console.log('-------- restart BS --------');
bs.reload();
}, 1000);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment