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.
javascript
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);