This is a Gulp configuration file used to automate various tasks for a web development project. It utilizes various Gulp plugins to minify CSS and JavaScript files, concatenate them, and reload the browser automatically whenever changes are made to the source files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | 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);
|