2

I'm developing a Jekyll plugin. When I run the jekyll serve command, site files are regenerated when I change any markdown, html, or plugin files, as expected. The problem I've found is that while markdown/HTML files are regenerated, the plugins themselves are not reloaded. I have to terminate jekyll serve and issue the command again for the plugin changes to go into effect. Is there a way to make it so that the plugins get reloaded automatically when changed?

This is for Jekyll 3.1.2.

Chris Hunt
  • 3,840
  • 3
  • 30
  • 46
  • You can search for Gulp serve and watch, it will do the trick. – David Jacquel Apr 08 '16 at 21:31
  • Try `jekyll serve --watch` – Virtua Creative Apr 09 '16 at 00:37
  • @DavidJacquel thanks, I think I'll go that route and post my script once it is done. – Chris Hunt Apr 09 '16 at 00:40
  • @VirtuaCreative, thank you. I don't know which version it was changed but `jekyll serve` includes auto-regeneration by default. My problem is that it doesn't reload plugins. – Chris Hunt Apr 09 '16 at 00:42
  • Hmm... got it. I didn't know that. Have you tried [Prepos](https://prepros.io/)? I'm not sure it's gonna work, but you could try... – Virtua Creative Apr 09 '16 at 00:45
  • No, I don't think this is gonna work. "In your site source root, make a _plugins directory. Place your plugins here. Any file ending in *.rb inside this directory will be loaded before Jekyll generates your site." [Source](https://jekyllrb.com/docs/plugins/#installing-a-plugin). The plugin will be loader before Jekyll generates the site. – Virtua Creative Apr 09 '16 at 00:49

1 Answers1

1

Based on the suggestion from @DavidJacquel and the gist I found here, I used Gulp with this gulpfile

'use strict';

var gulp = require('gulp'),
    express = require('express'),
    spawn = require('child_process').spawn;

var jekyll_file = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';

gulp.task('jekyll', () => {
  var jekyll = spawn(jekyll_file, ['build', '--incremental']);

  var output = '';
  jekyll.stdout.on('data', (t) => { output += t; });
  jekyll.stderr.on('data', (t) => { output += t; });

  jekyll.on('exit', (code) => {
    if (code)
      console.log(`Jekyll exited with code: ${code}\n${output}`);
    else
      console.log("Finished Jekyll build");
  });
});


gulp.task('serve', () => {
  var server = express();
  server.use(express.static('_site/'));
  server.listen(4000);
});

gulp.task('watch', () => {
  gulp.watch(['**/*.html', '**/*.md', '_plugins/*.rb', '!_site/**/*'], ['jekyll']);
});

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

to get the desired effect. Also created issue here.

Chris Hunt
  • 3,840
  • 3
  • 30
  • 46