Skip to content

Commit

Permalink
Replace deprecated minifiers with gulp-cssnano and gulp-htmlmin
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
robwierzbowski committed Dec 29, 2015
1 parent c4f77a2 commit 5eb199c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 13 additions & 3 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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'));
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5eb199c

Please sign in to comment.