webpack-spritesmith
webpack-spritesmith copied to clipboard
how to set max size, sometimes the generated sprite.png is too big
how to set max size, sometimes the generated sprite.png is too big
I think you can't. Not via options anyway. If you could though it would be in spritesmithOptions
.
You can split your set of source images though, and create multiple instances of the plugin.
@mixtur same question here, and find a solution, just see see.
this line
https://github.com/mixtur/webpack-spritesmith/blob/be950b3ce0d7f76ae6cc7b02a23dcf8578315926/src/Plugin.js#L94
add a filter
function as options of src
// Plugin.js
const allSourceImages = Object.values(sourceImagesByFolder)
.reduce((allFiles, files) => [ ...allFiles, ...files ], [])
.filter(x => !x.endsWith(path.sep))
+ .filter(x=> typeof this.options.src.filter === 'function' ? this.options.src.filter(x): true)
then use it in configs like
// webpack.config.js
new Spritesmith({
src: {
cwd: path.resolve(globals.ImageDirectory, dir),
glob: '*.png',
filter: (f)=>fs.statSync(f).size < 10 * 1024 // limit to less than 10kb
},
target: {image:{/*....*/}}
})
just solve my problem. @echolove38 have a try try...