Skip to content

Instantly share code, notes, and snippets.

@jorishr
Last active June 17, 2019 17:14
Show Gist options
  • Save jorishr/6b162bbd419da1882524aaf4e97c1351 to your computer and use it in GitHub Desktop.
Save jorishr/6b162bbd419da1882524aaf4e97c1351 to your computer and use it in GitHub Desktop.
Gulp+BrowserSync+Nodemon
const { series, watch, parallel, src, dest} = require('gulp'),
nodemon = require('nodemon'),
browserSync = require('browser-sync');
function startNodemon (cb) {
let called = false;
return nodemon({
script: './app/app.js',
// watch core server file(s) that require server restart on change
watch: ['./app/app.js']
})
.on('start', function onStart() {
// ensure start only got called once
if (!called) { cb(); }
called = true;
})
.on('restart', function onRestart() {
// reload connected browsers after a slight delay
setTimeout(function reload() {
browserSync.reload({
stream: false
});
}, 2000);
});
};
function startBrowserSync (){
browserSync({
// informs browser-sync to proxy expressjs app (set port to 3000 in app.js)
proxy: 'http://localhost:3000',
// informs browser-sync to use a different port for the proxied app
// the default port is 3000, which would clash with our expressjs
port: 4000
});
};
exports.watch = series(startNodemon, startBrowserSync);
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment