5

I try to build my jekyll project on production mode using JEKYLL_ENV variable but it doesn't work.

Jekyll documentation specifies to set a production environment in the build command :

JEKYLL_ENV=production jekyll build

But on Windows, this type of syntax is not correct. I used this following syntax, but it looks not working:

jekyll build JEKYLL_ENV=production

I also set 'manually' this environment variable but doesn't take effect :

setx JEKYLL_ENV production & jekyll build

and

set JEKYLL_ENV=production & jekyll build
Nicolas Law-Dune
  • 1,631
  • 2
  • 13
  • 30

3 Answers3

11

I ran into this as well with my Windows/Jekyll setup. My workaround is to have production and development config files and set the environment variable in each file.

// _config.yml
environment: production
...<other config settings>...

--------

// _config_dev.yml
environment: development

Your prod environment should run jekyll build which automatically uses _config.yml. Your dev environment should run jekyll <command> --config _config.yml,_config_dev.yml. In the Jekyll config docs, "Settings in later [config] files override settings in earlier files." So, you can set the variable in prod and dev config files and use --config _config.yml,_config_dev.yml to set the variable in dev.

To do stuff with it in Jekyll, use Liquid statements to check for the environment variable. Config files set site variables, so check site.environment

// some file that will be processed by Jekyll
{% if site.environment == "production" %}
    <do prod stuff>
{% elsif site.environment == "development" %}
    <do dev stuff>
{% endif %}
DC.Azndj
  • 1,346
  • 12
  • 13
3

On windows you should run two commands:

the first command set env to production

set JEKYLL_ENV=production

the second command run jekyll build or jekyll server

jekyll build

when you use development evn, run this command again:

 set JEKYLL_ENV=development
Thxopen
  • 168
  • 6
  • This worked for me. What I do is I use `set JEKYLL_ENV=production` right before I run `jekyll build`. After it builds for production, I turn it back to dev with `set JEKYLL_ENV=development`. – SrgSprinkles Sep 28 '19 at 17:15
  • This is what I needed! So used to working on Mac, key here is defining that `set` at the beginning. Thanks. – Beck Feb 12 '20 at 00:54
3

This worked for me:

set JEKYLL_ENV=production | jekyll build

Running the two commands separately like Thxopen suggested worked. Then I tried running the two commands on one line using the separator character as mentioned here, and it worked nicely.