shakyShane / jekyll-gulp-sass-browser-sync

A starter project including full setup for Jekyll, GulpJS, SASS & BrowserSync
728 stars 169 forks source link

Update Gulpfile.js 3 to 4 #71

Open thanooshan opened 5 years ago

thanooshan commented 5 years ago

After updating to the latest version of gulp 4. The project is not running. The problem is because of the latest version of syntax changes. How to update the gulpfile.js to version 4.?

batook22 commented 5 years ago

https://stackoverflow.com/questions/50505275/gulp4-assertionerror-task-never-defined-when-calling-or-importing-tasks

batook22 commented 5 years ago

This code worked for me

`var browsersync = require('browser-sync'); var cp = require('child_process'); var gulp = require('gulp'); var gutil = require('gulp-util'); var sass = require('gulp-sass');

var paths = { html: { src: './app//*.html', }, jekyll: { src: './app', dist: './_site', }, markdown: { src: './app/*/.markdown', }, styles: { src: './app/_sass//*.scss', dist: './app/css', } };

gulp.task(jekyllbuild); gulp.task('jekyllrebuild', gulp.series(jekyllbuild, function(cb) { browsersync.reload(); cb(); })); gulp.task(serve); gulp.task(styles); gulp.task(watch); gulp.task('default', gulp.series( styles, jekyllbuild, gulp.parallel(serve, watch)) );

function jekyllbuild(done) { browsersync.notify('building jekyll'); return cp.spawn('jekyll.bat', ['build'], {stdio: 'inherit'}) .on('close', done); }

function jekyllrebuild() { browsersync.reload(); };

function serve() { browsersync.init({ server: paths.jekyll.dist, notify: true }) }

function styles() { return gulp.src(paths.styles.src) .pipe(sass().on('error', sass.logError)) .pipe(gulp.dest(paths.jekyll.dist + '/css')) .pipe(browsersync.stream()) .pipe(gulp.dest(paths.styles.dist)) }

function watch() { gulp.watch(paths.styles.src, styles); gulp.watch(paths.html.src, gulp.series('jekyllrebuild')); gulp.watch(paths.markdown.src, gulp.series('jekyllrebuild')); }`

batook22 commented 5 years ago

and to update your gulp version to 4 you should type < npm install gulp@^4.0.0 >

luknl commented 3 years ago

Thanks @batook22, your code save me! Worked perfectly :+1: