Skip to content

Instantly share code, notes, and snippets.

@robbintt
Forked from gabrielhpugliese/gulpfile.js
Last active April 5, 2019 07:20
Show Gist options
  • Save robbintt/54e97da94e02fc3c8ac9 to your computer and use it in GitHub Desktop.
Save robbintt/54e97da94e02fc3c8ac9 to your computer and use it in GitHub Desktop.
Django collectstatic + Gulp watch
var gulp = require('gulp');
// Run shell commands with exec:
// https://www.npmjs.com/package/gulp-exec
var exec = require('child_process').exec;
// collectstatic task for Django
// https://www.npmjs.com/package/gulp-exec
gulp.task('collectstatic', function (cb) {
exec('python ../../manage.py collectstatic -i node_modules -i bower_components --noinput', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
// collectstatic should be added to the end of each watch command rather than initalizing alone.
//gulp.task('watch', function () {
// gulp.watch('static/**/*.*', ['collectstatic']);
//});
@robbintt
Copy link
Author

robbintt commented Nov 5, 2015

Noted gulp-shell is blacklisted for antipatterns, tried gulp-exec but found they recommended not using their plugin for this very simple use-case. This pattern is modified from the howto on gulp-exec.

https://www.npmjs.com/package/gulp-exec

https://github.com/gulpjs/plugins/blob/master/src/blackList.json

@robbintt
Copy link
Author

robbintt commented Nov 5, 2015

I also added some output to gulp watch to remind me to enter a virtual environment (have django and requirements installed to run manage.py).

@Sydney-o9
Copy link

Note gulp 4.x: Pass a gulp.series() invocation with only one task name.

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