0

I have simply 'watchFiles' task which after file changed use task 'reload'. This 'reload' task is in separate file. How can I load this task to my 'watchFiles' task when I don't want this task in the same file?

// watchFiles task
gulp.task(watchFiles);

function watchFiles(cb) {
    watch(src + '**/*.html', series('reload'));
    cb();
}

// reload task in another file
gulp.task(reload);

function reload(cb) {
   browserSync.reload();
   cb();
}

// run from gulpfile
exports.watch = series('watchFiles');
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

I would do like this:

// watchFiles task file = watchfiles_task_file.js
const { reload } = require('./reload_task_file');
const { series, watch } = require('gulp');
const src = './';

function watchFiles(cb) {
    watch(src + '**/*.html', series(reload));
    cb();
}
exports.watchFiles = watchFiles;
// end watchfiles_task_file.js

// reload task in another file = reload_task_file.js
const browserSync = require('browser-sync').create();
function reload(cb) {
   browserSync.reload();
   cb();
}
exports.reload = reload;
// end reload_task_file.js

// gulpfile.js
const { watchFiles } = require('./watchfiles_task_file');
const { series } = require('gulp');

exports.watch = series(watchFiles);
gabrielgeo
  • 507
  • 2
  • 6
  • 17