Last active
October 22, 2023 12:26
-
-
Save dcalhoun/24338df04cdbfcbd2956 to your computer and use it in GitHub Desktop.
Gulp organization with Gulp 4.0, Babel, and require-dir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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)); | |
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
import requireDir from 'require-dir'; | |
requireDir('./gulp/tasks', { recurse: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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)); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
import gulp from 'gulp'; | |
import config from '../config'; | |
import browserSync from 'browser-sync'; | |
gulp.task('server', () => { | |
browserSync({ | |
server: { | |
baseDir: ['./dist'] | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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