From cc353694b62bfb377e168d25943cea2ef164d0f4 Mon Sep 17 00:00:00 2001 From: matt Date: Sat, 26 Feb 2022 22:30:40 +0000 Subject: [PATCH] Updated gulpfile to use modern syntax --- gulpfile.js | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 21eee5c..fe6f3c3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,16 +2,18 @@ // Import required modules const del = require('del'); -const gulp = require('gulp'); +const { dest, series, src, watch } = require('gulp'); const postcss = require('gulp-postcss'); const sass = require('gulp-sass')(require('sass')); // Set src and destination paths for css compilation -const src = 'src/stylesheets/main.scss'; -const dest = 'public/css'; +const cssPaths = { + src: 'src/stylesheets/main.scss', + dest: 'public/css' +}; -// Task to compile and optimise css from sass file -gulp.task('styles', () => { +// Compile and optimise css from sass file +function compileStyles() { let cssnanoOptions = { normalizeWhitespace: false }; @@ -27,25 +29,21 @@ gulp.task('styles', () => { require('postcss-sort-media-queries') ]; - return gulp.src(src) + return src(cssPaths.src) .pipe(sass().on('error', sass.logError)) .pipe(postcss(plugins)) - .pipe(gulp.dest(dest)); -}); + .pipe(dest(cssPaths.dest)); +} -// Task to clean up the destination directory -gulp.task('clean', () => { - return del([ - dest - ]); -}); +// Clean css destination directory +function cleanStyles() { + return del([ cssPaths.dest ]); +} -// When called with no task, clean the destination, and then compile styles -gulp.task('default', gulp.series([ 'clean', 'styles' ])); +// Task to build stylesheet from start to finish +exports.styles = series(cleanStyles, compileStyles); // Task to watch for changes in sass files, then compile on changes -gulp.task('watch', () => { - gulp.watch('src/stylesheets/**/*.scss', (done) => { - gulp.series([ 'clean', 'styles' ])(done); - }); -}); +exports.watchStyles = () => { + watch('src/stylesheets/**/*.scss', exports.styles); +};