0

当 Gulp Watch 只需要处理已修改的文件时,我遇到了问题

当我开始时,Gulp 会正确执行任务,但是当我进行更改时,Gulp 手表会再次执行所有任务,而不仅仅是那些已更改的任务。我不知道可能是什么问题,你能帮我吗?

// Watch Task: watch SCSS and JS files for changes
// If any change, run scss and js tasks simultaneously

function watchTask() {
    watch([files.htmlPath, files.scssPath, files.mincssPath, files.cssPath, files.minjsPath, files.jsPath, files.imgPath], 
        parallel(htmlTask, siteTask, series(scssTask, cleanTask, concatCSS), series(jsminTask, jsTask), imgTask));    
}

// Export the default Gulp task so it can be run
// Runs the scss and js tasks simultaneously
// then runs cacheBust, then watch task

exports.default = series(
    parallel(htmlTask, siteTask, series(scssTask, cleanTask, concatCSS), series(jsminTask, jsTask), imgTask), 
    cacheBustTask,
    watchTask
);
4

1 回答 1

1

为了实现您的目标,您应该创建单独的监视函数并并行运行它们。

像这样的东西:

exports.watch = gulp.parallel(watch_html, watch_scss,...);

function watch_html() {
    return gulp.watch(files.htmlPath, htmlTask);
}

function watch_scss(){
    return gulp.watch(files.scssPath, series(scssTask, cleanTask, concatCSS));
}
于 2019-06-20T13:06:13.057 回答