以下是我gulpfile.js
的相关部分:
var paths = {
sass: ['./www/**/*.scss'],
scripts: ['./www/**/*.js', '!./www/lib/**/*.js']
};
gulp.task('jshint', function(done) {
console.log('Running jshint');
gulp.src(paths.scripts)
.pipe(jshint())
.pipe(jshint.reporter('default'))
.on('end', done);
});
gulp.task('scripts', function(done) {
console.log('Running scripts');
gulp.src(paths.scripts)
.pipe(concat('chessmate.js'))
.pipe(gulp.dest('./www/'))
.on('end', done);
});
gulp.task('sass', function(done) {
gulp.src('./www/ionic.app.scss')
.pipe(sass({
errLogToConsole: true,
includePaths: []
}))
.pipe(concat('chessmate.css'))
.pipe(gulp.dest('./www/'))
.on('end', done);
});
gulp.task('watch', function() {
gulp.watch(paths.sass, ['sass']);
gulp.watch(paths.scripts, ['jshint', 'scripts']);
});
gulp.task('default', ['jshint', 'scripts', 'sass', 'watch']);
当我运行gulp
时,jshint
和scripts
都会运行:
[gulp] Using gulpfile /Users/mishamoroshko/ChessMate/gulpfile.js
[gulp] Starting 'jshint'...
Running jshint
[gulp] Starting 'scripts'...
Running scripts
[gulp] Starting 'sass'...
[gulp] Starting 'watch'...
[gulp] Finished 'watch' after 93 ms
但是,如果我更新app.js
,则只会运行scripts
:
[gulp] Starting 'scripts'...
Running scripts
[gulp] Finished 'scripts' after 396 ms
为什么jshint
无法运行?
答案 0 :(得分:2)
显然,改变这种风格:
gulp.task('taskname', function(done) {
[do stuff].on('end', done);
});
到这一个:
gulp.task('taskname', function() {
return [do stuff];
});
解决了这个问题。
答案 1 :(得分:0)
它似乎应该自动运行给我,但由于它不是,你可以尝试的一件事是添加jshint
任务作为scripts
任务的依赖项,如下所示:
gulp.task('scripts', ['jshint'], function(done) {
console.log('Running scripts');
gulp.src(paths.scripts)
.pipe(concat('chessmate.js'))
.pipe(gulp.dest('./www/'))
.on('end', done);
});
希望有所帮助。如果这对您有用,您还应该能够从jshint
任务中删除watch
:
gulp.task('watch', function() {
gulp.watch(paths.sass, ['sass']);
gulp.watch(paths.scripts, [ /*'jshint',*/ 'scripts']);
});