我刚回到这个问题上,自去年夏天以来情况有了很大改善。我基于 Polymer Starter Kit (1.2.3) 制作了一个 gulpfile。但是我改变了default 和serve 任务的行为来运行 Jekyll serve 并在 shell 中构建:
var spawn = require('child_process').spawn;
var argv = require('yargs').argv;
gulp.task('jekyllbuild', function(done) {
return spawn('bundle', ['exec', 'jekyll', 'build'], { stdio: 'inherit' })
.on('close', done);
});
// Build production files, the default task
gulp.task('default', ['clean'], function(cb) {
// Uncomment 'cache-config' if you are going to use service workers.
runSequence(
'jekyllbuild',
['ensureFiles', 'copy', 'styles'],
'elements',
['images', 'fonts', 'html'],
'vulcanize', // 'cache-config',
cb);
});
gulp.task('serve', function(done) {
if (argv.port) {
return spawn('bundle', ['exec', 'jekyll', 'serve', '--port=' + argv.port], { stdio: 'inherit' })
.on('close', done);
} else {
return spawn('bundle', ['exec', 'jekyll', 'serve'], { stdio: 'inherit' })
.on('close', done);
}
});
使用 BrowserSync 会产生更清洁的效果,但这是获得 Jekyll 功能和生产硫化优势的简单方法。 (请注意,您还必须安装 yargs 包来处理端口规范。)我的整个 gulpfile 是 here。