1
votes

I'm searching for Gulp task that can take multiple javascript files into a single javascript file and compress to one file, like grunt-contrib-uglify.

This what I tried to do so for to simulate grunt-contrib-uglify:

gulp.task('compressJS', function ()
{
    return gulp.src(SomeJSArrayWithALotOfFiles)
        .pipe(concat('application.js'))
        .pipe(rename({suffix: '.min'}))
        .pipe(uglify())
        .pipe(gulp.dest('../application'))
}

My problem with this solution:
I need manually delete the file (application.js.min) before I run the task, otherwise every task execution the new files concatenate to old compressed file (because this line: .pipe(concat('application.js'))).

1
Why the unvote? this is a very good question and I did a big search before I asked itcheziHoyzer

1 Answers

3
votes

In your SomeJSArrayWithALotOfFiles, exclude all files that end with .min.js.

As array, including all .js, but excluding .min.js files:

[ '**/*.js', '!**/*.min.js' ]

Or as single string, including all .js files not ending in .min.js:

'**/*!(.min).js'