完成其他任务后运行gulp任务 [英] Run gulp task after completion of other task

查看:96
本文介绍了完成其他任务后运行gulp任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两组文件,我们称它们为basemods. mods文件将覆盖base文件,因此,当我运行与base相关的gulp任务时,我需要在其后直接运行mods任务.我的设置是这样的:

I have two sets of files, let's call them base and mods. The mods files override the base files, so when I run the gulp task related to base, I need to run the mods task directly after. My setup is something like this:

gulp.task('base',function(){
  return gulp.src('base-glob')
    .pipe(...)
    .pipe(gulp.dest('out-glob'))
});

gulp.task('mods',function(){
  return gulp.src('mods-glob')
    .pipe(...)
    .pipe(gulp.dest('out-glob'))
});

所以我想在base任务完成时运行mods任务.请注意,这与将base定义为mods的依赖项不同,因为如果仅更改mods文件,则只需要运行mods任务.我不希望使用插件.

So I want to run the mods task at the completion of the base task. Note that this is not the same as defining base as a dependency of mods, because if I'm only changing mods files, I only need to run the mods task. I'd prefer not to use a plugin.

我一直在阅读有关回调函数和同步任务其他建议的文档,但似乎无法理解.

I've been reading the docs about callback functions and other suggestions of synchronous tasks, but can't seem to get my head around it.

推荐答案

我知道您不想使用插件,但是gulp无法在没有插件的情况下按顺序运行一系列任务. Gulp 4将,但与此同时,权宜之计的解决方案是

I know you don't want to use a plugin, but gulp doesn't have a way to run a sequence of tasks in order without a plugin. Gulp 4 will, but in the meantime the stopgap solution is the run-sequence plugin.

gulp.task('all', function() {
  runSequence('base', 'mods');
});

这可确保任务按顺序运行,而不是无序依赖.

This ensures that the tasks run in order as opposed to unordered dependencies.

现在设置手表:

gulp.task('watch', function() {
    gulp.watch('base-glob', ['all']);
    gulp.watch('mods-glob', ['mods']);
});

只要base-glob发生更改,gulp就会运行all任务,该任务将依次运行base然后是mods.

Whenever base-glob changes, gulp will run all task, which will run the sequence base then mods.

每当mods-glob更改时,gulp将仅运行mods任务.

Whenever mods-glob changes, gulp will run only mods task.

听起来不错吗?

这篇关于完成其他任务后运行gulp任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆