Search code examples
gulpjekyllbabeljs

Gulp Task Watch with Jekyll, gulpfile.babel.js


I'm wondering if what I have can be simplified, it seems a little repetitive but I can't figure out how to run all the file watchers at the same time in a different way.

Any help is appreciated:

let files = {
    html: './*.html',
    htmlDeeper: './*/*/.html',
    css:  './_assets/css/*.scss',
    cssDeeper: './_sass/*/*.scss',
    js:   './*.js',
    jsDeeper: './_assets/js/*.js',
    yml:  './_config.yml'
};

// Watch for file changes

gulp.task('watch', () => {
    gulp.watch(files.html, ['jekyll-reload']);
    gulp.watch(files.htmlDeeper, ['jekyll-reload']);
    gulp.watch(files.css, ['jekyll-reload']);
    gulp.watch(files.cssDeeper, ['jekyll-reload']);
    gulp.watch(files.js, ['jekyll-reload']);
    gulp.watch(files.jsDeeper, ['jekyll-reload']);
    gulp.watch(files.yml, ['jekyll-reload']);
});   

Solution

  • let files = {
    
        html: './**/**/*.html',
        // htmlDeeper: './*/*/.html',
    
        // it isn't clear if this will work for you
        //   perhaps you are trying to exclude something like './other/*.scss' ?
        // css: '/**/*.scss'
    
        css:  './_assets/css/*.scss',
        cssDeeper: './_sass/*/*.scss',
    
        // same comment as above, if you are trying to not include something like
        //  './otherFolder/js/*.js' than the next line would work
    
        //  js: '/**/*.js',
    
        js:   './*.js',
        jsDeeper: './_assets/js/*.js',
    
        yml:  './_config.yml'
    };
    
    
    // gulp.watch(files.htmlDeeper, ['jekyll-reload']);