Created
March 9, 2015 16:06
-
-
Save silenceisgolden/b5da72ab22d54f398e75 to your computer and use it in GitHub Desktop.
Example Gulpfile with Pagespeed Insights
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var psi = require('psi'); | |
var ngrok = require('ngrok'); | |
var sequence = require('run-sequence'); | |
// note server must already be running on port to be able to | |
// run this example perfectly | |
var PORT = 8000; | |
var site = ''; | |
gulp.task('ngrok', function(cb) { | |
return ngrok.connect( PORT, function( err, url ) { | |
site = url; | |
cb(err); | |
}); | |
}); | |
gulp.task('psi:desktop', function(cb) { | |
psi( site, { | |
nokey: 'true', | |
strategy: 'desktop' | |
}, function( error, data ) { | |
psi.output( site, function( err ) { | |
cb( err || error ); | |
}); | |
}); | |
}); | |
gulp.task('psi:mobile', function(cb) { | |
psi( site, { | |
nokey: 'true', | |
strategy: 'mobile' | |
}, function( error, data ) { | |
psi.output( site, function( err ) { | |
cb( err || error ); | |
}); | |
}); | |
}); | |
gulp.task('kill-process', function() { | |
process.exit(); | |
// could also be ngrok disconnect with callback | |
}); | |
gulp.task('psi', function(cb) { | |
sequence( | |
'ngrok', | |
'psi:desktop', | |
'psi:mobile', | |
'kill-process' | |
cb | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment