From 222cce33f3523e973ac7267247406558135658dc Mon Sep 17 00:00:00 2001 From: meower1 <109747197+meower1@users.noreply.github.com> Date: Tue, 10 Sep 2024 10:59:18 +0330 Subject: [PATCH] Fixed gulpfile to support auto rebuild and apply the changes. --- gulpfile.js | 111 ++++++++++++++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 52 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 398602c67..1b014a468 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,40 +1,40 @@ -var gulp = require('gulp'); -var browserSync = require('browser-sync'); -var sass = require('gulp-sass')(require('sass')); -var cssnano = require('gulp-cssnano'); -var prefix = require('gulp-autoprefixer'); -var concat = require('gulp-concat'); -var rename = require('gulp-rename'); -var uglify = require('gulp-uglify'); -var cp = require('child_process'); +var gulp = require("gulp"); +var browserSync = require("browser-sync"); +var sass = require("gulp-sass")(require("sass")); +var cssnano = require("gulp-cssnano"); +var prefix = require("gulp-autoprefixer"); +var concat = require("gulp-concat"); +var rename = require("gulp-rename"); +var uglify = require("gulp-uglify"); +var cp = require("child_process"); /** * Compile and minify sass */ function styles() { return gulp - .src([ '_sass/*.scss' ]) + .src(["_sass/*.scss"]) .pipe( sass({ - includePaths: [ 'scss' ], - onError: browserSync.notify + includePaths: ["scss"], + onError: browserSync.notify, }) ) - .pipe(prefix([ 'last 3 versions', '> 1%', 'ie 8' ], { cascade: true })) - .pipe(rename('main.min.css')) + .pipe(prefix(["last 3 versions", "> 1%", "ie 8"], { cascade: true })) + .pipe(rename("main.min.css")) .pipe(cssnano()) - .pipe(gulp.dest('_site/assets/css/')) + .pipe(gulp.dest("_site/assets/css/")) .pipe(browserSync.reload({ stream: true })) - .pipe(gulp.dest('assets/css')); + .pipe(gulp.dest("assets/css")); } function stylesVendors() { return gulp - .src([ '_sass/vendors/*.css' ]) - .pipe(concat('vendors.min.css')) + .src(["_sass/vendors/*.css"]) + .pipe(concat("vendors.min.css")) .pipe(cssnano()) - .pipe(gulp.dest('_site/assets/css/')) - .pipe(gulp.dest('assets/css')); + .pipe(gulp.dest("_site/assets/css/")) + .pipe(gulp.dest("assets/css")); } /** @@ -42,21 +42,21 @@ function stylesVendors() { */ function scripts() { return gulp - .src([ '_js/app.js' ]) - .pipe(rename('app.min.js')) + .src(["_js/app.js"]) + .pipe(rename("app.min.js")) .pipe(uglify()) - .pipe(gulp.dest('_site/assets/js')) + .pipe(gulp.dest("_site/assets/js")) .pipe(browserSync.reload({ stream: true })) - .pipe(gulp.dest('assets/js')); + .pipe(gulp.dest("assets/js")); } function scriptsVendors() { return gulp - .src([ '_js/vendors/*.js' ]) - .pipe(concat('vendors.min.js')) + .src(["_js/vendors/*.js"]) + .pipe(concat("vendors.min.js")) .pipe(uglify()) - .pipe(gulp.dest('_site/assets/js')) - .pipe(gulp.dest('assets/js')); + .pipe(gulp.dest("_site/assets/js")) + .pipe(gulp.dest("assets/js")); } /** @@ -64,8 +64,8 @@ function scriptsVendors() { */ function browserSyncServe(done) { browserSync.init({ - server: '_site', - port: 4000 + server: "_site", + port: 4000, }); done(); } @@ -79,21 +79,11 @@ function browserSyncReload(done) { * Build Jekyll site */ function jekyll(done) { - return cp - .spawn( - 'bundle', - [ - 'exec', - 'jekyll', - 'build', - '--incremental', - '--config=_config.yml,_config_dev.yml' - ], - { - stdio: 'inherit' - } - ) - .on('close', done); + cp.spawn( + "bundle", + ["exec", "jekyll", "build", "--config=_config.yml,_config_dev.yml"], + { stdio: "inherit" } + ).on("close", done); } /** @@ -102,36 +92,53 @@ function jekyll(done) { */ function watchData() { gulp.watch( - [ '_data/*.yml', '_config.yml', 'assets/*.json' ], + ["_data/*.yml", "_config.yml", "assets/*.json"], gulp.series(jekyll, browserSyncReload) ); } function watchMarkup() { gulp.watch( - [ 'index.html', '_includes/*.html', '_layouts/*.html' ], + ["index.html", "_includes/*.html", "_layouts/*.html"], gulp.series(jekyll, browserSyncReload) ); } function watchScripts() { - gulp.watch([ '_js/*.js' ], scripts); + gulp.watch(["_js/*.js"], scripts); } function watchStyles() { - gulp.watch([ '_sass/*.scss' ], styles); + gulp.watch(["_sass/*.scss"], styles); } function watch() { - gulp.parallel(watchData, watchMarkup, watchScripts, watchStyles); + gulp.watch( + [ + "_data/*.yml", + "_config.yml", + "assets/*.json", + "_includes/*.html", + "_layouts/*.html", + "index.html", + ], + gulp.series(jekyll, browserSyncReload) + ); + gulp.watch(["_sass/*.scss"], gulp.series(styles, jekyll, browserSyncReload)); + gulp.watch(["_js/*.js"], gulp.series(scripts, jekyll, browserSyncReload)); } var compile = gulp.parallel(styles, stylesVendors, scripts, scriptsVendors); -var serve = gulp.series(compile, jekyll, browserSyncServe); +var serve = gulp.series( + compile, + jekyll, + gulp.parallel(browserSyncServe, watch) +); + var watch = gulp.parallel(watchData, watchMarkup, watchScripts, watchStyles); /** * Default task, running just `gulp` will compile the sass, * compile the Jekyll site, launch BrowserSync & watch files. */ -gulp.task('default', gulp.parallel(serve, watch)); +gulp.task("default", gulp.parallel(serve, watch));