Running Jekyll Serve in Development Mode

With Jekyll I've gotten used to always change my _config.yml setting for url and imgurl like this when getting ready to commit my changes for the production version:

url: ''
urlimg: ''

#url: 'http://localhost:4000'
#urlimg: 'http://localhost:4000/images'

And then like this for development:

#url: ''
#urlimg: ''

url: 'http://localhost:4000'
urlimg: 'http://localhost:4000/images'

This not only is an annoying extra step, but it can lead to problems if you deploy to production and forget to swith the comments back in the _config.yml file. It turns out however that there's a much easier way: having a _config_dev.yml file. In that file you would have something like this:

url: 'http://localhost:4000'
urlimg: 'http://localhost:4000/images'

And then, when you want to work on your website in development mode, it's as simple as running this:

jekyll serve --config _config.yml,_config_dev.yml

With that command, the _config_dev.yml overwrites the settings from your regular _config.yml

Obviously, the problem now is that this jekyll serve --config _config.yml,_config_dev.yml is quite a mouthful to type in each time. A simple solution is to have a simple rake task for it. Create a file in your project's directory called rakefile and add the following to it:

def execute(command)
  system "#{command}"

desc 'Jekyll Serve'
task :serve do
  execute("jekyll serve --config _config.yml,_config_dev.yml")

Now all you have to do to run a jekyll development server is this:

rake serve

And there you have it! A good handful of seconds saved each time you want to start working on your Jekyll website locally.

  Tweet It

🕵 Search Results

🔎 Searching...