将Sass-rails gem升级到5.0会提供弃用警告 [英] upgrade sass-rails gem to 5.0 gives deprecation warning
问题描述
我们已升级到sass-rails版本5.0.0,并收到此弃用警告:
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/Projects/foo/app/assets/stylesheets/foo.css.scss to /Users/foo/Projects/foo/app/assets/stylesheets/foo.scss. (called from _app_views_layouts_application_html_erb__1560597815210891605_70190441246060 at /Users/foo/Projects/foo/app/views/layouts/application.html.erb:13)
有人知道这是怎么回事吗?宝石真的要我从以下位置重命名所有样式表资源吗?
Anyone know whats going on with this? Does the gem really want me to rename all of my stylesheet assets from:
app/assets/stylesheets/foo.css.scss
收件人:
app/assets/stylesheets/foo.scss
?
在我看来似乎违反了多年的Rails惯例.也许有一种方法可以抑制过时警告?
Seems to run against years of Rails convention to me. Perhaps there is a way to suppress the deprecation warning?
推荐答案
是的,您需要将.css.scss
重命名为.scss
,因为链轮4不支持.css.scss
.
Yes you need to rename your .css.scss
to just .scss
, as .css.scss
will not be supported in sprockets 4.
如果您想暂时取消弃用,则可以在config/initializer/deprecations.rb
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
这篇关于将Sass-rails gem升级到5.0会提供弃用警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!