File Minification in Gulp
Let's now learn how to apply operations to a set of files. First, we will minimize CSS files. This is done using the gulp-clean-css plugin.
First, this plugin must be installed in our project:
npm install gulp-clean-css --save-dev
After that, import the installed plugin:
let {src, dest} = require('gulp');
let cleanCSS = require('gulp-clean-css');
Use it for some file:
function task(cb) {
return src('src/styles.css')
.pipe(cleanCSS())
.pipe(dest('dist'));
}
Use our plugin for a group of files:
function task(cb) {
return src('src/*.css')
.pipe(cleanCSS())
.pipe(dest('dist'));
}
Using the gulp-uglify plugin, minimize a group of JavaScript files.