在单个gulp链中组合多个来源

时间:2014-07-04 01:10:23

标签: javascript gulp

如何在单个gulp 管道链中组合多个来源?例如,我有:

gulp.task('compressJS', function () {
    gulp.src('client/js/source/**/*.js')
        .pipe(concat('app'))
        .pipe(ngmin())
        .pipe(uglify())
        .pipe(rev())
        .pipe(rename({
            extname: ".min.js"
         }))
        .pipe(gulp.dest('client/js'))
        .pipe(rev.manifest())
        .pipe(gulp.dest('client/js'))
        .pipe(gulp.src('client/views/index.html'))
        .pipe(replace(/app\-[a-fA-F0-9]\.min\.js/, 'app-prod.min.js'))
        .pipe(gulp.dest('client/build'))
        .pipe(gulp.src('client/js/rev-manifest.json', {
             read: false
         }))
        .pipe(rimaf());
});

获取错误:

stream.js:94
      throw er; // Unhandled stream error in pipe.

1 个答案:

答案 0 :(得分:2)

我看到的这个问题的最常见解决方案是利用gulp-filter。我们的想法是,您的gulp.src更广泛,但您的过滤器可让您处理更具体的子集。

例如,使用您的代码:

   gulpFilter = require('gulp-filter');

   gulp.task('compressJS', function () {

       jsFilter = gulpFilter('client/js/source/**/*.js');
       clientFilter = gulpFilter('client/views/index.html');

       gulp.src('client/**/*')
           .pipe(jsFilter)
           .pipe(concat('app'))
           .pipe(ngmin())
           .pipe(uglify())
           .pipe(rev())
           .pipe(rename({
               extname: ".min.js"
           }))
           .pipe(gulp.dest('client/js'))
           .pipe(rev.manifest())
           .pipe(gulp.dest('client/js'))
           .pipe(jsFilter.restore())
           .pipe(clientFilter)
           .pipe(gulp.src('client/views/index.html'))
           .pipe(replace(/app\-[a-fA-F0-9]\.min\.js/, 'app-prod.min.js'))
           .pipe(gulp.dest('client/build'))
           .pipe(gulp.src('client/js/rev-manifest.json', {
               read: false
           }))
           .pipe(clientFilter.restore())
           .pipe(rimaf());
    });