title: Setting Jekyll environment for GitHub Pages
body: <p>I am building a site with Jekyll that I am hosting on GitHub Pages. I would like to be able to set the JEKYLL_ENV to 'production' (<code>JEKYLL_ENV=production</code>) when I deploy to GitHub Pages so I can do something like this:</p>
  
  <pre><code>{% if jekyll.environment == "production" %}
  {% include googleAnalytics.html %}
  {% endif %}
  </code></pre>
  
  <p>and </p>
  
  <pre><code>{% if jekyll.environment == "production" %}
      &lt;link rel="stylesheet" href="/assets/css/main.min.css"&gt;
  {% else %}
      &lt;link rel="stylesheet" href="/assets/css/main.css"&gt;
  {% endif %}
  </code></pre>
  
  <p>Now, I've read that GitHub Pages should automatically set the <code>JEKYLL_ENV</code> to <code>production</code>, but when I throw <code>{{ jekyll.enviornment }}</code> into my page, I get <code>development</code> both locally and on my hosted site. This may have do to with me building the site before I deploy using <a href="https://github.com/shakyShane/jekyll-gulp-sass-browser-sync" rel="noreferrer">this</a> and <a href="https://github.com/shinnn/gulp-gh-pages" rel="noreferrer">this</a>.</p>
  
  <p>My gulpfile.js</p>
  
  <pre><code>var gulp        = require('gulp');
  var ghPages     = require('gulp-gh-pages');
  var browserSync = require('browser-sync');
  var sass        = require('gulp-sass');
  var prefix      = require('gulp-autoprefixer');
  var minifyCss   = require('gulp-minify-css');
  var rename      = require('gulp-rename');
  var cp          = require('child_process');
  
  ...
  
  /**
   * Build the Jekyll Site
   */
  gulp.task('jekyll-build', function (done) {
      browserSync.notify(messages.jekyllBuild);
      return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
          .on('close', done);
  });
  
  ...
  
  /**
   * Deploy to gh-pages
   */
  gulp.task('deploy', ['jekyll-build'], function() {
      return gulp.src('./_site/**/*')
          .pipe(ghPages());
  });
  </code></pre>
  
  <p>Essentially, when I run <code>gulp deploy</code>, I take the <code>_site</code> directory and push it to the <code>gh-pages</code> branch.</p>
  
  <p>I don't know if this is causing the environment to be set to <code>development</code> or what, but what I am thinking of doing is instead of running the <code>jekyll-build</code> task in the <code>deploy</code> task is making and running a new <code>jekyll-build-prod</code> task that sets the <code>JEKYLL_ENV</code> to <code>production</code>.</p>
  
  <p>This is the problem I'm running into. I'm not sure how to set the environment using <code>child_process</code> <code>spawns</code> (it was already written in <a href="https://github.com/shakyShane/jekyll-gulp-sass-browser-sync" rel="noreferrer">this</a> boilerplate). I've seen this command recommended: <code>$ JEKYLL_ENV=production jekyll build</code>. I just seem to need to alter my <code>jekyll-build</code> task to incorporate that.</p>
  
  <p>If there is a simpler way of doing this, I'd love to hear it.</p>
  
  <p>Any help is appreciated.</p>
  
  <p>EDIT:</p>
  
  <p>I have tried including both a <code>_config.yml</code> where I set <code>environment: prod</code> and a <code>_config_dev.yml</code> where I set <code>environment: dev</code> and updating my gulp tasks to:</p>
  
  <pre><code>/**
   * Build the Jekyll Site
   */
  gulp.task('jekyll-build', function (done) {
      browserSync.notify(messages.jekyllBuild);
      return cp.spawn('jekyll', ['build', '--config', '_config.yml,_config_dev.yml'], {stdio: 'inherit'})
          .on('close', done);
  });
  
  /**
   * Build the Jekyll Site for production
   */
  gulp.task('jekyll-build-prod', function (done) {
      browserSync.notify(messages.jekyllBuild);
      return cp.spawn('jekyll', ['build', '--config', '_config.yml'], {stdio: 'inherit'})
          .on('close', done);
  });
  </code></pre>
  
  <p>However, when I run the deploy task and check the hosted site, it still says the <code>environment</code> is <code>development</code>.</p>
  
  <p>Even if I include <code>environment: prod</code> in both <code>_config.yml</code> and <code>_config_dev.yml</code>, it still says <code>development</code>.</p>