I am trying to write a minify function that can be used for minifiy html, css and js depending on the type of file. I would like to use existing gulp plugins for these 3 minimization processes to perform the actual minimization. The problem I am facing is that I don’t know what to name the plugin on one vinyl file. Here is what I still have:
var cssmin = require('gulp-cssmin');
var htmlmin = require('gulp-minify-html');
var uglify = require('gulp-uglify');
var minifiers = {
js: uglify,
css: cssmin,
html: htmlmin
};
function minify(options) {
var options = options || {};
return tap(function(file){
var fileType = file.path.split('.').pop();
options = options[fileType] || options
var minifier = minifiers[fileType];
if(!minifier)
console.error("No minifier for " + fileType + " - " + file.path);
file.pipe(minifier(options));
});
}
I would like to be able to call the minify function as follows:
gulp.src(['test.html', 'test.css', 'test.js'])
.pipe(minify());
Dusty source
share