envygeeks / jekyll-assets

:art: Asset pipelines for Jekyll.
ISC License
1.11k stars 169 forks source link

CSS compression does not work #514

Open rluba opened 6 years ago

rluba commented 6 years ago

Description

I use jekyll-assets to compile scss to css ({% asset main.css %} with a main.scss asset). But the resulting CSS is not compressed (neither in production nor development) when following the suggestion in the readme to use sprockets 4:

gem "sprockets", "~> 4.0.beta", {
  require: false
}

It works when using sprockets 3 (but then of course without sourcmaps).

Also: when using sprockets 4, source maps are generated within .site/assets but they are not referenced in the css file, so the browser doesn’t use them.

envygeeks commented 6 years ago

Please provide a repository with only Jelyll Assets, and Jekyll; that can replicate the issue.

rluba commented 6 years ago

Here you go: https://github.com/rluba/jekyll-assets-css-compression

While trying to reproduce the problem, I noticed that it’s a combination of sprockets v4 and autoprefixer-rails that causes the problem. If you either downgrade to sprockets v3. or remove autoprefixer-rails the CSS will be minified. But as soon as you enable both, the CSS is not minified.

caleb531 commented 6 years ago

@envygeeks I'm experiencing the same issue—my CSS is compiling from Sass, but the output file is not compressed. I am using jekyll-assets v3.0.8 but am not using autoprefixer-rails.

Here are the relevant lines from my _config.yml:

sass:
  style: :compressed
assets:
  sources:
    - _assets

(I have my sass files under _assets/styles)

envygeeks commented 6 years ago

I'll take a few days to consider people's opinions but Autoprefixer is probably gonna be cast out into the wind as buggy soon, rather than me having to do all the extra stuff I have to do work around it (like the nigmare code I had to write to get SourceMaps to work with it.) I feel no need to maintain extra logic in my compressors, and other code to work around a change they made that breaks literally everything else.

rluba commented 6 years ago

I can understand your frustration and I don’t expect you to throw good voluntary work after bad. Just a thought: Would it be easier to enable autoprefixer only in production mode – and ditch the source maps in that case? (Unfortunately, I don't know an alternative to autoprefixer.)

envygeeks commented 6 years ago

/cc @devraj for an opinion since I think this directly affects them.

deepfriedbrain commented 6 years ago

I'm also not using autoprefix-rails and CSS compression is not working for me. The sprockets version if 4.0.0.beta7 and jekyll-assets version if 3.0.11.

xRahul commented 6 years ago

How do I revert then? Anyone able to revert versions and compress?

envygeeks commented 6 years ago

I'm the only one with that power. I will not be reverting anything, provide more information, including debug logs, so that the bug can be fixed. If it's caused by autoprefixer-rails, file the bug with them, and Sprockets, I will no longer be working around the two issues that have surfaced this with Autoprefixer because I feel it's up to them to solve this problem, if it's not caused by autoprefixer-rails please file a new ticket with your own debug logs.

envygeeks commented 6 years ago

I will however concede that I am gonna see if I can implement @rluba idea, thought I don't know if it's possible unless we skip our processors entirely, but since we don't need SourceMaps it's probably easy to do. I just haven't had time to look into it.

xRahul commented 6 years ago

Hey guys, it worked for me. I have upgraded my ruby version to 2.5.1. And this is my setting:

# Important settings
assets:
  digest: false
  source_maps: true
  compression: true
  gzip: true
  plugins:
    css: { autoprefixer: {}}
    img: { optim: {jpegoptim: {strip: all}}}
  autoprefixer:
    browsers:
    - "last 2 versions"
    - "IE > 9"
  sources:
    - node_modules
    - _assets/javascripts
    - _assets/stylesheets
  baseurl: https://rahulja.in

Gemfile

source "https://rubygems.org"

gem "html-proofer"
gem "jekyll"
gem "jekyll-assets"
gem "jekyll-paginate-v2"
gem "jekyll-sitemap"
gem "jemoji"
gem "mini_magick"
gem "sass"
gem "uglifier"
gem "font-awesome-sass"
gem 'jekyll-feed'
gem 'jekyll-redirect-from'
gem 'jekyll-gist'
gem 'jekyll-seo'
gem 'jekyll-seo-tag'
gem 'jekyll-last-modified-at'
gem "sprockets", "4.0.0.beta7"
gem "image_optim"
gem "image_optim_bin" # Optional
gem "image_optim_pack"
gem "autoprefixer-rails"
gem "amp-jekyll"
gem "rouge"
gem "sanitize"
gem "crass"
morungos commented 5 years ago

This issue is still present, as far as I can tell. I'm using:

JS minifying works fine. CSS isn't, even when using, env JEKYLL_ENV=production bundle exec jekyll build.

If anyone can think of a workaround (in non-ruby-wizard detail), I'd be keen to hear it. Right now, this is something of a blocker, since my generated CSS is far and away the largest asset. Again, I can live without sourcemaps.

Config is as follows:

assets:
  digest: false
  source_maps: true
  compression: true
  gzip: true
  plugins:
    css: { autoprefixer: {}}
    img: { optim: {jpegoptim: {strip: all}}}

  autoprefixer:
    browsers:
    - "last 2 versions"
    - "IE > 9"

If I remove the autoprefixing, I don't get the hashing, and even though I do get .gz files (which I don't with autoprefixing there), but even the .gz files are unpacked CSS (while properly gzipped). I also get the sourcemaps. It just seems that none of the sass compression, as opposed to the gzip compression, happens, under any circumstances.