10

我有一个如下所示的对象数组。

var bundles = [
  {
    src: 'js/my-component/*.js',
    bundleName: 'my-component.js'
  },
  {
    src: 'js/my-other-component/*.js',
    bundleName: 'my-other-component.js'
  }
]

我希望 gulp 任务处理/连接数组中的每个条目,但它似乎不起作用。

gulp.task('bundlejs', function(){
    return bundles.forEach(function(obj){
      return gulp.src(obj.src)
      .pipe(concat(obj.bundleName))
      .pipe(gulp.dest('js/_bundles'))
    });
});
4

2 回答 2

12

您可能应该合并流并返回结果,以便任务在适当的时间完成:

var es = require('event-stream');

gulp.task('bundlejs', function () {
  return es.merge(bundles.map(function (obj) {
    return gulp.src(obj.src)
      .pipe(concat(obj.bundleName))
      .pipe(gulp.dest('js/_bundles'));
  }));
});
于 2015-08-19T04:37:35.790 回答
0

此解决方案确实有效,我的目录名称错误。多哈。

https://github.com/adamayres/gulp-filelog帮我找到了问题。

于 2015-08-17T23:54:26.490 回答