以下是我在gulpfile.js中的代码:
var gulp = require('gulp');
var ngrok = require('ngrok');
var psi = require('psi');
var sequence = require('run-sequence').use(gulp);
var browserSync = require('browser-sync').create();
var site = '';
var portVal = 3000;
gulp.task('browser-sync-psi', function() {
browserSync.init({
proxy: "http://localhost:8080/mysite/"
});
});
gulp.task('ngrok-url', function(cb) {
return ngrok.connect(portVal, function (err, url) {
site = url;
console.log('serving your tunnel from: ' + site);
cb();
});
});
gulp.task('psi-desktop', function (cb) {
psi(site, {
nokey: 'true',
strategy: 'desktop'
}, cb);
});
gulp.task('psi-mobile', function (cb) {
psi(site, {
nokey: 'true',
strategy: 'mobile'
}, cb);
});
// psi sequence with 'browser-sync-psi' instead
gulp.task('psi-seq', function (cb) {
return sequence(
'browser-sync-psi',
'ngrok-url',
'psi-desktop',
'psi-mobile',
cb
);
});
// psi task runs and exits
gulp.task('psi', ['psi-seq'], function() {
console.log('Woohoo! Check out your page speed scores!')
process.exit();
})
在运行'gulp psi'后,结果在我的终端中显示如下:
$ gulp psi
[08:29:48] Using gulpfile ~/Development/Test/npm-speedcheck/gulpfile.js
[08:29:48] Starting 'psi-seq'...
[08:29:48] Starting 'browser-sync-psi'...
[08:29:48] Finished 'browser-sync-psi' after 17 ms
[08:29:48] Starting 'ngrok-url'...
[BS] Proxying: http://localhost:8080
[BS] Access URLs:
-------------------------------------------
Local: http://localhost:3000/mysite
External: http://192.168.0.11:3000/mysite
-------------------------------------------
UI: http://localhost:3001
UI External: http://192.168.0.11:3001
-------------------------------------------
serving your tunnel from: https://9e2791da.ngrok.io
[08:29:49] Finished 'ngrok-url' after 761 ms
[08:29:49] Starting 'psi-desktop'...
[08:30:26] Finished 'psi-desktop' after 37 s
[08:30:26] Starting 'psi-mobile'...
[08:30:27] Finished 'psi-mobile' after 599 ms
[08:30:27] Finished 'psi-seq' after 39 s
[08:30:27] Starting 'psi'...
Woohoo! Check out your page speed scores!
我知道PSI安装正确,因为我可以在终端内测试公共站点并获得准确的结果。
我错过了什么?