我有一个无需使用 gulpif 和lazypipes 即可工作的 Grunt 文件,但我想要做的是创建一个任务,该任务将使用 useref
接收我的 index.html 页面中的脚本文件。然后是 gulpif
JS lint
、uglify
/concatenate 和 notify
。我收到“错误:对懒惰管道()的调用无效..”,我正在查看这篇文章 https://github.com/OverZealous/lazypipe/issues/19 ,但我有点绿,不明白错误/如何修复它“pipe(foo) vs. pipeline(foo())”。 如果有人能告诉我如何错误地使用懒惰管道=我应该很好。
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));
});
最佳答案
所以我终于弄清楚出了什么问题。 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));
});
关于javascript - 如何通过 gulp-if 和懒惰管道使用多个管道?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34404550/