2015-12-21 73 views
0

我有一个Grunt文件,它没有使用gulpif和lazypipes,但是我想要做的是创建一个任务,它将在我的index.html页面中使用useref来获取脚本文件。然后gulpif JS lint,uglify/concatenate,和notify。我得到一个“错误:无效的调用lazypipe()..”和我在看这篇文章https://github.com/OverZealous/lazypipe/issues/19,但我有点绿色,不明白错误/如何解决它“pipe(foo)vs.管(FOO())”。 如果有人能告诉我我如何使用lazypipe错误=我应该很好。如何与gulp-if和lazypipe一起使用多个管道?

grunt文件比较大,我使用的是gulpif bc css,一旦这个工作就会使用。如果有更好的方式让我知道,谢谢。

插件使用:

var gulp  = require('gulp'), 
jshint   = require('gulp-jshint'), 
notify   = require('gulp-notify'), 
gulpif   = require('gulp-if'), 
lazypipe  = require('lazypipe'), 
useref   = require('gulp-useref'); 
uglify   = require('gulp-uglify'); 

var anyJS  = '/**/*.js', 
    distFolder = 'dist'; 

//Lazy Tasks 
    var jsTask = lazypipe() 
     .pipe(jshint) 
     .pipe(jshint.reporter('jshint-stylish')) 
     .pipe(notify('JS Linting finished')) 
     .pipe(uglify()) 
     .pipe(notify('JS Compressing finished')); 


//Tasks 
    gulp.task('mini', function() { 
     return gulp.src('./index.html') 
      .pipe(useref()) 
      .pipe(gulpif(anyJS, jsTask())) 
      .pipe(gulp.dest(distFolder)); 
    }); 

回答

1

所以,我终于想通了,什么是错的。 LazyPipe中的所有函数调用都不能使用()!所以如果你有lazypipe()。pipe(jshint).pipe(uglify())。它不会工作 - 你需要删除uglify上的()。

我想我会再次尝试LP和GF,但这里它是与gulpFilter或至少90%的工作。通知未显示。

gulp.task('mini', function() { 
    var jsFilter = gulpFilter(jsInput, {restore: true}); 
    var cssFilter = gulpFilter(cssInput, {restore: true}); 

    return gulp.src('./index.html') 
     .pipe(plumber({ 
      handleError: function (err) { 
       console.log(err); 
       this.emit('end'); 
      } 
     })) 
     .pipe(useref()) 
     .pipe(jsFilter) 
     .pipe(jshint()) 
     .pipe(jshint.reporter('jshint-stylish')) 
     .pipe(uglify()) 
     .pipe(notify('JS task finished')) 
     .pipe(jsFilter.restore) 
     .pipe(cssFilter) 
     .pipe(sass()) 
     .pipe(autoPrefixer('last 2 versions')) 
     .pipe(cssComb()) 
     .pipe(mmq({ 
      log: true 
     })) 
     .pipe(minifyCss()) 
     .pipe(notify('CSS task finished')) 
     .pipe(cssFilter.restore) 

     .pipe(gulp.dest(distFolder)); 
}); 
相关问题