我只是执行了“ watchFiles”任务,该任务在文件更改后使用了“重新加载”任务。此“重新加载”任务在单独的文件中。当我不想在同一文件中使用该任务时,如何将其加载到“ watchFiles”任务中?
// 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');
答案 0 :(得分:0)
我会这样:
// 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);