0

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 it Commented Apr 16, 2015 at 10:47

1 Answer 1

3

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'
Sign up to request clarification or add additional context in comments.

3 Comments

My problem is not the source, the problem is the destination file, please read the question again!
If you don't include the old .min.js file in your src, it won't be concatinated or included in the other operations. So I fail to see how this doesn't solve your problem.
@cheziHoyzer your problem is indeed the source glob.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.