Skip to content

@dannygarcia /grunt.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Sample grunt-jekyll grunt.js

Sample grunt-jekyll grunt.js

  1. Use the following folder structure
[root]
    |-- templates/
        |-- index.html (Jekyll templates)
    |-- prod/
    |-- dev/
    |-- _config.yml (optional)
  1. Add the grunt.js file below at the root of your project.

  2. Install the grunt-jekyll gruntmodule next to your project's grunt.js gruntfile with: npm install grunt-jekyll.

  3. Run the grunt jekyll commands:

  • grunt jekyll or grunt jekyll:server to start a server that watches the templates directory.

  • grunt jekyll:dev to process files to the dev directory.

  • grunt jekyll:prod to process files to the prod directory.

Of course, everything here is fully configurable to your liking.

// Sample grunt-jekyll grunt.js file
// https://github.com/dannygarcia/grunt-jekyll
/*global module:false*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
jekyll: {
server : {
src : 'templates',
dest: 'dev',
server : true,
server_port : 8000,
auto : true
},
dev: {
src: 'templates',
dest: 'dev'
},
prod: {
src: 'templates',
dest: 'prod'
}
},
watch: { // for development run 'grunt watch'
jekyll: {
files: ['templates/*.html'],
tasks: ['jekyll:dev']
}
}
});
// Default task. Run standard jekyll server.
grunt.registerTask('default', 'jekyll:server');
// plugin tasks
grunt.loadNpmTasks('grunt-jekyll');
};
@bebraw

Is there a way to run the server instantly at "watch"? It seems to load only after I make a change to some watched file. Probably missing something obvious here.

EDIT: Solved this using the server task and an alias (grunt.registerTask('default', 'server watch');).

@caiogondim

With the new Grunt.js, it worked for me:
grunt.registerTask('default', ['server', 'watch']);

@tarjei

To use the watch functionality do:

npm install grunt-contrib-watch --save-dev

and add

grunt.loadNpmTasks('grunt-contrib-watch');

To your grunt file.

@Wolfr

What is the final file supposed to look like?

https://gist.github.com/Wolfr/5332250 returns a warning

Warning: Task "server" not found. Use --force to continue.
@fcalderan

using Jekyll 1.0.2, you might need to change the keys "src" and "dest" respectively into "source" and "destination", in order to correctly run the task

@tomireland

Hey, Danny

I setup my Gruntfile.js to reflect the above, but for some reason it keeps building instead of serving the site and the watch doesn't start. It seems to be picking up the defaults from my _config.yml file instead of using the one's specified in my grunt file e.g. I tell it to build to a dev folder, but it keeps building to _site. Any ideas?

jekyll: {
      server : {
        dest: 'dev',
        server : true,
        server_port : 8000,
        auto : true
      },
      dev: {
        dest: 'dev'
      }
    },

    watch: { // for development run 'grunt watch'
      jekyll: {
        files: ['templates/*.html'],
        tasks: ['jekyll:dev']
      }
    }
@YoungElPaso

@tomireland, I think this sample file is out of date. Or at least I don't think the syntax for the server options are set quite right. Yeah, in fact the option "server: true" needs to be "serve: true" with the current version of grunt-jekyll, and should be wrapped in an "options" object : eg options : {serve: true}. Also the rest of the options are just that, options and the default jekyll build and serve will work fine.

@liquidvisual

Any chance of an update? Would love to get this working with Jekyll 2.0.2

@prbaron

@liquidvisual, I made it works by modifying these lines, allowing to the code of the plugin.

jekyll: {
    server : {
        options : {
            server : true,
            server_port : 8000,
            auto : true
        }
    }
}
@ezze

I was unable to run a server with Jekyll 2.4.0 and plugin version 0.4.2 on Ubuntu 14.04 LTS. After looking at the source code of the Grunt task I got that it must be serve option instead of server.

server: {
    options: {
        serve: true,
        port: 8000,
        auto: true
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.