I've a variable like
var files = {
'foo.css': 'foo.min.css',
'bar.css': 'bar.min.css',
};
What I want the gulp to do for me is to minify
the files and then rename
for me.
But the tasks is currently written as (for one file)
gulp.task('minify', function () {
gulp.src('foo.css')
.pipe(minify({keepBreaks: true}))
.pipe(concat('foo.min.css'))
.pipe(gulp.dest('./'))
});
How to rewrite so it work with my variable files
defined above?
I tried the earlier answers, but I got a never ending loop because I wasn't ignoring the files that were already minified.
First use this code which is similar to other answers:
Notice the
'!css/build/*.min.css'
in the src (i.e. var cssMinifyLocation)You have to ignore minified files in both the watch and the task.
This is what I have done
Then
end result is unique timestamp added
Example in index.html
You should be able to select any files you need for your src with a Glob rather than defining them in an object, which should simplify your task. Also, if you want the css files minified into separate files you shouldn't need to concat them.