Jekyll-Assets: Missing assets when building site

Viewed 1583

I'm struggling to overcome a strange behavior with Jekyll-Assets when exporting all assets correctly on build command. The configuration is set to use cachebusting with "file system" cache type. When building we get all images and fonts correctly. But on one of the scss files it seems that fonts and images are exported randomly (sometimes yes, other times no). When files are not exported the path written in css is correct, containing the hash for the cachebust. While trying to debug with deleting .assets-cache and _site/ folder I've notice the random gets even much more frequent.

This is the configuration

Dev environment(Docker Container):

version: '3'
services:
  jekyll:
    build: .
    command: jekyll build --watch --incremental
    volumes:
      - .:/usr/src/app
  nginx:
    image: nginx:stable-alpine
    volumes:
      - ./_site:/usr/share/nginx/html
    ports:
      - 8080:80
    depends_on:
      - jekyll

Dev environment(Dockerfile):

FROM ruby:2.4.1-stretch
RUN apt-get update -qq && \
    apt-get install -y build-essential
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
ADD Gemfile /usr/src/app
ADD Gemfile.lock /usr/src/app
RUN gem install bundle && \
    bundle && \
    bundle install

Jekyll configuration(Gemfile):

gem "jekyll", "3.5.1"
group :jekyll_plugins do
  # gem "html-proofer"
  #gem "jekyll-redirect-from"
  gem "jekyll-assets"
  gem "coffee-script"
  gem "uglifier"
  gem "sass"
  gem "therubyracer"
  gem "less"
  gem "jekyll-feed"
  gem "jekyll-paginate-v2"
  gem "jekyll-last-modified-at"
  gem "jekyll-sitemap"
  gem "jekyll-minifier"
end

Project configuration (_config.yml):

assets:
  digest: true
  compress:
    css:  true
    js:   uglifier
  autoprefixer:
    browsers:
      - "> 1%"
      - "last 3 versions"
      - "IE > 9"
  prefix: "/assets"
  sources:
    - _assets/
    - _assets/js
    - _assets/css
    - _assets/javascript
    - _assets/stylesheets
    - _assets/img
    - _assets/fonts
1 Answers

TL;DR: Deleting _site before build caused the problem. Also deleting .jekyll-cache before build solved the problem for me.

I had a very similar experience with Jekyll-assets. During development it occurs that some images were missing in the _site/assets folder. After a bit trying out I found a way to reproduce it.

  1. Checkout a clean version of the code
  2. Build with bundle exec Jekyll build
  3. Run bundle exec jekyll clean (which deletes, among others, the _site folder)
  4. Build with bundle exec Jekyll build again

After these steps I had missing files in the _site/assets folder. What solved the problem for me was additional to using the jekyll clean to delete the folder .jekyll-cache. I quiet not deep enough into jekyll-assets to understand how the caching in this folder works, but at least it solves the problem. If the folder is excluded from version control, and in case it's a generated cache folder it should be, you can also use git clean -xdf but be careful with this, it deletes any file, that is not under version control! I would be grateful if you could verify my solution according to your concrete case.

I'm sorry that I could not provide you a real explanation for why this happens, but I hope that my answer could help you anyway.

Related