Skip to content

Use svgr for SVGs - #244

Merged
swissspidy merged 6 commits into
masterfrom
simplify/svg
Feb 12, 2020
Merged

swissspidy merged 6 commits into
masterfrom
simplify/svg

Conversation

@swissspidy

Copy link
Copy Markdown
Collaborator

Less magic, less dependencies, less security warnings.

See WordPress/gutenberg#18243

Less magic, less dependencies, less security warnings.

See WordPress/gutenberg#18243
@barklund

barklund commented Feb 6, 2020

Copy link
Copy Markdown
Contributor

What's the improvement here? Don't really see it in the linked GB issue.

@swissspidy

Copy link
Copy Markdown
Collaborator Author

We currently use s combination of a webpack loader and a Babel plugin for this, which are both pretty much unmaintained and also cause warnings to be raised by npm‘s audit command.

The linked PR shows that we can simplify this by using the more maintained svgr library which is now integrated in the wp-scripts suite of tools.

@barklund

barklund commented Feb 6, 2020

Copy link
Copy Markdown
Contributor

We currently use s combination of a webpack loader and a Babel plugin for this, which are both pretty much unmaintained and also cause warnings to be raised by npm‘s audit command.

The linked PR shows that we can simplify this by using the more maintained svgr library which is now integrated in the wp-scripts suite of tools.

Sounds good with me!

The syntax is a little crude though - is there anyway to make the named ReactComponent export the default one? Though it doesn't sound like it.

@swissspidy

swissspidy commented Feb 6, 2020 •

Copy link
Copy Markdown
Collaborator Author

I thought not, but maybe it is possible: https://react-svgr.com/docs/webpack/#usage

I'll check again.

Edit: looks like that's indeed intended behavior: the default export is for
the source link that can be used in an img, and ReactComponent is for using as a component

@swissspidy
swissspidy marked this pull request as ready for review February 7, 2020 15:19
@swissspidy swissspidy added Type: Infrastructure Changes impacting testing infrastructure or build tooling Type: Enhancement New feature or improvement of an existing feature labels Feb 7, 2020
@swissspidy

swissspidy commented Feb 7, 2020 •

Copy link
Copy Markdown
Collaborator Author

Just noticed some issues where icons are cropped. I'll take a look at that.

Edit: resolved in 2543566

@dvoytenko

Copy link
Copy Markdown
Contributor

@swissspidy How did you get these SVG changes done? Is there some linter/commit hook for that?

@swissspidy

Copy link
Copy Markdown
Collaborator Author

You mean the removal of width/height attributes? Manually. But there might be a svgr config for that. Will check!

And changing the imports, well, without that the editor wouldn‘t run. But perhaps the linter might help there too, will check that.

@dvoytenko

Copy link
Copy Markdown
Contributor

You mean the removal of width/height attributes? Manually. But there might be a svgr config for that. Will check!

And changing the imports, well, without that the editor wouldn‘t run. But perhaps the linter might help there too, will check that.

Width/height and currentColor. I think it'd be enough to simply error out to remove manually.

@swissspidy

Copy link
Copy Markdown
Collaborator Author

Sounds good! I‘ll see whether it warrants a new PR or not.

@dvoytenko

Copy link
Copy Markdown
Contributor

otherwise lgtm

@barklund barklund left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If it's better, it's better!

#welcometotautologyclub

@swissspidy

Copy link
Copy Markdown
Collaborator Author

@dvoytenko Done in 76aff44 🎉

@swissspidy
swissspidy merged commit 500bc71 into master Feb 12, 2020
@swissspidy
swissspidy deleted the simplify/svg branch February 12, 2020 10:29
Comment thread .svgo.yml
Comment on lines +3 to +5
- removeDimensions: true
- convertColors:
currentColor: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is awesome magic! Love it!

@spacedmonkey spacedmonkey mentioned this pull request Feb 13, 2020
2 of 5 tasks
swissspidy added a commit that referenced this pull request Feb 13, 2020
swissspidy added a commit that referenced this pull request Feb 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Enhancement New feature or improvement of an existing feature Type: Infrastructure Changes impacting testing infrastructure or build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants