Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gulp-minify without rename original files

It is possible minify js files without add -min suffix?

I want keep original name.

gulp.task("js-external-release", function() {
    gulp.src(config.vendorJs)
        .pipe(minify())
        .pipe(gulp.dest(config.dist + "/scripts"));
});
like image 406
Ninja.Turtle Avatar asked Nov 23 '15 21:11

Ninja.Turtle


1 Answers

This is a very old question, but it still pops up quite high on Google, and since Uglify is no longer actively maintained for ES6+ and gulp-minify is, I thought I’d add that it is (now) perfectly possible to do this with gulp-minify.

If you specify the extension of minified files to be just .js (or whatever your input file extension is) in your gulp-minify options, the minified file will have the same file name as the original. The problem is that gulp-minify by default also compiles a non-minified copy of the input file to the output directory – and that non-minified copy gets added after the minified copy, thus overwriting it and leaving you with just a copy of the original.

To get around this, set the noSource option to true – then no copy of the input file is output:

gulp.task("js-external-release", function() {
    gulp.src(config.vendorJs)
    .pipe(minify({
        ext: {
            min: '.js' // Set the file extension for minified files to just .js
        },
        noSource: true // Don’t output a copy of the source file
    }))
    .pipe(gulp.dest(config.dist + '/scripts'));
});
like image 64
Janus Bahs Jacquet Avatar answered Oct 01 '22 02:10

Janus Bahs Jacquet