我有一个clean
任务,我想在运行构建任务之前完成。
无论我尝试了什么,我都无法正常工作:clean
启动,build tasks
启动,clean
完成(并因为编写某个文件夹而抛出错误),同时构建任务还在运行。
以下是我的一些任务定义:
gulp.task('default', ['clean', 'build']);
gulp.task('js', ['phnxjs', 'vendorsjs']);
gulp.task('css', ['phnxcss', 'vendorscss']);
gulp.task('assets', ['fonts', 'images', 'templates']);
gulp.task('build', ['js', 'css', 'assets', 'login']);
gulp.task('index', ['build'], index); <-- index is a function defined elsewhere
gulp.task('clean', function() {
return gulp.src('**/*', targetOptions)
.pipe(filters.excludeWebInf)
.pipe(g.rimraf());
});
所有我的任务返回一个流
我还尝试从callback function
任务调用clean
而不是返回流,但无济于事。
我甚至尝试了run-sequence
,如下:
gulp.task('default', function() {
run('clean', 'build', 'index');
});
它似乎会产生更好的效果,但看起来因为index
未执行而错过了一步
编辑:尝试了大量的“任务依赖”组合,其中我尝试了task('build', ['clean', 'js' ...]
仍然无法使用该方案:
[13:46:32] Starting 'clean'...
[13:46:32] Starting 'phnxjs'... <-------- Clean not finished, other tasks started
[13:46:33] Starting 'vendorsjs'...
[13:46:33] Starting 'phnxcss'...
[13:46:33] Starting 'vendorscss'...
[13:46:33] Starting 'fonts'...
[13:46:33] Starting 'images'...
[13:46:33] Starting 'templates'...
[13:46:33] Starting 'login'...
[13:46:33] Starting 'index'...
[13:46:34] Finished 'vendorscss' after 1.2 s
[13:46:34] Finished 'login' after 1.1 s
[13:46:34] Finished 'index' after 1.09 s
[13:46:35] Finished 'fonts' after 2.7 s
[13:46:35] Finished 'images' after 2.7 s
[13:46:35] 'clean' errored after 3.1 s <--------- Clean Error
[13:46:35] Error in plugin 'gulp-rimraf'
ENOTEMPTY, rmdir '/Users/oclement/Documents/phoenix/MedifastCerBrokenDown/MedifastWeb/build/WebContent/app/generated'
[13:46:35] Finished 'templates' after 2.72 s
[13:46:36] Finished 'phnxcss' after 3.46 s
答案 0 :(得分:0)
build
需要clean
作为依赖。
// -----------------v
gulp.task('build', ['clean', 'js', 'css', 'assets', 'login']);
答案 1 :(得分:0)
您可以使用以下代码...
gulp.task( 'task1', () => console.log(a) )
gulp.task( 'task2', () => console.log(a) )
gulp.task( 'task3', () => console.log(a) )
gulp.task( 'task4', () => console.log(a) )
gulp.task( 'task5', () => console.log(a) )
function runSequential( tasks ) {
if( !tasks || tasks.length <= 0 ) return;
const task = tasks[0];
gulp.start( task, () => {
console.log( `${task} finished` );
runSequential( tasks.slice(1) );
} );
}
gulp.task( "run-all", () => runSequential([ "task1", "task2", "task3", "task4", "task5" ));