如何基于条件运行一些Gulp任务 [英] How to run some gulp task based on a conditional
本文介绍了如何基于条件运行一些Gulp任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我的gulpfile中有这个文件:
Suppose I have this in my gulpfile:
gulp.task('foo', ...);
gulp.task('bar', function () {
if (something) {
// how do I run task 'foo' here?
}
});
推荐答案
Gulp v3
使用已弃用,但仍在工作 gulp.run
gulp.task('foo', ...)
gulp.task('bar', function () {
if (something) {
gulp.run('foo')
}
})
Alternatively, use use any plugins that consume task names as arguments, like run-sequence for example (which you will probably need anyway for running tasks in a strict sequence). I call my tasks conditionally this way (Gulp v3):
gulp.task('bar', (callback) => {
if (something) {
runSequence('foo', callback)
} else {
runSequence('foo', 'anotherTask', callback)
}
})
Gulp v4
您的gulpfile
,即gulpfile.babel.js
暂时设置,将任务作为导出的函数,因此您可以直接调用它们:
Gulp v4
Your gulpfile
, that is, gulpfile.babel.js
for now, would set Gulp tasks as exported functions so you would call them directly:
export function foo () {
...
}
export function bar () {
if (something) {
foo()
}
}
这篇关于如何基于条件运行一些Gulp任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文