From 5eb199c5852dee192f941a552d92b9d302c6be21 Mon Sep 17 00:00:00 2001 From: Rob Wierzbowski Date: Mon, 28 Dec 2015 16:13:33 -0800 Subject: [PATCH] Replace deprecated minifiers with gulp-cssnano and gulp-htmlmin gulp-htmlmin currently has to be manually configured; there are no sensible defaults. These transforms are all relatively safe, and in my experience provide the bulk of HTML minification gains. --- gulpfile.babel.js | 16 +++++++++++++--- package.json | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 9ca38a4df..0d5011f9c 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -96,7 +96,7 @@ gulp.task('styles', () => { .pipe($.autoprefixer(AUTOPREFIXER_BROWSERS)) .pipe(gulp.dest('.tmp/styles')) // Concatenate and minify styles - .pipe($.if('*.css', $.minifyCss())) + .pipe($.if('*.css', $.cssnano())) .pipe($.size({title: 'styles'})) .pipe($.sourcemaps.write('./')) .pipe(gulp.dest('dist/styles')); @@ -141,10 +141,20 @@ gulp.task('html', () => { // Concatenate and minify styles // In case you are still using useref build blocks - .pipe($.if('*.css', $.minifyCss())) + .pipe($.if('*.css', $.cssnano())) // Minify any HTML - .pipe($.if('*.html', $.minifyHtml())) + .pipe($.if('*.html', $.htmlmin({ + removeComments: true, + collapseWhitespace: true, + collapseBooleanAttributes: true, + removeAttributeQuotes: true, + removeRedundantAttributes: true, + removeEmptyAttributes: true, + removeScriptTypeAttributes: true, + removeStyleLinkTypeAttributes: true, + removeOptionalTags: true + }))) // Output files .pipe($.if('*.html', $.size({title: 'html', showFiles: true}))) .pipe(gulp.dest('dist')); diff --git a/package.json b/package.json index c8cbc02f2..c401f4050 100644 --- a/package.json +++ b/package.json @@ -11,12 +11,12 @@ "gulp-babel": "^6.0.0", "gulp-cache": "0.2.2", "gulp-concat": "^2.5.2", + "gulp-cssnano": "^2.0.0", "gulp-eslint": "^1.0.0", + "gulp-htmlmin": "^1.3.0", "gulp-if": "^2.0.0", "gulp-imagemin": "^2.0.0", "gulp-load-plugins": "^1.0.0", - "gulp-minify-css": "^1.1.6", - "gulp-minify-html": "^1.0.4", "gulp-newer": "^1.0.0", "gulp-sass": "^2.0.0", "gulp-size": "^2.0.0",