upgrade sass-rails gem to 5.0 gives deprecation warning

前端 未结 3 982
野的像风
野的像风 2021-02-07 07:38

We upgraded to sass-rails version 5.0.0 and are getting this deprecation warning:

DEPRECATION WARNING: Extra .css in SCSS file is unnecessary. Rename /Users/foo/         


        
相关标签:
3条回答
  • 2021-02-07 07:53

    This handled it for me:

    #!/bin/sh
    for file in $(find ./app/assets/stylesheets/ -name "*.css.scss")
    do
        git mv $file `echo $file | sed s/\.css//`
    done
    
    0 讨论(0)
  • 2021-02-07 07:55

    This command helped me renaming lots of .css.sass files:

    find ./app/assets/stylesheets -type f | sed 'p;s/\.css\.scss/.scss/' | xargs -n2 git mv
    
    0 讨论(0)
  • 2021-02-07 08:01

    Yes you need to rename your .css.scss to just .scss, as .css.scss will not be supported in sprockets 4.

    If you want to suppress the deprecation temporary you can the following to config/initializer/deprecations.rb

    Rails.application.config.after_initialize do
      old_behaviour = ActiveSupport::Deprecation.behavior
      ActiveSupport::Deprecation.behavior = ->(message, callstack) {
        unless message.starts_with?('DEPRECATION WARNING: Extra .css in SCSS file is unnecessary.',
                                    'DEPRECATION WARNING: Extra .css in SASS file is unnecessary.')
          old_behaviour.each { |behavior| behavior[message,callstack] }
        end
      }
    end
    

    Or you can monkey patch to not to generate the message like this:

    module DisableCssDeprecation
      def deprecate_extra_css_extension(engine)
        if engine && filename = engine.options[:filename]
          if filename.end_with?('.css.scss','.css.sass')
            engine
          else
            super
          end 
        end
      end
    end
    
    module Sass ; module Rails ; class SassImporter
      prepend DisableCssDeprecation
    end ; end ; end
    
    0 讨论(0)
提交回复
热议问题