99

これは、タスクの依存関係に置き換える方法がわからない構成されたタスクです。

...
gulp.task('watch', function () {
 var server = function(){
  gulp.run('jasmine');
  gulp.run('embed');
 };
 var client = function(){
  gulp.run('scripts');
  gulp.run('styles');
  gulp.run('copy');
  gulp.run('lint');
 };
 gulp.watch('app/*.js', server);
 gulp.watch('spec/nodejs/*.js', server);
 gulp.watch('app/backend/*.js', server);
 gulp.watch('src/admin/*.js', client);
 gulp.watch('src/admin/*.css', client);
 gulp.watch('src/geojson-index.json', function(){
  gulp.run('copygeojson');
 });
});

対応する変更ログ https://github.com/gulpjs/gulp/blob/master/CHANGELOG.md#35 [gulp.run を非推奨]

4

10 に答える 10

85

または、次のようにすることもできます。

gulp.start('task1', 'task2');
于 2014-04-25T16:48:31.633 に答える
25

ソース: https://github.com/gulpjs/gulp/issues/755

gulp.start()公開 API になることも、使用されることも意図されていませんでした。そして、上記のコメントで述べたように、タスク管理は次のリリースで置き換えられます....そのため、機能しgulp.start()なくなります。

gulp 設計の真意は、通常の Javascript 関数を作成し、それらを呼び出すタスクのみを作成することです。

例:

function getJsFiles() {
    var sourcePaths = [
        './app/scripts/**/*.js',
        '!./app/scripts/**/*.spec.js',
        '!./app/scripts/app.js'
    ];

    var sources = gulp.src(sourcePaths, { read: false }).pipe(angularFilesort());

    return gulp.src('./app/index.html')
        .pipe(injector(sources, { ignorePath: 'app', addRootSlash: false }))
        .pipe(gulp.dest('./app'));
}  

gulp.task('js', function () {
    jsStream = getJsFiles();
});
于 2014-11-05T22:03:17.117 に答える
12

古い質問を復活させてすみません。受け入れられた回答は、時計を設定する前に実行中のタスクの問題に対処していません。次の回答では、廃止される gulp.start を使用しています。3番目の回答は、通常の関数を使用する必要があることを指摘していますが、例は奇妙に思えます。いくつか検索しましたが、簡単な例は見つかりませんでした。

これが私の解決策です。アイデアは、通常の js 関数を定義し、それらをタスクとして登録することです。その後、必要に応じて、またはウォッチ内から関数を直接呼び出すことができます。

var 
  gulp     = require('gulp'),
  concat   = require('gulp-concat'),
  markdown = require('gulp-showdown')
;
var scriptFiles   = [ 'ang/app.js' ];
var markdownFiles = [ 'content/articles/*.md'];

var watchTask = function() 
{
  buildTask();

  gulp.watch(scriptFiles,  ['scripts' ]);
  gulp.watch(markdownFiles,['markdown']);
};
gulp.task('watch',watchTask);

var buildTask = function()
{
  scriptsTask();
  markdownTask();
};
gulp.task('build',buildTask);

var markdownTask = function() 
{
  gulp.src(markdownFiles)
    .pipe(markdown())
    .pipe(gulp.dest('web/articles'));
};
gulp.task('markdown',markdownTask);

var scriptsTask = function() 
{
  gulp.src(scriptFiles)
    .pipe(concat('app.js'))
    .pipe(gulp.dest('web/js'));

  gulp.src(
    [
      'bower_components/angular/angular.min.js',
      'bower_components/angular-route/angular-route.min.js'
    ])
    .pipe(concat('vendor.js'))
    .pipe(gulp.dest('web/js'));

  gulp.src(
    [
      'bower_components/angular/angular.min.js.map',
      'bower_components/angular-route/angular-route.min.js.map'
    ])
    .pipe(gulp.dest('web/js'));
};
gulp.task('scripts', scriptsTask);

私はガクガクするのが初めてです。明らかなことを見落としている場合はお知らせください。

于 2015-03-27T16:14:14.120 に答える
7

ゴクゴク4

gulp.parallel('taskName1', 'taskName2')()
gulp.series('taskName1', 'taskName2')()

私はgulp4が好きです!

于 2017-03-20T16:23:04.563 に答える
5

@dman が言及しているgulp.startように、次のバージョンでは破棄されます。また、この問題の gulpで見ることができます。

@Pavel Evstigneev の回答のコメントで、@joemaller は、このシナリオでrun-sequenceを使用できると述べています。

ただし、run-sequence の作成者は次のように述べていることに注意してください。

これは、順次または並行してタスクの依存関係を定義することをサポートする gulp 4.0 がリリースされるまでの一時的な解決策であることを意図しています。

このソリューションはハックであり、gulp の将来の更新で機能しなくなる可能性があることに注意してください。

したがって、gulp 4.0 より前はrun-sequenceを使用でき、4.0 以降は gulp のみを使用できます。

于 2015-12-24T14:02:00.510 に答える
3

実行中のタスクの順序を維持する必要がある場合は、ここで説明するように依存関係を定義できます。依存関係からストリームを返すだけで済みます。

gulp.task('dependency', function () {
  return gulp.src('glob')
    .pipe(plumber())
    .pipe(otherPlugin())
    .pipe(gulp.dest('destination'));
});

それに依存するタスクを定義します。

gulp.task('depends', [ 'dependency' ], function () {
  // do work
});

そして時計からそれを使用します:

gulp.task('watch', function () {
  watch('glob', [ 'depends' ]);
});

これで、dependecy実行前にタスクが完了しdependsます (たとえば、「jasmine」タスクと「embed」タスクは依存関係になり、それらに依存する別のタスク「server」があるとします)。ハックは必要ありません。

于 2015-08-28T09:55:45.257 に答える
0

I still dont see how this actually solves the question at hand.

If i have 4 tasks with dependencies defined between them

A,B,C,D

where A depends on B, etc as defined by gulp.task('A',['B'],function A(){}); and then i defined a new task using gulp.watch running just the functions would duplicate the dependencies.

e.g given these tasks (each tasks function exposed via name):

function A(){}
gulp.task('A',['B'],A);

function A(){}
gulp.task('A',['B'],A);

function B(){}
gulp.task('B',['C'],B);

function C(){}
gulp.task('C',['D'],C);

function D(){}
gulp.task('D',[],D);

i can write 1)

gulp.task('WATCHER', ['A'], function(){
   ...
}

which would execute A->D but if e.g Step B fails it would never enter the task (think of compile or test error)

or i can write 2)

gulp.task('WATCHER', [], function(){
   gulp.watch(...,['A'])
}

which would not run A->D until something was changed first.

or i can write 3)

gulp.task('WATCHER', [], function(){
   D();
   C();
   B();
   A();
   gulp.watch(...,['A'])
}

which would cause duplication (and errors over time) of the dependency hierarchy.

PS: In case someone is wondering why i would want my watch task to execute if any of the dependent tasks fail that is usually because i use watch for live development. eg. i start my watch task to begin working on tests etc. and it can be that the initial code i start out with already has issues thus errors.

So i would hope that gulp run or some equivalent stays for some time

于 2016-03-15T14:27:36.997 に答える