与所有的文件做任务,一饮而尽后运行code [英] Run code after gulp task done with all files
问题描述
所以,我一直在尝试咕嘟咕嘟来看看它是如何比较至于速度呻吟,我是pretty IM pressed的结果,但我有一件事我不知道该怎么办中咕嘟咕嘟。
So I have been trying out Gulp to see how it compares to Grunt as far as speed and I am pretty impressed with the results but I have one thing I don't know how to do in Gulp.
所以我有这样的任务,一饮而尽,以压缩HTML:
So I have this gulp task to minify HTML:
gulp.task('html-minify', function() {
var files = [
relativePaths.webPath + '/*.html',
relativePaths.webPath + '/components/**/*.html',
relativePaths.webPath + '/' + relativePaths.appPath + '/components/**/*.html'
];
var changedFiles = buildMetaData.getChangedFiles(files);
//TODO: needs to execute only after successful run of the task
buildMetaData.addBuildMetaDataFiles(changedFiles);
buildMetaData.writeFile();
return gulp.src(changedFiles, {
base: relativePaths.webPath
})
.pipe(filelog())
.pipe(minifyHtml({
empty: true,
quotes: true,
conditionals: true,
comments: true
}))
.pipe(gulp.dest(relativePaths.webPath + '/' + relativePaths.appPath + '/' + relativePaths.buildPath));
});
该buildMetaData对象,我需要定制的功能,为什么我不能使用像一饮而尽改变的插件。我试图弄清楚是怎么(如果可能)缩小完成后过程中的所有文件,并运行成功运行code块。是像这可能与一饮而尽?
The buildMetaData object has custom functionality that I need and why I can't use plugins like gulp-changed. What I am trying to figure out is how (if possible) to run a block of code after the minify is done process all files and it run successfully. Is something like this possible with gulp?
推荐答案
您可以只让这取决于任务 HTML-缩小
:
You could just make a task which depends on html-minify
:
gulp.task('other-task', ['html-minify'], function() {
//stuff
});
您还可以收听流结束
的 HTML-缩小
任务内部事件:
You could also listen for the stream end
event inside the html-minify
task:
gulp.task('html-minify', function(done) {
var files = [
relativePaths.webPath + '/*.html',
relativePaths.webPath + '/components/**/*.html',
relativePaths.webPath + '/' + relativePaths.appPath + '/components/**/*.html'
];
var changedFiles = buildMetaData.getChangedFiles(files);
//TODO: needs to execute only after successful run of the task
buildMetaData.addBuildMetaDataFiles(changedFiles);
buildMetaData.writeFile();
var stream = gulp.src(changedFiles, {
base: relativePaths.webPath
})
.pipe(filelog())
.pipe(minifyHtml({
empty: true,
quotes: true,
conditionals: true,
comments: true
}))
.pipe(gulp.dest(relativePaths.webPath + '/' + relativePaths.appPath + '/' + relativePaths.buildPath));
stream.on('end', function() {
//run some code here
done();
});
stream.on('error', function(err) {
done(err);
});
});
这篇关于与所有的文件做任务,一饮而尽后运行code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!