Created
June 1, 2019 02:39
-
-
Save anhtran/4f5e4ab981926bffc8a761e0d7fdf549 to your computer and use it in GitHub Desktop.
Reload Django development server using Browsersync and Gulp 4
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
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); | |
} | |
) | |
); |
what about running the above file in windows os ?
spawn is different in windows machine
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
woop woop it worked like a charm