gulp4 顺序 任务
gulp.js is an awesome utility for so many things. I've recently started using gulp as a build tool for the next blog redesign, whenever that may come. In the past I had written my own build scripts but they quickly got messy and I ran into problems with concurrent tasks and knowing when each was complete. gulp.js has made my build code prettier but I still get caught with timing issues due to async tasks.
gulp.js是一个很棒的工具,可以处理很多事情。 我最近开始使用gulp作为下一次博客重新设计的构建工具,只要有可能。 过去,我编写了自己的构建脚本,但是它们很快变得混乱不堪,我遇到了并发任务以及何时完成每个任务的问题。 gulp.js使我的构建代码更漂亮,但是由于异步任务,我仍然陷入计时问题。
Of course the nature of JS is becoming async but sometimes I just want a "top down" build process -- that's where run-sequence comes in. With run-sequence I can easily group tasks to ensure they are done before setting off other tasks!
当然,JS的性质正在变得异步,但是有时我只想要一个“自上而下”的构建过程-这就是运行顺序的所在。借助运行顺序,我可以轻松地对任务进行分组,以确保在完成其他任务之前完成任务!
run-sequence works by passing arguments in the form of arrays or strings; an array signifies the tasks can be run concurrently, a string signifies a single task:
运行序列通过以数组或字符串形式传递参数来工作; 数组表示任务可以同时运行,字符串表示单个任务:
var runSequence = require('run-sequence');
gulp.task('some-task', function() {
runSequence(
['task-1', 'task-2', 'task-3'], // These 3 can be done in parallel
'task-4', // ...then just do this
['task-5', 'task-5'], // ...then do these things in parallel
'task-6', // ...then do this
// ....
);
});
Each successive argument waits for the previous task(s) to finish. My future theme's working gulp build file default task looks as follows:
每个连续的参数都等待先前的任务完成。 我未来主题的工作gulp构建文件默认任务如下所示:
// Create the default run action, which should be the entire build
gulp.task('default', function() {
runSequence(
['copy-js-dir', 'copy-php-files', 'copy-image-files', 'compile-stylus'],
'clone-prism',
['minify-css', 'minify-js'],
'replace-build-ids',
'create-backup-zip',
'move-to-wordpress'
);
});
JavaScript purists will hate on me for not creating my own promises to avoid the need for sync and run-sequence, but to be honest, I don't care. Adding my own promises would make the code messier and with little speed benefit.
JavaScript纯粹主义者会讨厌我没有创建自己的承诺以避免避免同步和运行顺序,但是老实说,我不在乎。 添加我自己的承诺会使代码更加混乱,并且几乎没有速度收益。
Sometimes we have to make concessions for the sake of maintainability -- all developers know that. run-sequence was a concession I've made to keep my code maintainable and logical in my own head.
有时,出于可维护性的考虑,我们不得不做出让步-所有开发人员都知道这一点。 运行顺序是我为让我的代码保持可维护性和逻辑性而做出的让步。
gulp4 顺序 任务