From 2d0ebdfd881f2bb805067d0add853d184244ca54 Mon Sep 17 00:00:00 2001 From: Matt Stratton Date: Thu, 12 Jan 2017 18:02:30 -0800 Subject: [PATCH 1/2] Add critical module and initial test Not part of the default gulp task yet Signed-off-by: Matt Stratton --- gulpfile.js | 32 ++++++++++++++++++++++++++++++++ package.json | 2 ++ 2 files changed, 34 insertions(+) diff --git a/gulpfile.js b/gulpfile.js index 37aba80c4..9c6b22b02 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -11,6 +11,23 @@ var gulp = require('gulp'), runSequence = require('run-sequence'); responsive = require('gulp-responsive'); imgRetina = require('gulp-img-retina'); + critical = require('critical').stream; + gutil = require('gulp-util'); + +// Generate & Inline Critical-path CSS +gulp.task('critical', function () { + return gulp.src('public/**/*.html') + .pipe(critical({ + base: 'staging/', + inline: true, + css: ['public/css/googlemaps.css','public/css/site.css'], + ignore: ['@font-face',/url\(/], + minify: true, + timeout: 300000 // 5 min timeout + })) + .on('error', function(err) { gutil.log(gutil.colors.red(err.message)); }) + .pipe(gulp.dest('staging')); +}); gulp.task('responsive-images', function () { @@ -52,6 +69,21 @@ gulp.task('process-html', function() { .on('error', function(e) { console.log(e.message); }) + .pipe(critical({ + base: 'public/', + inline: true, + css: ['public/css/googlemaps.css','public/css/site.css'], + ignore: ['@font-face',/url\(/], + minify: true, + dimensions: [{ + width: 1300, + height: 900 + }, + { + width: 500, + height: 900 + }] + })) .pipe(htmlmin({collapseWhitespace: true})) .pipe(gulp.dest('staging')); diff --git a/package.json b/package.json index a7c048c88..466bb0a0c 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "author": "Matt Stratton", "license": "MIT", "devDependencies": { + "critical": "^0.8.1", "gulp": "^3.9.1", "gulp-cache": "^0.4.5", "gulp-changed": "^1.3.2", @@ -22,6 +23,7 @@ "gulp-rev-replace": "^0.4.3", "gulp-uglify": "^2.0.0", "gulp-useref": "^3.1.2", + "gulp-util": "^3.0.8", "run-sequence": "^1.2.2" } } From 880f52bb3b91b5f26c788e783b858f0ddd91dd67 Mon Sep 17 00:00:00 2001 From: Matt Stratton Date: Thu, 12 Jan 2017 18:12:53 -0800 Subject: [PATCH 2/2] Update gulpfile Signed-off-by: Matt Stratton --- gulpfile.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 9c6b22b02..d57958a49 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -70,7 +70,7 @@ gulp.task('process-html', function() { console.log(e.message); }) .pipe(critical({ - base: 'public/', + base: 'staging/', inline: true, css: ['public/css/googlemaps.css','public/css/site.css'], ignore: ['@font-face',/url\(/], @@ -82,7 +82,8 @@ gulp.task('process-html', function() { { width: 500, height: 900 - }] + }], + timeout: 300000 // 5 min timeout })) .pipe(htmlmin({collapseWhitespace: true})) .pipe(gulp.dest('staging'));