我的gulpfile中有以下(简化)设置:
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var watch = require('gulp-watch');
var paths = {
scripts: ['js/*.js']
}
var jscsRunner = jscs({
disallowMixedSpacesAndTabs: true // etc
});
var jshintRunner = jshint({
browser: true // etc
});
// this outputs messages from jshint no problem
gulp.task('jshint', function() {
return gulp.src(paths.scripts)
.pipe(jshintRunner)
.pipe(jshint.reporter('default'));
});
// this outputs messages from jscs no problem
gulp.task('jscs', function() {
return gulp.src(paths.scripts)
.pipe(jscsRunner);
});
// this only outputs messages from jshint
gulp.task('watch', function() {
return watch(paths.scripts)
.pipe(jscsRunner)
.pipe(jshintRunner)
.pipe(jshint.reporter('default'));
});
我的问题是 - 如所示 - 在watch
任务中没有从jscs
生成输出,即使管道与jscs
任务中的管道基本完全相同,其中它按预期工作。
(我在Windows上运行它。)
编辑:此问题已在此处转载和讨论:https://github.com/jscs-dev/gulp-jscs/pull/66
答案 0 :(得分:0)
我能够拿走你的脚本,清理一下,重构一些代码,然后我就可以让它在我的机器上工作了:
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var paths = {
scripts: ['js/*.js']
}
// this outputs messages from jshint no problem
gulp.task('jshint', function() {
return gulp.src(paths.scripts)
.pipe(jshint({browser: true}))
.pipe(jshint.reporter('default'));
});
// this outputs messages from jscs no problem
gulp.task('jscs', function() {
return gulp.src(paths.scripts)
.pipe(jscs({ disallowMixedSpacesAndTabs: true }));
});
// this only outputs messages from jshint
gulp.task('watch', function() {
return gulp.watch(paths.scripts,['jscs','jshint']);
});
有几点需要注意: