我是gulp世界的新手,因此我仍然在踩着如何对这件事情进行排查。
问题:正在跳过zip
任务,甚至是在默认情况下定义的任务。任务。
我遗失的地方/我在哪里?
更多详情
gulp zip
在命令行中指定时运行正常(没有eg;语法错误,并且正在按预期生成输出):
$ gulp zip
[16:49:41] Using gulpfile ~/Work/........../gulpfile.js
[16:49:41] Starting 'zip'...
[16:49:41] Finished 'zip' after 11 ms
$
但是,在运行gulp
时(没有任何其他参数,这意味着选择了default
):
$ gulp
[16:49:34] Using gulpfile ~/Work/........../gulpfile.js
[16:49:34] Starting 'clean'...
[16:49:34] Finished 'clean' after 35 ms
...
...
[16:49:36] Finished 'minify-css' after 750 ms
[16:49:36] Starting 'build'...
[16:49:36] Finished 'build' after 2.1 μs
$
正在跳过zip
任务(!?)
检查'默认'任务定义:
gulp.task('default', ['clean'], function () {
gulp.start('build');
});
并且`build'任务定义为:
gulp.task('build', ['html', 'images', 'fonts', 'misc', 'i18n', 'swagger', 'minify-js', 'minify-css', 'zip']);
查看数组末尾列出的zip
任务。
最后,zip
任务定义为:
gulp.task('zip', function () {
var packageName = 'whatever';
var dateString = now.getFullYear()+('0'+(parseInt(now.getMonth())+1)).substr(-2)+('0'+now.getDate()).substr(-2);
var timeString = ('0'+now.getHours()).substr(-2)+('0'+now.getMinutes()).substr(-2)+('0'+now.getSeconds()).substr(-2);
gulp.src('target/dist/**')
.pipe(zip(packageName+'-'+dateString+'.'+timeString+'.zip'))
.pipe(gulp.dest('target'));
return;
});
任何帮助[指明方向]将不胜感激。
答案 0 :(得分:1)
又吸取了一个教训!
Gulp,默认为runs as much as possible the tasks in asynchronous fashion - 除非您已采取适当的措施强制它以顺序方式运行任务。
说到这里,zip
任务确实被执行了 - 但是它比我预期的更早执行 - 因此我[错误地]假设它根本没有运行。
因此,我没有将'zip'任务添加为'build'任务所依赖的任务,而是将'zip'任务设置为依赖于'build'任务,并运行'default'任务'zip'任务:
gulp.task('zip', function () {
var packageName = 'whatever';
var dateString = now.getFullYear()+...
var timeString = ('0'+now.getHours()).substr(-2)+...
gulp.src('target/dist/**')
.pipe(zip(packageName+'-'+dateString+'.'+timeString+'.zip'))
.pipe(gulp.dest('target'));
return;
});
gulp.task('build', ['html', 'images', 'fonts', 'misc', 'i18n', 'swagger', 'minify-js', 'minify-css']);
gulp.task('default', ['clean'], function () {
//gulp.start('build');
gulp.start('zip');
});
完成这些更改后,构建开始按预期工作:
$ gulp
[17:04:59] Using gulpfile ~/Work/ij-wksp/smiles-password-form-Q1_2017/gulpfile.js
[17:04:59] Starting 'clean'...
[17:04:59] Finished 'clean' after 45 ms
[17:04:59] Starting 'default'...
[17:04:59] Starting 'wiredep'...
[17:04:59] Starting 'injector:css'...
[17:04:59] Starting 'scripts'...
[17:05:00] Starting 'version'...
[17:05:00] Starting 'consolidate:jade:app'...
[17:05:00] Starting 'consolidate:jade:scripts'...
...
[17:05:01] Finished 'html' after 233 ms
[17:05:01] Starting 'build'...
[17:05:01] Finished 'build' after 3.71 μs
[17:05:01] Starting 'zip'...
[17:05:01] Finished 'zip' after 1.95 ms
$