Skip to content

Problems when other gems depend on sass-rails #6

New issue

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

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

Already on GitHub? # to your account

Closed
constantm opened this issue Apr 9, 2015 · 17 comments
Closed

Problems when other gems depend on sass-rails #6

constantm opened this issue Apr 9, 2015 · 17 comments

Comments

@constantm
Copy link

I've been struggling to get sassc to work with Rails for quite some time but with little luck. Tonight I thought I'd give it a try again, but a quick Google lead me to this repo. Woo!

Unfortunately I can't see any sort of increase in the speed that my scss files compile after changing them. Is there some extra configuration necessary after installing the gem?

@bolandrm
Copy link
Member

Hey! This gem is very much a work in progress. Your mileage may vary.

It seems that your project isn't using sassc-rails to compile. Could you try some of the following:

  • remove sass-rails
  • after bundling, double check that sass-rails is not present
  • remove cache assets folder
  • spring stop? restart server?

@constantm
Copy link
Author

Had a quick look and it seems that sass-rails is still getting included because of ActiveAdmin's dependency on it. I forked ActiveAdmin and replaced the dependencies on sass-rails with sassc and it works perfectly now. Obviously that's not the best way to go about doing things - is there some way that you're aware of to do this in a more sustainable way?

@bolandrm bolandrm changed the title YAY! Super excited about this gem. No increase in speed though. :/ Problems when other gems depend on sass-rails Apr 29, 2015
@bolandrm
Copy link
Member

bolandrm commented May 3, 2015

@constantm I've released version 0.0.6, which I believe addressed this problem. If you have both installed, sassc-rails should override sass-rails. Please give it a shot and let me know how it goes!

@bolandrm bolandrm closed this as completed May 3, 2015
@bolandrm bolandrm reopened this May 4, 2015
@bolandrm
Copy link
Member

bolandrm commented May 4, 2015

I had to revert the changes here, i'm trying this out:

in an initializer: config/initializers/sassc_rails.rb

Rails.application.assets.register_engine '.sass', SassC::Rails::SassTemplate
Rails.application.assets.register_engine '.scss', SassC::Rails::ScssTemplate

@bolandrm
Copy link
Member

I ran into some more issues with this. I had to add the following to the initializer in the previous comment:

# config/initializers/sassc_rails.rb

require "sprockets/engines"

module Extensions
  module Sprockets
    module Engines
      def register_engine(ext, klass)
        return if [
          Sass::Rails::SassTemplate,
          Sass::Rails::ScssTemplate
        ].include?(klass)

        super
      end
    end
  end
end

Sprockets::Base.send(:prepend, Extensions::Sprockets::Engines)

Rails.application.assets.register_engine '.sass', SassC::Rails::SassTemplate
Rails.application.assets.register_engine '.scss', SassC::Rails::ScssTemplate

@bolandrm
Copy link
Member

i'd welcome anyone else's thoughts on a more permanent solution - do we simply include the about in the sassc-rails railtie?

@brainopia
Copy link
Contributor

@bolandrm here you go :)

bolandrm added a commit that referenced this issue Jul 25, 2015
Prevent sass-rails railtie from running, fixes #6
@bolandrm bolandrm reopened this Jul 29, 2015
@bolandrm
Copy link
Member

Testing against my rails project, this issue does not seem to be resolved yet.

@brainopia
Copy link
Contributor

I can help to investigate. In my project the problem was that a sass rails initializer was setting up sprocket engines.

In your case were sprocket engines pointing to sass instead of sassc? If so, than can you check separately whether sass-rails initializer was ran or not.

If not then you need to track where they're registered from (like you did with your monkeypatch of register_engine) .
If yes, then tell me what rails version do you use? And then I'll check whether a different railtie loading mechanism is used there compared to latest rails.

@rstacruz
Copy link

The workaround doesn't help for me, btw. I've placed it in config/initializers, register_engine never gets called for Sass::Rails.

@rstacruz
Copy link

I have a cleaner workaround to propose:

# Gemfile
gem 'sass-rails', require: false
gem 'sassc-rails'

This ensures that sass-rails is not automatically require'd, making sassc-rails take over. This of course won't work if a gem explicitly requires sass-rails.

@bolandrm
Copy link
Member

updated to this:

# config/initializers/sassc_rails.rb

require "sprockets/engines"

module Extensions
  module Sprockets
    module Engines
      def register_engine(ext, klass)
        return if [
          Sass::Rails::SassTemplate,
          Sass::Rails::ScssTemplate
        ].include?(klass)

        super
      end
    end
  end
end

Sprockets::Base.send(:prepend, Extensions::Sprockets::Engines)

# Rails.application.assets.register_engine '.sass', SassC::Rails::SassTemplate
# Rails.application.assets.register_engine '.scss', SassC::Rails::ScssTemplate

Rails.application.config.assets.configure do |env|
  env.register_engine '.sass', SassC::Rails::SassTemplate
  env.register_engine '.scss', SassC::Rails::ScssTemplate
end

@mibamur
Copy link

mibamur commented Jun 27, 2016

@bolandrm last comment
and

gem 'sass-rails', require: false
gem 'sassc-rails', github: 'sass/sassc-rails'

worked fine

mibamur added a commit to mibamur/sassc-rails that referenced this issue Jun 27, 2016
depend on sass#6
but here - more clear sass#68
@pinzonjulian
Copy link

Hi! Has a permanent fix for this issue been made? I really want to use SassC in my project!

@wesley6j
Copy link

wesley6j commented Feb 4, 2017

config/initializers/sassc_rails.rb does not work for me. It has conflicts with slim-rails. Since in my project the only gem that requires sass-rails is activeadmin, I updated the dependency of activeadmin and it works really well: activeadmin with sassc-rails

@jmdfm
Copy link

jmdfm commented Apr 4, 2018

register_engine has been deprecated in Sprockets 3, so I had to use the following initializer to work with Rails 5 and Sprockets 4:

Rails.application.config.assets.configure do |env|
  env.register_mime_type 'text/css', extensions: ['.scss'], charset: :css
  env.register_mime_type 'text/css', extensions: ['.css.scss'], charset: :css
  env.register_preprocessor 'text/css', SassC::Rails::ScssTemplate
end

@Marcellllll
Copy link

The initializer isn't working for me. I get an error: uninitialized constant SassC

Any idea how I could fix this ? I would really like to use sassc.

jrochkind added a commit to samvera/browse-everything that referenced this issue Nov 19, 2018
A Rails app is generated with a sass-rails dependency, so no changes to tests were needed -- the engine-cart-generated test app adds it's own sass-rails dependency.

While current Rails releases generate with sass-rails dependency, sass-rails is sunsetted/deprecated, due to the underlying pure-ruby ruby-sass gem being deprecated, and instructs "consider switching to the sassc gem"  https://github.com/sass/ruby-sass .

Rails 6.0 will perhaps depend on the sassc-rails gem instead, or perhaps the sass-rails gem itself will be changed to depend on sassc instead of sass-ruby. I am not sure if it is yet determined/done. rails/rails#3289

But apps now may wish to switch to sassc-rails, especially if it's a new app. While sassc-rails _ought_ to be a drop-in replacement, bugs can happen, and the timeline of switching (or refraining from switching) should be up to a dependent app.  However, if an app depends on both sass-rails and sassc-rails, problems can occur. sass/sassc-rails#6

So, removing the sass-rails as an explicit dependency from browse-everything will allow dependent apps to choose sass-rails or sassc-rails themselves, switching on their own timeline, without the browse-everything dependency interfering. This change is unlikely to pose any backwards compatibility problems, as dependent apps should have sass-rails in their Gemfile already, as it is generated by Rails. In the unlikely event some dependent app did not have sass-rails independently declared as a dependency, however, they would have to add it."
jrochkind added a commit to samvera/browse-everything that referenced this issue Nov 19, 2018
A Rails app is generated with a sass-rails dependency, so no changes to tests were needed -- the engine-cart-generated test app adds it's own sass-rails dependency.

While current Rails releases generate with sass-rails dependency, sass-rails is sunsetted/deprecated, due to the underlying pure-ruby ruby-sass gem being deprecated, and instructs "consider switching to the sassc gem"  https://github.com/sass/ruby-sass .

Rails 6.0 will perhaps depend on the sassc-rails gem instead, or perhaps the sass-rails gem itself will be changed to depend on sassc instead of sass-ruby. I am not sure if it is yet determined/done. rails/rails#3289

But apps now may wish to switch to sassc-rails, especially if it's a new app. While sassc-rails _ought_ to be a drop-in replacement, bugs can happen, and the timeline of switching (or refraining from switching) should be up to a dependent app.  However, if an app depends on both sass-rails and sassc-rails, problems can occur. sass/sassc-rails#6

So, removing the sass-rails as an explicit dependency from browse-everything will allow dependent apps to choose sass-rails or sassc-rails themselves, switching on their own timeline, without the browse-everything dependency interfering. This change is unlikely to pose any backwards compatibility problems, as dependent apps should have sass-rails in their Gemfile already, as it is generated by Rails. In the unlikely event some dependent app did not have sass-rails independently declared as a dependency, however, they would have to add it."
@bolandrm bolandrm closed this as completed May 3, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants