How to add src files in the middle of a pipe

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 19:08:59

You don't need to add files to the original src, but rather to use coffee only "if"...

So, use gulp-if

gulp.task('task', function() {
  gulp.src('./stuff/*')
    .pipe(gulpif(/[.]coffee$/, coffee()))
    .pipe(gulp.dest('./dist/'));
});

See here more about gulp-if.

@Contra 's answer doesn't work for me. New stream replaced the old one, not joined them.

You should combine streams in this way:

es = require("event-stream")

es.concat(
  gulp.src('*.coffee')
  .pipe(coffee()),
  gulp.src('*.js')
).pipe(concat('all.js'))
.pipe(gulp.dest('.'))

And you can see official guide about this here Using multiple sources in one task

If you care about the order inside the stream, you should use streamqueue instead of event-stream

You can use the gulp-add-src plugin:

addsrc = require 'gulp-add-src'

gulp.task 'build-js', ->
  gulp.src(['src/coffee/*.coffee'])
    .pipe(coffee()).on('error', gutil.log)
    .pipe(addsrc(['src/js/somefile.js', 'src/js/otherfile.js']))
    .pipe(concat('app.js'))
    .pipe(gulp.dest('public/js'))

gulp.src streams are passthroughs so you can add them at any point in the pipeline

gulp.task 'build-js', ->
  gulp.src([
      "src/js/config/app.coffee"
      "src/js/config/app-db.coffee"              
      "src/js/accounts/accounts.coffee"
      "src/js/budget_items/budget_items.coffee"
      "src/js/line_items/line_items.coffee"
      "src/js/misc/misc.coffee"
      "src/js/reports/report_generators.coffee"
      "src/js/reports/reports.coffee"
  ])
  .pipe(coffee()).on('error', gutil.log)
  .pipe(gulp.src([
      "bower_components/mbdev-core/dist/js/db.js"
      "bower_components/mbdev-core/dist/js/utils.js"
  ]))
  .pipe(concat('app.js'))
  .pipe(gulp.dest('public/js'))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!