Gulp运行替代方案

Gulp运行替代方案

本文介绍了Gulp运行替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次运行gulp时,我都会看到这个消息

您不应该使用 run 。这是另一种选择(解决你的答案的一部分),但不是你需要做的:

  gulp 
.start('default')
.once('task_stop',function(){
//做其他的东西。
});

如果您确实必须开启临时任务,但可以从字面上使用运行...您可以使用 .start 与任务名称关联,并附加到 task_stop 处理程序以在任务完成时触发某些内容。这在编写测试吞咽任务时很好,但实际上它就是这样。然而,在日常使用中,这是一个反模式。



通常情况下,您可以构建更小的任务并将其合成。这是正确的方法。请参阅:

  var gulp = require('gulp'),
runSequence = require('run-sequence' );

函数a(){
// gulpstuff
}
函数b(){
// gulpstuff
}

函数d(回调函数){
runSequence('a','b',callback)
}

gulp
.task('a' ,a)//吞噬a - 运行
.task('b',b)// gulp b运行b
.task('c',['a','b']) // gulp c同时运行a和b
.task('d',d); // gulp d运行a,然后b。

基本上,如果c或d是一项监视任务,您可以实现同样的目标没有 .run


Everytime I run gulp, I see this message gulp.run() has been deprecated. Use task dependencies or gulp.watch task triggering instead.

Example code:

var watch = require('gulp-watch');
watch(['public/**/*.js','!public/**/*.min.js'],function(){
    gulp.run('compressjs');
    gulp.run('bs-reload');
});

How can I avoid using gulp.run() with gulp-watch?

解决方案

You shouldn't use run. Here is an alternative (to address that part of your answer), but not what you need to do:

gulp
    .start('default')
    .once('task_stop', function(){
        //do other stuff.
     });

If you really must fire an ad hoc task, but can literally use run...You can use .start with the task name, and also attach to the task_stop handler to fire something when the task is complete. This is nice when writing tests for gulp tasks, but that's really it.

however in day to day gulp usage, this is an antipattern.

Normally, you build smaller tasks and composite them. This is the right way. See this:

var gulp = require('gulp'),
    runSequence = require('run-sequence');

function a(){
  //gulpstuff
}
function b(){
  //gulpstuff
}

function d(callback){
  runSequence('a', 'b', callback)
}

gulp
    .task('a', a) // gulp a -runs a
    .task('b', b) // gulp b runs b
    .task('c', ['a', 'b']) //gulp c runs a and b at the same time
    .task('d', d); //gulp d runs a, then b.

basically if c or d was a watch task, you'd achieve the same goal of firing the already registered smaller gulp tasks without .run

这篇关于Gulp运行替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 06:51