gulp执行命令是的错误

[13:47:26] Using gulpfile D:\gulpstudyone
[13:47:26] Starting 'scripts'...
ERROR: Can't find config file: .jshintrc

(Can't find config file: .jshintrc)这句找不到.jshintrc,是什么原因呢,下面是我的配置文件:
gulp.task('scripts', function() {
  return gulp.src('src/js/*.js')
    .pipe(jshint('.jshintrc'))
    .pipe(jshint.reporter('default'))
    .pipe(concat('main.js'))
    .pipe(gulp.dest('dist/scripts'))
    .pipe(rename({ suffix: '.min' }))
    .pipe(uglify())
    .pipe(gulp.dest('dist/scripts'))
    .pipe(notify({ message: 'Scripts task complete' }));
});

这个怎么解决,还请高手指点:

阅读 3.4k
2 个回答

这个提示是因为在jshint中指明要调用.jshintrc,这样就需要创建一个.jshintrc的文件,并填入所指定的配置项。使用gulp的jshint可以直接配置或者留空调用默认配置,如:

gulp.task('scripts', function() {
  return gulp.src('src/js/*.js')
    .pipe(jshint())
    .pipe(concat('main.js'))
    .pipe(gulp.dest('dist/scripts'))
    .pipe(rename({ suffix: '.min' }))
    .pipe(uglify())
    .pipe(gulp.dest('dist/scripts'))
    .pipe(notify({ message: 'Scripts task complete' }));
});

或者参考jshint官方例子配置, 例如:

gulp.task('scripts', function() {
  return gulp.src('src/js/*.js')
    .pipe(jshint({
        'undef': true,
        'unused': true
    }))
    .pipe(concat('main.js'))
    .pipe(gulp.dest('dist/scripts'))
    .pipe(rename({ suffix: '.min' }))
    .pipe(uglify())
    .pipe(gulp.dest('dist/scripts'))
    .pipe(notify({ message: 'Scripts task complete' }));
});

感觉不是gulp的问题,是配置jshint的问题。 读取不到.jshintrc 配置文件 看 jshint的配置 http://jshint.com/docs/

JSHint comes with a default set of warnings but it was designed to be very configurable. There are three main ways to configure your copy of JSHint: you can either specify the configuration file manually via the --config flag, use a special file .jshintrc or put your config into your projects package.json file under the jshintConfig property. In case of .jshintrc, JSHint will start looking for this file in the same directory as the file that's being linted. If not found, it will move one level up the directory tree all the way up to the filesystem root. (Note that if the input comes from stdin, JSHint doesn't attempt to find a configuration file)

是不是你项目没有配置.jshintrc文件?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题