Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed gulpfile to support auto rebuild and apply the changes. #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 59 additions & 52 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
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"));
}

/**
* Compile and minify js
*/
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"));
}

/**
* Server functionality handled by BrowserSync
*/
function browserSyncServe(done) {
browserSync.init({
server: '_site',
port: 4000
server: "_site",
port: 4000,
});
done();
}
Expand All @@ -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);
}

/**
Expand All @@ -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));