最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I exclude only .min.js files in gulp task, while staying in same directory? - Stack Overflow

programmeradmin0浏览0评论

I am trying to set up a build system for my front end work though I am running into a problem where it loops processing files over and over again. This is a problem with my js processing since I am not sure how to exclude just the files with .min as a suffix.

The task goes as follows

return gulp.src(["!dev/js/*.min.js", "dev/js/*.js"])
        .pipe(plumber())
        .pipe(browserify())
        .pipe(smaps.init())
            .pipe(uglyify({preserveComments: "license"}))
        .pipe(smaps.write())
        .pipe(rename({suffix: ".min"}))
        .pipe(gulp.dest(output_dir));

Though what I have found is that it still targets the .min.js files since they are also seen as .js files. I have messed around with a few different configurations of these wildcards but I keep ending up with the task looping creating example.min.js then example.min.min.js then example.min.min.min.js etc.

So, how can I just process files that do not include the .min prefix?

I am trying to set up a build system for my front end work though I am running into a problem where it loops processing files over and over again. This is a problem with my js processing since I am not sure how to exclude just the files with .min as a suffix.

The task goes as follows

return gulp.src(["!dev/js/*.min.js", "dev/js/*.js"])
        .pipe(plumber())
        .pipe(browserify())
        .pipe(smaps.init())
            .pipe(uglyify({preserveComments: "license"}))
        .pipe(smaps.write())
        .pipe(rename({suffix: ".min"}))
        .pipe(gulp.dest(output_dir));

Though what I have found is that it still targets the .min.js files since they are also seen as .js files. I have messed around with a few different configurations of these wildcards but I keep ending up with the task looping creating example.min.js then example.min.min.js then example.min.min.min.js etc.

So, how can I just process files that do not include the .min prefix?

Share Improve this question asked Oct 2, 2016 at 9:30 sparcutsparcut 8251 gold badge12 silver badges27 bronze badges 1
  • Try putting ./ at the beginning just to see – iSkore Commented Oct 2, 2016 at 13:59
Add a comment  | 

3 Answers 3

Reset to default 15

You can use negated patterns to exclude .min.js files.

gulp.src(['dev/js/*.js', '!dev/js/*.min.js'])

if you want to do it in only one string you can use:

gulp.src(["dev/js/!(*.min)*.js"])

In your gulp command.

const
    gulpIgnore = require( 'gulp-ignore' ),
    uglify = require( 'gulp-uglify' ),
    jshint = require( 'gulp-jshint' ),
    condition = './**/*.min.js';

gulp.task( 'task', function() {
    gulp.src( './**/*.js' )
        .pipe( jshint() )
        .pipe( gulpIgnore.exclude( condition ) )
        .pipe( uglify() )
        .pipe( gulp.dest( './dist/' ) );
} );

In the condition you specify your directory. ../ to go backward, /dir to go forwards

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论