Created
April 30, 2022 12:56
-
-
Save dimkoug/6fd73cfc7c2d609944440f8e61a1204f to your computer and use it in GitHub Desktop.
example gulpfile for use with django
This file contains 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
/* change paths based on your project */ | |
const { parallel, src, dest, watch, series } = require('gulp'); | |
const gulp = require("gulp"); | |
let rename = require("gulp-rename"); | |
const cleanCSS = require('gulp-clean-css'); | |
const minify = require('gulp-minify'); | |
let wrap = require('gulp-wrap'); | |
let declare = require('gulp-declare'); | |
let concat = require('gulp-concat'); | |
let exec = require('child_process').exec; | |
const browsersync = require('browser-sync').create(); | |
let spawn = require('child_process').spawn; | |
function css(){ | |
return gulp.src([ | |
'./static/src/css/*.css']) | |
.pipe(concat('site.css')) | |
.pipe(cleanCSS({compatibility: 'ie8'})) | |
.pipe(rename({extname:'.min.css'})) | |
.pipe(gulp.dest('./static/build/css')) | |
.pipe(browsersync.reload({ | |
stream: true | |
})) | |
} | |
function vendor(){ | |
return gulp.src([ | |
'./static/src/js/jquery-3.6.0.min.js', | |
'./static/src/js/popper.min.js', | |
'./static/src/js/bootstrap.min.js', | |
'./static/src/js/django_ajax.js', | |
'./static/src/js/site.js', | |
]) | |
.pipe(concat('site.js')) | |
.pipe(minify()) | |
.pipe(gulp.dest('./static/build/js')) | |
.pipe(browsersync.reload({ | |
stream: true | |
})) | |
} | |
function browsersyncServe(cb){ | |
browsersync.init({ | |
notify: false, | |
proxy: "localhost:8000" | |
}); | |
browsersync.watch('static/src/css/**/*.css', series(css)); | |
browsersync.watch('static/src/js/**/*.js', series(vendor)); | |
browsersync.watch('templates/**/*.html', browsersync.reload); | |
browsersync.watch('templates/*.html', browsersync.reload); | |
cb(); | |
} | |
function runServer(){ | |
var cmd = spawn('venv/Scripts/python.exe', ['manage.py', 'runserver'], {stdio: 'inherit'}); | |
cmd.on('close', function(code) { | |
console.log('runServer exited with code ' + code); | |
cb(code); | |
}); | |
} | |
exports.css = css; | |
exports.vendor = vendor; | |
exports.runServer = runServer; | |
exports.browsersyncServe = browsersyncServe; | |
exports.default = parallel(css, vendor, runServer, browsersyncServe); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment