简体   繁体   English

gulp-jshint指定应该通过jshint()并忽略其他文件的文件

[英]gulp-jshint specify files which should go through jshint() and ignore other files

I have situation where i'm building minified script through gulp, from scripts that are either vendor scripts or my scripts, something like: 我有这样的情况,我正在通过gulp构建缩小的脚本,从脚本是供应商脚本或我的脚本,如:

var paths = {
    public      : './public/javascripts',
    api         : './public/API',
    vendor      : './public/vendor',
    destination : './dist'
};

gulp.task('scripts-out', function() {
    gulp.src([
        paths.public + '/a.js',
        paths.public + '/b.js',
        paths.public + '/c.js',
        paths.public + '/d.js',
        paths.api    + '/e.js',
        paths.public + '/f.js'
    ])
    .pipe(jshint())
    .pipe(jshint.reporter('default'))
    .pipe(concat('out.js'))
    .pipe(gulp.dest(paths.destination + '/javascripts'));
});

Only e.js is not vendor script and only that script should go through jshint(), from official documentation of the plugin i can't see solution for this. 只有e.js不是供应商脚本,只有那个脚本应该通过jshint(),从插件的官方文档我看不到解决方案。

I tried passing config object to jshint(), something like: 我尝试将config对象传递给jshint(),类似于:

pipe(jshint({
    files: paths.api     + '/e.js'
}))

That was just speculation which don't work. 这只是猜测不起作用。 Side question of this how to force jshint to write results to some file instead of console? 这方面的问题是如何强制jshint将结果写入某个文件而不是控制台?

EDIT: FIND SOLUTION I find the way through the .jshintignore file, which should be in the root of the project, for example if you want to ignore all from the vendor folder you can just add one line to .jshintignore file: public/src/vendor/* 编辑:查找解决方案我找到了通过.jshintignore文件的方法,该文件应位于项目的根目录中,例如,如果要忽略vendor文件夹中的所有文件,只需在.jshintignore文件中添加一行: public/src/vendor/*

You could use gulp-filter to filter which files get passed to jshint : 您可以使用gulp-filter来过滤哪些文件传递给jshint

var gulpFilter = require('gulp-filter');
var filter = gulpFilter([paths.public + '/e.js']);

gulp.task('scripts-out', function() {
    return gulp.src([
        paths.public + '/a.js',
        paths.public + '/b.js',
        paths.public + '/c.js',
        paths.public + '/d.js',
        paths.api    + '/e.js',
        paths.public + '/f.js'
    ])
    .pipe(filter)
    .pipe(jshint())
    .pipe(jshint.reporter('default'))
    .pipe(filter.restore())
    .pipe(concat('out.js'))
    .pipe(gulp.dest(paths.destination + '/javascripts'));
});

New version(3.0.1) has interface updates: 新版本(3.0.1)具有接口更新:

 // you should pass {restore: true} for restore ability
 var filter = gulpFilter([paths.public + '/e.js'], {restore: true});
 ...
 // filter.restore is now object, not a method
 .pipe(filter.restore)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM