来自其他Gulp任务的Gulp任务? [英] Gulp tasks from within other Gulp tasks?
问题描述
gulp.task('
)我有一个Gulp构建任务,由其他构建任务组成: build',['build-html','build-css','build-js','build-images']);
我最讨厌的是 build
启动'build-html'...
在1 s后完成'build-html'
开始'build-css'...
在1 s后完成'build-css'
开始'build-js'...
在1秒后完成'build-js'
开始'构建图像'...
在1秒后完成'构建图像'
开始'构建'...
在1 ms后完成'build'
现在很明显, build
根本不应该运行,直到它的依赖关系完成,所以它按预期工作。但是这导致控制台说 build
只花了1毫秒,实际上它应该说花了4秒钟,因为它的所有依赖关系花了很长时间。如果看起来像这样:
启动'build'...
启动'build- html'...
1 s后完成'build-html'
开始'build-css'...
1 s后完成'build-css'
开始' build-js'...
在1 s后完成'build-js'
开始'build-images'...
在1 s后完成'build-images'
4 s后完成'build'
注意 build
是开始的第一件事,然后所有依赖运行,然后 build
完成。
所以我想知道的是,我可以从 build 中一次调用每个任务,而不是使用任务依赖关系。 code>任务?如果是这样,我用什么命令来做到这一点?
这是一个坏主意吗?是否有更好的解决方案来解决这个问题?我猜你可以使用 .com / OverZealous / run-sequencerel =nofollow> runSequence 插件来做你想做的事。
因为你的 build
任务是启动所有 build - *
任务,并且没有特定的顺序,这可以如下所示:
var rs = require('run-sequence');
gulp.task('build',function(cb){
rs(['build-css','build-html','build-js','build-images '],cb);
});
I have a Gulp build task that is made up of other build tasks similar to this:
gulp.task('build', ['build-html', 'build-css', 'build-js', 'build-images']);
The thing I hate about this is that the build
task doesn't run until after the dependencies are finished:
Starting 'build-html'...
Finished 'build-html' after 1 s
Starting 'build-css'...
Finished 'build-css' after 1 s
Starting 'build-js'...
Finished 'build-js' after 1 s
Starting 'build-images'...
Finished 'build-images' after 1 s
Starting 'build'...
Finished 'build' after 1 ms
Now obviously, build
is not supposed to run at all until it's dependencies are finished, so it's working as expected. But this results in the console saying build
took only 1 ms when in reality it should say it took 4 seconds, since all it's dependencies took that long. It would be nice if it looked something like this:
Starting 'build'...
Starting 'build-html'...
Finished 'build-html' after 1 s
Starting 'build-css'...
Finished 'build-css' after 1 s
Starting 'build-js'...
Finished 'build-js' after 1 s
Starting 'build-images'...
Finished 'build-images' after 1 s
Finished 'build' after 4 s
Notice how build
is the first thing that "starts", then all the dependencies run, then build
finishes.
So what I'm wondering, instead of using task dependencies, can I just call each task one at a time from within the build
task? If so, what command do I use to do this?
Is this a bad idea? Is there a better solution to this problem?
I guess you could use the runSequence plugin to do what you want.
Since the only purpose of your build
task is to launch all the build-*
tasks with no specific order, this can look like:
var rs = require('run-sequence');
gulp.task('build', function (cb) {
rs(['build-css', 'build-html', 'build-js', 'build-images'], cb);
});
这篇关于来自其他Gulp任务的Gulp任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!