patrickhulce / fontmin-webpack

Minifies icon fonts to just the used glyphs.
MIT License
139 stars 19 forks source link

Add fontRegex configuration option #64

Open Moustachos opened 2 years ago

Moustachos commented 2 years ago

Add fontRegex option to control which file types should be processed by fontmin.

Default value: FONT_REGEX.

I didn't write any test for this because it doesn't change anything on lib behavior, it just adds more room for fine-tuning.

For example, in a project I have many SVG logos, but no SVG fonts, so it doesn't make much sense to try and find glyphs in these files.

With this option we can define which file types must be parsed at a project level :)

patrickhulce commented 2 years ago

Thanks for the contribution!

I didn't write any test for this because it doesn't change anything on lib behavior, it just adds more room for fine-tuning.

Test can be added that leverages this fine-tuning :) At the moment I'm not sure how this is useful, if we're picking up non-font SVGs in a way that generates bad output, that's a bug we should fix separately!

Moustachos commented 2 years ago

You're welcome!

In fact, I needed this feature in my project because I copy these SVG logos from my assets directory to my build directory using Webpack's .copyFiles() method.

It worked just fine on v3.2.0, but since https://github.com/patrickhulce/fontmin-webpack/pull/59 merge I get an error at this line: https://github.com/patrickhulce/fontmin-webpack/blob/master/lib/index.js#L93

The error was something like: Error: ENOENT: no such file or directory, open 'images/my-logo.svg'

The image exists, I didn't quite get why it used to work just fine before and removing svg from FONT_REGEX fixed my issue, so I came up with this PR.

But if you got a way to fix this error without my PR, it would be even better :)