twolfson/grunt-spritesmith

Prevent sprite generation if no source images present

Closed this issue · 2 comments

I've read the documentation and I can't see anything for this, so I thought I'd raise it as an issue. In our case, a modular boilerplate/framework we maintain uses spritesmith as part of the Grunt set-up.

When it's used to create a new project it is incredibly likely that there will be no images at the source, meaning a 0 sized PNG will be created.

It would be great if spritesmith could not generate the PNG in this case. 👍

Not sure whether it's really relevant, but here is our spritesmith config:

module.exports = {
    all: {
        src: [
            '<%= siteInfo.assets_path %>/<%= siteInfo.img_dir %>/*.png',
            '!<%= siteInfo.assets_path %>/<%= siteInfo.img_dir %>/sprite.png'
        ],
        dest: '<%= wpInfo.wp_content %>/themes/<%= wpInfo.theme_name %>/<%= wpInfo.img_dir %>/sprite.png',
        destCss: '<%= siteInfo.assets_path %>/<%= siteInfo.sass_dir %>/base/_sprites.scss',
        // Add a cache busting timestamp to the file name
        imgPath: '<%= wpInfo.assets_dir %>/<%= wpInfo.img_dir %>/sprite.png?' + ( new Date().getTime() ),
    }
};

Unfortunately, this was a decision made early on. The reasoning is that we should provide consistent behavior for generating an image (even when nothing is provided). This seems to be consistent with canonical grunt plugins like grunt-contrib-concat.

https://github.com/gruntjs/grunt-contrib-concat

Could you explain why you don't want an image being created?

hey @twolfson

It's more of a housekeeping thing more than anything else to be honest. Thanks for the quick reply!