1. ホーム
  2. javascript

[解決済み] gulp.runは非推奨です。タスクの構成はどうすればいいですか?

2022-12-12 12:10:01

質問

構成されたタスクがありますが、タスクの依存関係で置き換える方法がわかりません。

...
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の非推奨]。

どのように解決するのですか?

gulp.task('watch', function () {
  var server = ['jasmine', 'embed'];
  var client = ['scripts', 'styles', 'copy', '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', ['copygeojson']);
});

タスクを実行するために関数を渡す必要はもうありません(渡すことはできますが)。watchにタスク名の配列を渡せば、それを実行してくれます。