Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add svgo #16

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

add svgo #16

wants to merge 4 commits into from

Conversation

KubaJastrz
Copy link
Contributor

Fixes #7

Description

Add SVGO for svg optimizations.

Type of change

Please mark relevant options with an x in the brackets.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Algorithm update - updates algorithm documentation/questions/answers etc.
  • Other (please describe):

How Has This Been Tested?

Tested against the remix-vite test app with basic-shapes.svg and looking at the output.

  • Integration tests
  • Unit tests
  • Manual tests
  • No tests required

Reviewer checklist

Mark everything that needs to be checked before merging the PR.

  • Check if the UI is working as expected and is satisfactory
  • Check if the code is well documented
  • Check if the behavior is what is expected
  • Check if the code is well tested
  • Check if the code is readable and well formatted
  • Additional checks (document below if any)

Screenshots (if appropriate):

Questions (if appropriate):

I don't know why the other changes to dependencies are included, must be
auto-generated by npm.
formatting the output sprite would cause the empty symbols to be
deleted, which is probably not what we want
can probably use a better description though
@KubaJastrz KubaJastrz changed the title add basic-shapes for testing add svgo Jul 26, 2024
@@ -1,3 +1,3 @@
<svg>
<svg xmlns:xlink="http://www.w3.org/1999/xlink">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this, svgo would yell at me

SvgoParserError: <input>:2:24: Unbound namespace prefix: "xlink"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need to take a deeper dive into this PR before I merge it in, so what will svgo do by default here when ran alongside the plugin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this error? Crash the plugin and build sadly :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, maybe leaving a comment here specifically was a bad idea, this was more of a general question of what will happen when I merge this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Svgo is an svg minification tool. This implementation will optimize each svg file individually right before it's being included in the spritesheet as a symbol.

Users can opt-out of Svgo or customize its config by passing the options through the plugin config. I don't know if Svgo can pick up the default svgo.config.js, will have to check.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is good because using xlink:href inside an <svg> element that doesn't have xmlns:xlink is probably invalid, that's why SVGO was complaining.

Comment on lines +97 to +100
svgo?: {
enabled?: boolean;
options?: SvgoConfig;
};
Copy link

@silvenon silvenon Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion for an alternative API:

Suggested change
svgo?: {
enabled?: boolean;
options?: SvgoConfig;
};
svgo?: boolean | SvgoConfig

to simplify, and also eliminate this impossible state:

{
  svgo: {
    enabled: false,
    options: {
      // ...
    }
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's a pretty good idea

@silvenon
Copy link

silvenon commented Aug 16, 2024

However, I don't know how much you'd be gaining from SVGO in this situation, published icons are probably already optimized. Although many are exported from Figma, so those aren't optimized, for them it might be good to optimize.

Also, here you're running SVGO for each icon, and for performance SVGO might be best run once per entire SVG sprite (with special care for default options like cleanupIds), but that seems like a job better suited for vite-plugin-svgo for people to do it at their own risk. I don't know whether it's worth it to include SVGO as a dependency of this plugin.

Anyway, that's all from me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Svg minification
3 participants