sass-contrib / sass-embedded-host-ruby

:gem: A Ruby library that will communicate with Embedded Dart Sass using the Embedded Sass protocol
https://rubygems.org/gems/sass-embedded
MIT License
67 stars 5 forks source link

How to set sass options for silencing deprecations? #265

Closed javierjulio closed 3 days ago

javierjulio commented 3 days ago

I'm using sassc-embedded in a Rails app to update foundation-sites and foundation-emails to new versions that require Dart Sass which I'm very close to and will eventually swap to using sass-embedded directly. Thank you.

I don't believe I've ever had to set sass options before even when I used sass-rails v6 so the examples here suggest we should be compiling our sass directly but when using sprockets-rails it would be handled automatically. So it's confusing and unclear how I would change one of the options if I'm not directly calling the compile method.

With this gem, how do we set a sass option, for example quiet_deps to silence deprecation warnings, when using the sassc-embedded gem? And then again when using the sass-embedded gem directly? Both would be alongside sprockets-rails only. We are not using dartsass-sprockets and we have removed sassc-rails.

ntkme commented 3 days ago

If you're using sass-embedded completely standalone:

require 'sass-embedded'

Sass.compile('application.scss', quiet_deps: true).css

Sass.compile_string(sass, quiet_deps: true).css

If you're using sassc-embedded completely standalone:

require 'sassc-embedded'

SassC::Engine.new(sass, quiet_deps: true).render

If you're using sprockets-rails + sassc-embedded without sassc-rails or dartsass-sprockets:

    config.assets.configure do |env|
      sass_config = {
        quiet_deps: true
      }
      env.register_transformer 'text/sass', 'text/css', Sprockets::SasscProcessor.new({ sass_config: })
      env.register_transformer 'text/scss', 'text/css', Sprockets::ScsscProcessor.new({ sass_config: })
    end

In addition to quiet_deps, you may also want to use silence_deprecations option.

javierjulio commented 3 days ago

@ntkme thank you. That worked. I had tried several attempts at a monkey patch but failed. Thank you again. Once we are ready to replace sassc-embedded with sass-embedded, can we still use sprockets-rails with sass-embedded as we did with sassc-embedded? Or it won't work and our we have to migrate to dartsass-rails?

ntkme commented 3 days ago

sprockets does not have direct integration for sass-embedded's new API, which is why sassc-embedded was created in the first place - to emulate the old SassC API so that sass-embedded can be used with nearly all existing code.

Current options for rails are:

I previously said in https://github.com/sass/sassc-ruby/issues/220 that sassc-embedded will not be supported after @import gets dropped. However, the situation has changed since https://github.com/sass/sass/pull/3688, which made it possible to support sassc-embedded in long term, and it will have support as long as it is technically feasible.

sassc-embedded won't get all the new features in sass-embedded's new Ruby API, but it should still be enough for majority of the use cases, so there is no need to rush on getting rid of sassc-embedded if you still prefer sprockets.

javierjulio commented 3 days ago

Thank you, that breakdown is very helpful. Basically, the conclusion I came to on my own. The main concern is still having JS compiled and served through sprockets that cannot be easily migrated so looking for options to stick with sprockets for now. Otherwise, I'd just migrate to dartsass-rails and propshaft. Thank you again for the help and these libraries.