64

The js file being compressed is output with the same filename.

gulp.task('compressjs', function () {
  gulp.src('app/**/*.js')
    .pipe(uglify())
    .pipe(gulp.dest('dist'));
});

How can I have it output the file with min.js at the back?

1 Answer 1

130

You can use the suffix or extname parameters of gulp-rename like:

gulp.task('compressjs', function () {
  gulp.src('app/**/*.js')
    .pipe(uglify())
    .pipe(rename({ suffix: '.min' }))
    .pipe(gulp.dest('dist'))
})
Sign up to request clarification or add additional context in comments.

7 Comments

How would you update the html script tags to reflect the name change? I would like a gulp build that minified javascript files for production but not for development builds.
another (cleaner) way to do it is .pipe(rename({ suffix: '.min' }))
@intellion You're right, mind if I change it in the answer?
@Aperçu absolutely not :)
It's terrible that gulp-clean-css and gulp-uglify don't do this automagically. But this solution worked like charm. Thanks.
|

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.