Skip to content

Instantly share code, notes, and snippets.

@anhtran
Created June 1, 2019 02:39
Show Gist options
  • Save anhtran/4f5e4ab981926bffc8a761e0d7fdf549 to your computer and use it in GitHub Desktop.
Save anhtran/4f5e4ab981926bffc8a761e0d7fdf549 to your computer and use it in GitHub Desktop.
Reload Django development server using Browsersync and Gulp 4
const browserSync = require('browser-sync').create();
const spawn = require('child_process').spawn;
function reload(done) {
browserSync.reload();
done();
}
gulp.task('buildCss', gulp.series(
// your functions here
));
gulp.task('runServer', function() {
let cmd = spawn('./venv/bin/python', ['manage.py', 'runserver', 'localhost:8000', '--noasgi'], {stdio: 'inherit'});
cmd.on('close', function(code) {
console.log('runServer exited with code ' + code);
cb(code);
});
});
gulp.task('watch',
gulp.parallel(
'runServer',
function browserSyncInit (cb) {
browserSync.init({
notify: false,
port: 8000,
proxy: 'localhost:8000',
localOnly: true,
reloadDelay: 300,
reloadDebounce: 500
});
cb()
},
function watch_ () {
gulp.watch(['static/**/*.scss'], gulp.series('buildCss', reload));
gulp.watch(['templates/**/*.html'], reload);
gulp.watch(['**/*.py'], reload);
}
)
);
@Vanss472
Copy link

woop woop it worked like a charm

@dimkoug
Copy link

dimkoug commented Apr 30, 2022

what about running the above file in windows os ?

@dimkoug
Copy link

dimkoug commented Apr 30, 2022

spawn is different in windows machine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment