Reputation: 137
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"));
});
Upvotes: 6
Views: 4046
Reputation: 516
Use gulp-uglify
instead - it doesn't rename files, which is the default behavior for most gulp plugins.
var gulp = require('gulp');
var uglify = require('gulp-uglify');
gulp.task("js-external-release", function() {
gulp.src(config.vendorJs)
.pipe(uglify())
.pipe(gulp.dest(config.dist + "/scripts"));
});
Alternatively, you could use gulp-rename
, but switching to uglify
will eliminate the need for such a plugin and is less complex than adding a new plugin in my opinion.
Upvotes: 1
Reputation: 920
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'));
});
Upvotes: 15