2015-12-21 72 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)); 
}); 
相關問題