I'm trying to do the following in Gulp: 1) Minify JS files from a specified folder to a folder called 'dist'. 2) Append '.min' to the minified filenames. 3) Provide a sourcemap to the minified files and place them in a folder called 'maps'.
I am using 'gulp-uglify', 'gulp-rename' and 'gulp-sourcemaps'.
Here is what I have:
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var sourcemaps = require('gulp-sourcemaps');
gulp.task('compress', function () {
gulp.src('src/*.js')
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('dist'));
});
Everything works as intended, except the map files also get '.min' appended to them. How do I restrict the renaming to only occur in the dist folder?
I did a little more digging and found a solution to this. I ended up breaking the single task into two different ones. Once the files are in the dist folder then I call the 'rename' task. I also used 'vinyl-paths' and 'del' to delete the renamed files. Here is what I have: