connect.reload() завершается ошибкой после задачи jekyll в файле gulpfile.js

Это gulpfile.js код должен следить за моими файлами и преобразовывать их при изменении. Кажется, все работает хорошо, кроме connect.reload()после джекилла Помогите мне в решении этой проблемы, а также советы по возможной оптимизации кода в целом.

var gulp = require('gulp'),
    less     = require('gulp-less'),
    plumber  = require('gulp-plumber'),
    connect  = require('gulp-connect');

function jekyll() {
  var through = require('through2');
  return through.obj(function (file, enc, cb) {
    var spawn = require('win-spawn');
    spawn('jekyll', ['build', '--config', file.path.split('\\').slice(-1)], {
      stdio: 'inherit'
    }).on('close', function() {
      cb();
    });
  });
}

gulp.task('connect', connect.server({
  root: ['../deployment'],
  port: 8888,
  livereload: true,
}));

gulp.task('less', function() {
  return gulp.src('./less/bootstrap/bootstrap.less')
    .pipe(plumber())
    .pipe(less({
      paths: [ './less/bootstrap/*.less' ]
    }))
    .pipe(gulp.dest('./css'))
    .pipe(connect.reload());
});

gulp.task('jekyll',function() {
  return gulp.src('./_config.yml')
    .pipe(jekyll())
    .pipe(connect.reload());
});

gulp.task('watch', ['connect'], function(){
  gulp.watch('./less/bootstrap/*.less', ['less']);
  gulp.watch([
    './_layouts/*.html',
    './_includes/*.html',
    './_posts/*.*',
    './css/*.*',
    './index.html'],
  ['jekyll']);
});

gulp.task('default', ['connect', 'watch']);

В исполнении:

[gulp] Using gulpfile C:\blog\source\gulpfile.js
[gulp] Starting 'connect'...
[gulp] Connect LiveReload on 35729 port
[gulp] Finished 'connect' after 20 ms
[gulp] Starting 'watch'...
[gulp] Finished 'watch' after 208 ms
[gulp] Starting 'default'...
[gulp] Finished 'default' after 11 μs
[gulp] Server started on 8888 port
[gulp] Starting 'jekyll'...
Configuration file: _config.yml
            Source: .
       Destination: ../deployment
      Generating... done.
[gulp] Finished 'jekyll' after 1.23 s
[gulp] Starting 'less'...
... Reload C:\blog\source\css\bootstrap.css ...
... Reload C:\blog\source\css\bootstrap.css ...
[gulp] Finished 'less' after 904 ms
[gulp] Starting 'jekyll'...
Configuration file: _config.yml
            Source: .
       Destination: ../deployment
      Generating... done.
[gulp] Finished 'jekyll' after 1.11 s

Обновить:

var gulp    = require('gulp'),
    less    = require('gulp-less'),
    connect = require('gulp-connect'),
    plumber = require('gulp-plumber'),
    map     = require('map-stream');

var jekyll = function(file, callback) {
  var spawn = require('win-spawn');
  var path  = require('path');
  return spawn('jekyll', ['build', '--config', file.path.split('\\').slice(-1)], {
    stdio: 'inherit'
  }).on('close', function(){
    callback(null, file);
  });
};

gulp.task('jekyll', function(){
  return gulp.src('./_config.yml')
    .pipe(map(jekyll))
    .pipe(connect.reload());
});

gulp.task('connect', function() {
  connect.server({
    root: [ __dirname ],
    port: 1337,
    livereload: true
  });
});

gulp.task('less', function() {
  return gulp.src('./less/bootstrap/bootstrap.less')
    .pipe(plumber())
    .pipe(less({
      paths: [ './less/bootstrap/*.less' ]
    }))
    .pipe(gulp.dest('./css'))
    .pipe(connect.reload());
});

gulp.task('watch', ['connect'], function(){
  gulp.watch('./less/bootstrap/*.less', ['less', 'jekyll']);
  gulp.watch([
    './_layouts/*.html',
    './_includes/*.html',
    './_posts/*.*',
    './css/*.*',
    './index.html'],
  ['jekyll']);
});

gulp.task('default', ['connect', 'watch']);

В исполнении:

C:\Users\Sparky\blog\src>gulp
[gulp] Using gulpfile C:\Users\Sparky\blog\src\gulpfile.js
[gulp] Starting 'connect'...
[gulp] Server started http://localhost:1337
[gulp] LiveReload started on port 35729
[gulp] Finished 'connect' after 20 ms
[gulp] Starting 'watch'...
[gulp] Finished 'watch' after 140 ms
[gulp] Starting 'default'...
[gulp] Finished 'default' after 9.41 μs
[gulp] Starting 'jekyll'...
Configuration file: _config.yml
            Source: C:/Users/Sparky/blog/src
       Destination: ../dest
      Generating... done.
... Reload C:\Users\Sparky\blog\src\_config.yml ...
... Reload C:\Users\Sparky\blog\src\_config.yml ...
... Reload C:\Users\Sparky\blog\src\_config.yml ...
... Reload C:\Users\Sparky\blog\src\_config.yml ...
[gulp] Finished 'jekyll' after 677 ms
[gulp] Starting 'jekyll'...
Configuration file: _config.yml
            Source: C:/Users/Sparky/blog/src
       Destination: ../dest
      Generating... done.
... Reload C:\Users\Sparky\blog\src\_config.yml ...
... Reload C:\Users\Sparky\blog\src\_config.yml ...
... Reload C:\Users\Sparky\blog\src\_config.yml ...
[gulp] Finished 'jekyll' after 647 ms
[gulp] Starting 'jekyll'...
Configuration file: _config.yml
            Source: C:/Users/Sparky/blog/src
       Destination: ../dest
      Generating... done.
... Reload C:\Users\Sparky\blog\src\_config.yml ...
... Reload C:\Users\Sparky\blog\src\_config.yml ...
[gulp] Finished 'jekyll' after 662 ms
[gulp] Starting 'jekyll'...
Configuration file: _config.yml
            Source: C:/Users/Sparky/blog/src
       Destination: ../dest
      Generating... done.
... Reload C:\Users\Sparky\blog\src\_config.yml ...
... Reload C:\Users\Sparky\blog\src\_config.yml ...
... Reload C:\Users\Sparky\blog\src\_config.yml ...

0 ответов

Другие вопросы по тегам