paolochiodi / htmlcompressor

A work in progress port of google's htmlcompressor.jar
Other
150 stars 26 forks source link

No CSS Compressor. Please set the :css_compressor option #38

Closed maxrosecollins closed 6 years ago

maxrosecollins commented 7 years ago

My settings are as follows

require 'htmlcompressor'
Rails.application.configure do

  # Strip all comments from JavaScript files, even copyright notices.
  # By doing so, you are legally required to acknowledge
  # the use of the software somewhere in your Web site or app:
  uglifier = Uglifier.new output: { comments: :none }

  # To keep all comments instead or only keep copyright notices (the default):
  # uglifier = Uglifier.new output: { comments: :all }
  uglifier = Uglifier.new output: { comments: :copyright }

  config.assets.compile = true
  config.assets.debug = false

  config.assets.js_compressor = uglifier
  config.assets.css_compressor = :sass

  config.middleware.use Rack::Deflater
  config.middleware.insert_before ActionDispatch::Static, Rack::Deflater

  config.middleware.use HtmlCompressor::Rack,
    compress_css: true,
    css_compressor: :sass,
    compress_javascript: true,
    javascript_compressor: uglifier,
    preserve_line_breaks: false,
    remove_comments: true,
    remove_form_attributes: false,
    remove_http_protocol: false,
    remove_https_protocol: false,
    remove_input_attributes: true,
    remove_intertag_spaces: false,
    remove_javascript_protocol: true,
    remove_link_attributes: true,
    remove_multi_spaces: true,
    remove_quotes: true,
    remove_script_attributes: true,
    remove_style_attributes: true,
    simple_boolean_attributes: true,
    simple_doctype: false
end

But I am getting the following error No CSS Compressor. Please set the :css_compressor option

evgeniy-khlopin commented 6 years ago

@maxrosecollins are there any updates about this issue?

paolochiodi commented 6 years ago

As you may have noticed I'm not spending much time on the gem. However, I plan to spend some time on it during the festivities and will check this issue as well.

paolochiodi commented 6 years ago

Sorry I should have figured out this earlier: htmlcompressor only supports yui as the css compressor. A PR I merged today make the error more clear in this situation (with a different messages for "option not set" and "compressor not found".

htmlcompressor also accepts an object as a parameter for the css_compressor option: this can be used to make it work with other compressors. The only thing required is for the object to have a compress method that will receive the content to compress and returns compressed content