Skipping Tasks Listed as Dependencies in Gulp

a 夏天 提交于 2019-12-10 16:33:56

问题


I have looked all over the documentation and NPM to try to find a solution to this, but I have had no luck. I would like to have the option to skip the tasks that I list as dependencies when running a specific task. For example, if I have the following:

gulp.task('prerun', function(){
  // do cleaning, installation, etc.
});

gulp.task('run', ['prerun'], function(){
  // do stuff
});

gulp.task('watch', function(){
  gulp.watch('glob/glob/**', ['run']);
});

I would like to be able to have my gulp.watch execute run without having to touch the overhead involved in prerun. Is this at all possible in Gulp?


回答1:


What's about a helper task? I use this approach to eliminate any dependencies in my watch tasks. Your example can look like this:

gulp.task('prerun', function(){
    // do cleaning, installation, etc.
});

gulp.task('run', ['prerun'], function(){
    gulp.start('run-dev');
});

gulp.task('run-dev', function() {
    // do the run stuff
});

gulp.task('watch', function(){
    gulp.watch('glob/glob/**', ['run-dev']);
});

The prerun task you can also use as dependency for your watch task if needed:

gulp.task('watch', ['prerun'], function(){
    gulp.watch('glob/glob/**', ['run-dev']);
});

Ciao Ralf




回答2:


Without using gulp.start, you can try this:

gulp.task('prerun', function(){
    // do cleaning, installation, etc.
});

// run all dependencies while keeping run-dev as a separate task
gulp.task('run', ['prerun', 'run-dev']);

gulp.task('run-dev', function() {
    // do the run stuff
});

gulp.task('watch', ['run'], function(){
    gulp.watch('glob/glob/**', ['run-dev']);
});


来源:https://stackoverflow.com/questions/25374533/skipping-tasks-listed-as-dependencies-in-gulp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!