5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gulpでpipeする処理を事前にまとめておく

5
Posted at

ぐぐってもみつかりにくかったのでメモしておく。

探したところthrough-pipesでできそうだった。

下記のような処理をかいたとする

gulp.src("src/*.txt")
    .pipe(hoge())
    .pipe(goro())
    .pipe(gulp.dest("dist"))
    

hoge()goro()の組み合わせはよくつかうので、mofu()として使えるように合成しておきたい。そして以下のように使いたい。

gulp.src("src/*.txt")
    .pipe(mofu())
    .pipe(gulp.dest("dist"))

どうするか。

var through = require('through-pipes');

func mofu() {
  return through(function(source) {
    source.pipe(hoge())
          .pipe(goro())
  });
}

としてmofuをつくっておけばつかえる。
いつか指定されるであろう、情報源 sourceがはいってきて、使えるという感じである。

gulpのプログインは単にTransform Streamのはずなので、gulpに限らずthrough-pipesは使えるはず。
もっと簡単に合成できてもいい気がする。

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?