Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jekyll-assets not compatible with Jekyll 4.0 #613

Closed
2 of 18 tasks
metrix78 opened this issue Aug 22, 2019 · 13 comments
Closed
2 of 18 tasks

Jekyll-assets not compatible with Jekyll 4.0 #613

metrix78 opened this issue Aug 22, 2019 · 13 comments
Assignees
Milestone

Comments

@metrix78
Copy link

metrix78 commented Aug 22, 2019

  • I tried updating to the latest version
    • I can't, there is an issue
    • This is about an < latest
      • I understand older versions may be unsupported
  • I Am on Windows
    • Ubuntu Bash on Windows
    • Fedora Bash on Windows
    • Other Bash on Windows
  • I Am on Linux
    • Ubuntu
    • Fedora
    • CentOS
    • Redhat
    • Debian
  • I am on macOS 10.13
  • I am on macOS 10.14
  • I'm on Docker
    • I understand Docker may be unsupported

Description

Making a new project that uses jekyll-assets and jekyll 3.8.6 works fine, but when upgrading
to Jekyll 4.0.0 assets does not appear to be called.

Steps

use the following shell script to setup test environment

#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset

echo 'removing broke'
#rm -Rf broke

echo 'creating broke'
mkdir broke
cd broke
echo 'gem "jekyll"' >> Gemfile
echo 'gem "jekyll-assets"' >> Gemfile

echo 'creating new blog'
bundle exec jekyll new blog
cd blog
echo 'gem "jekyll-assets"' >> Gemfile
bundle install

echo 'setting up the failure state'

#make an abc javascript file.
mkdir -p assets/javascript/abc
echo "//test javascript file." >> assets/javascript/abc/index.js

#add asset to index.md
echo '{% asset abc.js %}' >> index.md


cat > _config.yml <<EOF
# Welcome to Jekyll!
#
# This config file is meant for settings that affect your whole blog, values
# which you are expected to set up once and rarely edit after that. If you find
# yourself editing this file very often, consider using Jekyll's data files
# feature for the data you need to update frequently.
#
# For technical reasons, this file is *NOT* reloaded automatically when you use
# 'bundle exec jekyll serve'. If you change this file, please restart the server process.

# Site settings
# These are used to personalize your new site. If you look in the HTML files,
# you will see them accessed via {{ site.title }}, {{ site.email }}, and so on.
# You can create any custom variable you would like, and they will be accessible
# in the templates via {{ site.myvariable }}.
title: Your awesome title
email: your-email@example.com
description: >- # this means to ignore newlines until "baseurl:"
  Write an awesome description for your new site here. You can edit this
  line in _config.yml. It will appear in your document head meta (for
  Google search results) and in your feed.xml site description.
baseurl: "" # the subpath of your site, e.g. /blog
url: "" # the base hostname & protocol for your site, e.g. http://example.com
twitter_username: jekyllrb
github_username:  jekyll

# Build settings
markdown: kramdown
theme: minima
plugins:
  - jekyll-feed
  - jekyll-assets

# Exclude from processing.
# The following items will not be processed, by default. Create a custom list
# to override the default setting.
# exclude:
#   - Gemfile
#   - Gemfile.lock
#   - node_modules
#   - vendor/bundle/
#   - vendor/cache/
#   - vendor/gems/
#   - vendor/ruby/
EOF


echo 'build'
bundle exec jekyll b

Output

Running the above command will work fine:

      Generating...
       Jekyll Feed: Generating feed for posts
                    done in 0.75 seconds.
 Auto-regeneration: disabled. Use --watch to enable.

but if you:

  • change the version of Jekyll in broke/blog/Gemfile to 4.0.0
  • cd broke/blog
  • bundle update
  • bundle exec jekyll b

You will get:

 bundle exec jekyll b
Configuration file: /home/metrix/code/broke/blog/_config.yml
            Source: /home/metrix/code/broke/blog
       Destination: /home/metrix/code/broke/blog/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
       Jekyll Feed: Generating feed for posts
  Liquid Exception: Couldn't find file 'abc.js' in index.md
                    ------------------------------------------------
      Jekyll 4.0.0   Please append `--trace` to the `build` command
                     for any additional information or backtrace.
                    ------------------------------------------------

Expected

The abc.js should have been built with no error like so:

      Generating...
       Jekyll Feed: Generating feed for posts
                    done in 0.75 seconds.
 Auto-regeneration: disabled. Use --watch to enable.
@metrix78
Copy link
Author

metrix78 commented Aug 22, 2019

I think the following section of the 3.x to 4.x upgrade documentation states what the issues is:

If its a requirement that template you get from the above step be different at all times, you can invoke Liquid::Template directly:

- template = site.liquid_renderer.file(path).parse(content)
+ template = Liquid::Template.parse(content)

I don't know enough about how jekyll assets works, but I would guess line 186 of utils.rb needs to be modified:

        when obj.is_a?(String)
          k = Digest::SHA256.hexdigest(obj)[0, 6]
          ctx.registers[:site].liquid_renderer.file("(asset:var:#{k})")
            .parse(obj).render!(ctx)
        else

@metrix78
Copy link
Author

Digging further, I see what happened. Upgrading to Jekyll 4 makes Bundler try to find the first version compatible. 1.0 is marked to be compatible with Jekyll < 5.0, so it gets installed.

@flipacholas
Copy link

flipacholas commented Sep 14, 2019

Manually setting the Gemfile to get all the cutting edge dependencies:

gem 'jekyll-assets', :git => 'https://github.com/envygeeks/jekyll-assets.git'
gem 'jekyll-sanity', :git => 'https://github.com/envygeeks/jekyll-sanity.git'
gem 'sprockets', '4.0.0.beta8'

will still result in

Dependency Error: Yikes! It looks like you don't have jekyll-assets or one of its dependencies installed. In order to use Jekyll as currently configured, you'll need to install this gem. If you've run Jekyll with `bundle exec`, ensure that you have included the jekyll-assets gem in your Gemfile as well. The full error message from Ruby is: 'cannot load such file -- sass' If you run into trouble, you can find helpful resources at https://jekyllrb.com/help/! 
------------------------------------------------
Jekyll 4.0.0   Please append `--trace` to the `build` command for any additional information or backtrace. 
------------------------------------------------

Which doesn't happen using Jekyll 3.8.6

@flipacholas
Copy link

flipacholas commented Oct 11, 2019

Finally got it working, this setup should be provisional but it works if you want to make the jump to 4.0.0:

group :jekyll_plugins do
    gem 'jekyll-assets', :git => 'https://github.com/kou/jekyll-assets.git', :branch => 'add-support-for-sprockets-4.0'
    gem 'jekyll-sanity', :git => 'https://github.com/envygeeks/jekyll-sanity.git'
    gem 'sass'
end

Branch used comes from #620

@nhoizey
Copy link
Contributor

nhoizey commented Nov 5, 2019

@flipacholas I tried this, but there are issues with some assets.

You can compare these two pages for example:

What I see:

  • syntax like {% asset "early-js" @inline %} for inline JS works as before, but {% asset "critical-styles" @inline %} for inline CSS (compiled from Sass) doesn't work anymore (there is nothing produced in the resulting HTML)
  • syntax like {% asset "non-critical-styles" @path %} generates the path to the (hashed) source Sass file instead of the generated CSS file
  • syntax like {% asset "non-critical-styles" %} for linked CSS doesn't work anymore (there is nothing produced in the resulting HTML)

All these examples come from this include.

I don't know if these are known issues, or syntax changes I should make in my templates, I'll try to find out.

@flipacholas
Copy link

@nhoizey I also ran into a lot of problems with css (in my case with making autoprefixers work) and to be honest I started migrating to webpack to process sass and js some weeks ago, I don't regret it at all.

Jekyll-assets is a great plugin, but I ended up doing a lot of monkey-patching with ruby (to include code from pending pull-requests) and I also don't know what are the future prospects about this project, so I just offloaded the critical bits.

@nhoizey
Copy link
Contributor

nhoizey commented Nov 5, 2019

@flipacholas I wanted to migrate to Jekyll 4 to have a real project on which testing my own plugins, but I plan anyway to leave Jekyll for Eleventy, so it might not be worth losing time on this… 😢

I agree Jekyll-Assets is a great plugin I've been using for years, but Jekyll's future concerns me even more.

@nhoizey
Copy link
Contributor

nhoizey commented Nov 7, 2019

Asside from these parts missing in the output, I get build times around 600 seconds instead of 80 seconds with Jekyll 3, and a flame graph shows uglifier taking 80% of this build time.

@nhoizey
Copy link
Contributor

nhoizey commented Nov 7, 2019

It looks like it might be related to this sprockets issue: rails/sprockets#640

@lucascaton
Copy link

Any news on this?

@envygeeks
Copy link
Owner

Do we need to add Sprockets.export_concurrent = false?

@metrix78
Copy link
Author

metrix78 commented Mar 7, 2020

Looks like Sprockets has set export_concurrent to false by default: rails/sprockets#581

@envygeeks
Copy link
Owner

That's a little relieving! I'm gonna close this for now then since the specs are passing for both Sprockets 4, and Jekyll 4 on master. If this arises again please file a ticket!

NaanProphet added a commit to NaanProphet/tripodvideoninja that referenced this issue Mar 8, 2022
- rebuilding Gemfile.lock (i.e. delete it first and have it regen)
- kramdown v2 is now standard https://jekyllrb.com/docs/upgrading/3-to-4/
- jekyll-assets needs an unpublished version envygeeks/jekyll-assets#613 (comment)
- also upgrading jekyll-algolia in the same sweep
- pulling in the new defaults in the bottom part of the Gemfile (windows, performance-booster)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants