简体   繁体   English

忽略gulp.js中的任务依赖项

[英]Ignoring task dependencies in gulp.js

I have the following task 我有以下任务

gulp.task('sass-build', ['clean-build'], function () {
    // do stuff
});

which obviously requires clean-build to be finished before starting. 显然,这需要在开始之前完成clean-build However, I would also like to use this task with gulp.watch without the clean-build dependency. 但是,我还想将此任务与gulp.watch一起使用,而没有clean-build依赖性。

I'm aware that you could solve this with a helper task like suggested in Skipping Tasks Listed as Dependencies in Gulp , but this would require using gulp.run (which is deprecated) or gulp.start (which isn't even documented because it's considered bad practise). 我知道您可以使用帮助任务来解决此问题, 如在Gulp跳过作为依赖项列出的任务中所建议的那样 ,但这将需要使用gulp.run (已弃用)或gulp.start (甚至没有记录,因为它是被认为是坏习惯)。

What would be a better way of doing this? 有什么更好的方法呢? Or is the only way to use gulp.run or gulp.start ? 还是使用gulp.rungulp.start的唯一方法?

The approach showed in the linked question is actually not that bad. 链接问题中显示的方法实际上还不错。 Instead of gulp.run you can use simple functions which do the same: 除了gulp.run您还可以使用执行相同操作的简单函数:

var sassFunction = function() {
    return gulp.src('blahbla')
        .pipe(bla())
}

gulp.task('sass-build', ['clean-build'], function () {
    return sassFunction()
});

gulp.task('sass-dev', function () {
    return sassFunction();
});


gulp.task('watch', function() {
    gulp.watch('your/sass/files/**/*.scss', ['sass-dev'])
});

Your other approach is also not so bad and will be fully incorporated with Gulp 4. 您的其他方法也不错,并将与Gulp 4完全合并。

gulp.task('default', gulp.series('clean-build', gulp.parallel('sass-build')));

Something to look out for, since it changes dependency trees completely. 需要注意的事情,因为它完全更改了依赖关系树。

I solved this using run-sequence . 我使用run-sequence解决了这个问题。 This also made the entire multitask order much clearer. 这也使整个多任务顺序更加清晰。

What I did exactly was remove the clean-build dependency from sass-build . 我所做的就是从sass-build删除clean-build依赖sass-build So eventually: 所以最终:

gulp.task('sass-build', function () {
    // do stuff
});

gulp.task('build', function () {
    runSequence('clean-build', [..., 'sass-build', ...], 'index-build');
});

gulp.task('watch', function () {
    gulp.watch('src/sass/*', ['sass-build']);
});

Very convenient! 很方便!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM