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

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

但是,文件名始终附加随机字符串。 例如icons-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 

学分转到这里如何从Compass生成的精灵图像文件名中删除哈希?

尝试将这些行添加到config.rb

 module Compass::SassExtensions::Functions::Sprites def sprite_url(map) verify_map(map, "sprite-url") map.generate generated_image_url(Sass::Script::String.new(map.name_and_hash)) end end module Compass::SassExtensions::Sprites::SpriteMethods def name_and_hash "sprite-#{path}.png" end def cleanup_old_sprites Dir[File.join(::Compass.configuration.generated_images_path, "sprite-#{path}.png")].each do |file| log :remove, file FileUtils.rm file ::Compass.configuration.run_sprite_removed(file) end end end module Compass class << SpriteImporter def find_all_sprite_map_files(path) glob = "sprite-*{#{self::VALID_EXTENSIONS.join(",")}}" Dir.glob(File.join(path, "**", glob)) end end end 

适用于Compass 0.12.2 (Alnilam)