Gulp 运行替代方案 [英] Gulp run alternative

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

问题描述

每次我运行 gulp 时,我都会看到这条消息 gulp.run() 已被弃用.改用任务依赖或 gulp.watch 任务触发.

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

示例代码:

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

如何避免将 gulp.run() 与 gulp-watch 一起使用?

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

推荐答案

你不应该使用 run.这是一种替代方法(解决您答案的那部分问题),但不是您需要做的:

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.
     });

如果您确实必须触发临时任务,但可以按字面意思使用 run...您可以将 .start 与任务名称一起使用,并附加到 task_stop 处理程序在任务完成时触发某些东西.这在为 gulp 任务编写测试时很好,但就是这样.

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.

但是在日常 gulp 使用中,这是一种反模式.

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.

基本上,如果 c 或 d 是监视任务,您将实现相同的目标,即在没有 .run

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 运行替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆