Using Compass generated sprites in Middleman, how to leave out sprite source files from the build?

StackOverflow https://stackoverflow.com/questions/9339024

  •  27-10-2019
  •  | 
  •  

Using Middleman 2.0.14, I use the Compass features to generate some sprites in my CSS file with:

@import "companies/*.png";
@include all-companies-sprites;

This takes all the files from source/images/companies/*.png and generates a single sprite file source/images/companies-s45e421528f.png. So far, so good.

When I do a middleman build, it dutifully copies over the generated image file, but also includes the companies/*.png files.

Its not a big deal to have a deployment script remove these extra files, but I wonder if there is an option I'm missing somewhere? (Or maybe the 'almost ready to release MM 3.x' has a solution?) Perhaps I should put the companies/*.png files somewhere else in the source tree?

有帮助吗?

解决方案

I suggest cleaning them up with a script (or an after_build hook). This is the default behavior of Compass, to generate images in development mode, and it would require some monkey patching to alter (for now, the Compass beta have direct access to these options).

In 3.0, you could try:

configure :build do
  ignore "source/images/companies/*.png"
end

But I'm not sure Compass wouldn't choke on that.

其他提示

Using ignore slowed down the build significantly for me so I preferred putting the sprite assets outside of source/.

This way, sprites are generated under source/sprites/, build/sprites and the sources are excluded without ignoreing it.

Here is how to set this up:

# config.rb

compass_config do |config|
    # tell Compass to load sprites from `project_root/sprites`
    config.sprite_load_path = 
      config.sprite_load_path
      .to_a
      .push(File.join root, 'sprites')
end 
# style.css.scss

@import "..sprites/companies/*.png";
@include all-companies-sprites;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top