2createStudio / postcss-sprites

Generate sprites from stylesheets.
MIT License
413 stars 50 forks source link

Hook on spritesheet creation #66

Closed niksy closed 7 years ago

niksy commented 8 years ago

Would it make sense to have hook when spritesheet is created?

One use case for this is image optimization with tool like imagemin where you could act on spritesheet image buffer and optimize it before it is saved (similar to transform for postcss-copy). This could be done in separate process like Gulp plugin or plugin like postcss-copy, but it seems like this could be nice addition to whole sprite generate process.

I’m leaning to solution number 2; open to modification and left to developers and how they want to handle final output.


Example:

sprites({
    // ...
    hooks: {
        onSaveSpritesheet: ( opts, spritesheet ) => {
            return imagemin.buffer(spritesheet.image, {
                plugins: [
                    imageminPngquant()
                ]
            }).then(( buff ) => {
                return Object.assign({}, spritesheet, {
                    image: buff
                });
            });
        }
    }
})

What do you think? Is this too much?

vvasilev- commented 8 years ago

I think that will be a nice addition to the plugin. Can you make a PR for this one?

niksy commented 8 years ago

Sure, will get on it as soon as possible!

niksy commented 7 years ago

@vvasilev- I’ve made the PR https://github.com/2createStudio/postcss-sprites/pull/70

Sorry this took so long :/