简体   繁体   English

如何在gulp任务中仅排除.min.js文件,同时保留在同一目录中?

[英]How do I exclude only .min.js files in gulp task, while staying in same directory?

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. 这是我的js处理的问题,因为我不确定如何仅排除后缀为.min的文件。

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. 尽管我发现它仍然以.min.js文件为目标,因为它们也被视为.js文件。 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. 我已经弄乱了这些通配符的几种不同配置,但是我一直以创建example.min.js example.min.min.js依次创建example.min.js example.min.min.js example.min.min.min.js等。

So, how can I just process files that do not include the .min prefix? 因此,如何处理不包含.min前缀的文件?

您可以使用否定模式排除.min.js文件。

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

如果您只想使用一个字符串来执行此操作,则可以使用:

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

In your gulp command. 在您的gulp命令中。

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. 在这种condition您可以指定目录。 ../ to go backward, /dir to go forwards ../后退, /dir前进

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

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