css – 使用Compass / Sass删除附加到sprite文件名的随机字符串

我最近一直在使用Compass和Sass做一些CSS spriting,因为它非常有用.

但是,文件名始终附加随机字符串.例如.图标,s5eb424578c.png.而且我不希望附加这个随机字符串,因为这意味着我需要上传新的CSS文件和放大器.每当有变化时,新的精灵图像.

那么,有没有人知道Compass gem目录中的哪个Ruby或其他配置文件,即附加这个随机字符串?然后我可以只为该位注释代码.除非我错过了一个官方变量,否则我可以在Compass中设置告诉它我不希望附加这个字符串?

在此先感谢任何帮助.

解决方法

在您的项目配置文件中输入这样的内容
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

学分在这里How to remove the hash from Compass’s generated sprite image filenames?

相关文章

Css3如何实现鼠标移上变长特效?(图文+视频)
css3怎么实现鼠标悬停图片时缓慢变大效果?(图文+视频)
jquery如何实现点击网页回到顶部效果?(图文+视频)
css3边框阴影效果怎么做?(图文+视频)
css怎么实现圆角边框和圆形效果?(图文+视频教程)
Css3如何实现旋转移动动画特效