Skip to content

Instantly share code, notes, and snippets.

@dcalhoun
Last active October 22, 2023 12:26
Show Gist options
  • Save dcalhoun/24338df04cdbfcbd2956 to your computer and use it in GitHub Desktop.
Save dcalhoun/24338df04cdbfcbd2956 to your computer and use it in GitHub Desktop.
Gulp organization with Gulp 4.0, Babel, and require-dir
'use strict';
import gulp from 'gulp';
import config from '../config';
import browserSync from 'browser-sync';
gulp.task('default', gulp.parallel('html', 'scripts', 'styles', 'server', () => {
gulp.watch(config.paths.html.all, gulp.parallel('html', gulp.series('html', browserSync.reload)));
gulp.watch(config.paths.scripts.all, gulp.parallel('scripts', browserSync.reload));
gulp.watch(config.paths.styles.all, gulp.parallel('styles', browserSync.reload));
}));
'use strict';
import requireDir from 'require-dir';
requireDir('./gulp/tasks', { recurse: true });
'use strict';
import gulp from 'gulp';
import config from '../config';
import cp from 'child_process';
gulp.task('html', (callback) => {
var jekyll = cp.spawn('jekyll', ['build', '-q', '--config', '_config.yml'], { stdio: 'inherit' });
jekyll.on('exit', function (code) {
callback(code === 0 ? null : 'ERROR: Jekyll process exited with code: ' + code);
});
});
'use strict';
import gulp from 'gulp';
import config from '../config';
import coffee from 'gulp-coffee';
import sourcemaps from 'gulp-sourcemaps';
gulp.task('scripts', () => {
return gulp.src(config.paths.scripts.entry)
.pipe(sourcemaps.init())
.pipe(coffee().on('error', (err) => {
console.log('CoffeeScript Error:', err);
this.emit('end');
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(config.paths.scripts.dest));
});
'use strict';
import gulp from 'gulp';
import config from '../config';
import browserSync from 'browser-sync';
gulp.task('server', () => {
browserSync({
server: {
baseDir: ['./dist']
}
});
});
'use strict';
import gulp from 'gulp';
import config from '../config';
import sass from 'gulp-sass';
import sourcemaps from 'gulp-sourcemaps';
import autoprefixer from 'gulp-autoprefixer';
gulp.task('styles', () => {
return gulp.src(config.paths.styles.entry)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions']
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(config.paths.styles.dest));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment