javascript - gulp执行命令是的错误
高洛峰
高洛峰 2017-04-11 09:08:59
[JavaScript讨论组]
[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' }));
});

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

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(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文件?

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号