Environment Variables, Bundler Groups, and Jekyll
Mar 4, 2016
Tags: Jekyll Web Development
Oh my. If you’re working with Jekyll and rolling your own build and deployment process, chances are you’re slowly but surely accumulating sundry plugins, gems, and build scripts. Some of these are for local development, some are for deploying your site, some are for both—but configured differently for each. How do you manage all this? Bundler groups and environment variables are here to help.
JEKYll_ENV. It defaults to
"development" and you can set it when building or serving e.g.
JEKYLL_ENV=production jekyll build. Most plugins like Jekyll-Assets will look for the variable and act accordingly—only compressing and digesting in production, etc. The variable is also available in your templates at
jekyll.environment so you can include and exclude things as appropriate.
When it comes to managing your site’s dependencies for a given environment, Bundler’s groups can help out. Organize your Gemfile into the approprate groups to make sure you’re loading the right gems when you need them.
source 'https://rubygems.org' gem 'github-pages' gem 'jekyll-paginate' group :development do gem 'guard' gem 'guard-livereload' end group :production do gem 'rake' gem 'uglifier' end
This is especially helpful when using something like a continuous integration service to build and deploy your site. By passing in the
--without development flag as a bundler argument you can leave those gems behind and not bother loading them onto the build server since you don’t need them.