cascornelissen / svg-spritemap-webpack-plugin

SVG spritemap plugin for webpack
MIT License
210 stars 51 forks source link

Add filepath as second param to `options.sprite.idify` #162

Closed dios-david closed 3 years ago

dios-david commented 3 years ago

Hello there! 👋

I recently started to use this great plugin, and I run into an issue: In my project the icons are organised in sub folders (e.g. actions, brands etc), and I would like to include the sub folder name in the generated ID (e.g. {subfolder}-{iconname}).

I noticed there is a way to provide a custom ID generator function in options.sprite.idify, but that only receives the file name of the icon as a parameter.

So I thought I could add the filepath as the second parameter for idify, which would help me to solve my issue without introducing a breaking change.

Please let me know if I missed anything!

cascornelissen commented 3 years ago

I may be wrong as I haven't done the initial implementation but https://github.com/cascornelissen/svg-spritemap-webpack-plugin/pull/61, and especially https://github.com/cascornelissen/svg-spritemap-webpack-plugin/pull/61#issuecomment-453736767, seem to have taken this into account.

sprite.idify is merely there to transform the filename to a valid HTML id. sprite.prefix can be used to generate a custom prefix for each sprite and that function does get the full path.

dios-david commented 3 years ago

Ah thanks, makes sense, I haven't noticed prefix accepts a function as well.