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

Fix merging svgo config #384

Merged
merged 1 commit into from
Jan 20, 2020
Merged

Conversation

tardiva
Copy link
Contributor

@tardiva tardiva commented Jan 20, 2020

Summary

The only optimization we need in our project is prefixing ids. But when we tried to use the configuration below, we faced the problem - prefixes were added unexpectedly to the class names.

Use https://react-svgr.com/playground for reproducing the issue:

  • use simple svg example:
<svg height="100" width="100">
  <circle id="test" class="test" cx="50" cy="50" r="40" fill="red"/>
</svg>
  • add svgo config:
{ 
"full": true,
"plugins": [{ "prefixIds": {"prefixIds": true, "prefixClassNames": false} }]
}
  • check the output and note that both id and class have prefixes

This PR fixes the issue and allows to configure prefixIds plugin in more flexible way.

Test plan

New test case was added for plugin-svgo

@vercel
Copy link

vercel bot commented Jan 20, 2020

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/gregberge/svgr/5az8wdkxu
✅ Preview: https://svgr-git-fork-tardiva-fix-prefix-ids.gregberge.now.sh

@codecov
Copy link

codecov bot commented Jan 20, 2020

Codecov Report

Merging #384 into master will increase coverage by 0.37%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #384      +/-   ##
==========================================
+ Coverage   85.14%   85.52%   +0.37%     
==========================================
  Files          30       30              
  Lines         505      518      +13     
  Branches      140      142       +2     
==========================================
+ Hits          430      443      +13     
  Misses         62       62              
  Partials       13       13
Impacted Files Coverage Δ
packages/plugin-svgo/src/index.js 72.88% <100%> (+7.66%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6d2eab6...ef885a8. Read the comment docs.

Copy link
Owner

@gregberge gregberge left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@gregberge gregberge merged commit c9d2dfc into gregberge:master Jan 20, 2020
@doctyper
Copy link

FYI this is a breaking change if you have an existing custom Webpack configuration. I had to update my config to fix it:

  use: [
    {
      loader: require.resolve('@svgr/webpack'),
      options: {
        svgoConfig: {
-          plugins: { removeViewBox: false },
+          plugins: [{ removeViewBox: false }],
        },
      },
    },
  ],

@gregberge
Copy link
Owner

Yeah but your configuration was not correct IMO, plugins should always be an array.

@samuelmeuli
Copy link
Contributor

samuelmeuli commented Jan 23, 2020

Had the same issue.

I also used this the config for the removeViewBox option. When I introduced the dependency, I probably found out about the option because of #142 or #18. The answer in both issues uses an object for plugins, not an array. These answers both have a significant number of upvotes, so I'm expecting things to break silently for quite a few users who copied these configurations.

IMO, it would be a good idea to at least throw an error if an incorrect config is found. I can work on a PR if you'd like :)

@doctyper
Copy link

Yes some clear documentation on Webpack configuration would be helpful.

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.

4 participants