压缩

压缩 html css js

'use strict';
let { series, src, dest } = require('gulp');
let del = require('delete');
var htmlmin = require('gulp-htmlmin');
var cssnano = require('gulp-cssnano');
var uglify = require('gulp-uglify');
let pump = require('pump');


function clean(cb) {
 del('./dist',cb);
}
//压缩html
function html(cb) {
    src('./*.html')
        .pipe(htmlmin({
            collapseWhitespace: true,
            removeComments: true
        }))
        .pipe(dest('dist'));
      cb();
}

//压缩css
function style(cb) {
    src(['./css/*.css'])
        .pipe(cssnano())
        .pipe(dest('dist/css'));
    cb();
}

//压缩js
function js(cb) {
    pump([
          gulp.src('./js/*.js'),
          uglify(),
          gulp.dest('dist/js')
      ]);
      cb();
}

exports.default = series("clean","style");

压缩图片

$_> npm i -D gulp-image
'use strict';
let { series, src, dest } = require('gulp');
let del = require('delete');
var imageMin = require('gulp-image');


function clean(cb) {
 del('./dist',cb);
}

function imagemin(cb) {
    gulp.src('images/*.*')
    .pipe(imageMin())
    .pipe(gulp.dest('dist/images'))
    cb();
}
exports.default = series('clean','imagemin');

你可能感兴趣的:(压缩)