使用Compass / Sass删除附加到sprite文件名的随机字符串 [英] Remove the random string appended to sprite filename with Compass/Sass

查看:129
本文介绍了使用Compass / Sass删除附加到sprite文件名的随机字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近使用Compass与Sass做一些CSS sprits,因为它非常有用。

I've recently been using Compass with Sass to do some CSS spriting, as it's extremely useful.

但是,文件名总是附加一个随机字符串。例如。 icons-s5eb424578c.png 。我不想要附加这个随机字符串,因为它意味着我需要上传新的CSS文件&

However, the filename is always appended with a random string. E.g. icons-s5eb424578c.png. And I don't want this random string to be appended, because it means I'm required to upload both the new CSS file & the new sprite image every time there's a change.

那么,有没有人知道Compass gem目录中的哪个Ruby或其他配置文件是附加这个随机字符串?然后我可以只是注释掉那个位的代码。除非我缺少一个官方变量,我可以在Compass中设置,告诉它我不想要这个字符串附加?

So, does anyone know which Ruby or other config file within the Compass gem directory, that is appending this random string? Then I can just comment the code out for that bit. Unless I'm missing an official variable I can set within Compass to tell it I don't want this string appended?

感谢您提供任何帮助。 / p>

Thanks in advance for any help on this.

推荐答案

在您的项目配置文件中输入如下

in your project config file enter something like this

asset_cache_buster :none

# Make a copy of sprites with a name that has no uniqueness of the hash.
on_sprite_saved do |filename|
  if File.exists?(filename)
    FileUtils.mv filename, filename.gsub(%r{-s[a-z0-9]{10}\.png$}, '.png')
  end
end

# Replace in stylesheets generated references to sprites
# by their counterparts without the hash uniqueness.
on_stylesheet_saved do |filename|
  if File.exists?(filename)
    css = File.read filename
    File.open(filename, 'w+') do |f|
      f << css.gsub(%r{-s([a-z0-9]{10})\.png}, '.png?v\1')
    end
  end
end

学分如何关闭COMPASS SASS缓存无效化?

这篇关于使用Compass / Sass删除附加到sprite文件名的随机字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆