基本上我想看看我的jekyll项目,当发生变化时,我的浏览器会刷新以反映它们。我的想法是将gulp-jekyll集成到我的工作流程中,这样做也可以启动服务器......
var gulp = require('gulp');
gutil = require('gulp-util'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
connect = require('gulp-connect'),
exec = require('gulp-exec'),
livereload = require('gulp-livereload'),
lr = require('tiny-lr'),
server = lr();
var jsSources = ['source/assets/js/*.js', 'source/assets/lib/*.js'];
var sassSources = ['source/assets/sass/style.scss'];
gulp.task('styles', function() {
return gulp.src(sassSources)
.pipe(sass({
style: 'expanded'
}))
.pipe(autoprefixer('last 29 version'))
.pipe(minifycss())
.pipe(gulp.dest('source/stylesheets/vendor/min'))
.pipe(connect.reload())
.pipe(livereload())
.pipe(notify({
message: 'By your command..."styles" command executed'
}))
});
gulp.task('js', function() {
return gulp.src(jsSources)
.pipe(uglify())
.pipe(concat('script.js'))
.pipe(gulp.dest('source/javascript'))
.pipe(connect.reload())
.pipe(livereload())
.pipe(notify({
message: 'By your command..."js" command executed'
}))
});
然而,这就是造成错误的原因......请参阅下面的终端输出。
gulp.task('server', function() {
connect(connect.static('_site')).listen(9000);
console.log('Server running at http://localhost:9000/');
gulp.watch('source/**', function(event) {
console.log(event.path + ' ' + event.type + ', rebuilding...')
gulp.src('').pipe(exec("jekyll build && compass compile")).pipe(livereload());
});
});
gulp.task('watch', function() {
var server = livereload();
gulp.watch(jsSources, ['js']);
gulp.watch(['source/**'], ['server']);
gulp.watch(['javascript/script.js'], function(e) {
server.changed(e.path);
});
gulp.watch(sassSources, ['styles']);
});
gulp.task('default', ['js', 'styles', 'watch', 'server']);
这是终端中的错误......
[gulp] Starting 'server'...
[gulp] 'server' errored after 83 μs Object #<Object> has no method 'static'
声明 我知道有一个伟大的yeoman generator已经存在。它似乎做了我想要的一切。为什么折磨自己呢?好吧,我实际上自己配置了大部分现有的gulp文件。并且很想弄明白......