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

How to stop Parcel from removing and lowercasing svg viewBox attribute in production? #2151

Closed
brianzelip opened this issue Oct 16, 2018 · 3 comments

Comments

@brianzelip
Copy link

brianzelip commented Oct 16, 2018

❔ Question

How to stop Parcel from removing and lowercasing svg viewBox attribute on production build?

πŸ”¦ Context

This issue relates to PostHTML, HTMLnano, SVGO, and has been reported at least via:

While many of the above issues have "closed", the issue hasn't actually found a solution.

The only solution that has come close is creating a .htmlnanorc file in the project root with the following content:

{
    "minifySvg": false
}

Yet this falls short, because the resulting attribute is renamed from viewBox to viewbox which renders it useless since browsers only understand viewBox.

This has affected me in such that I am unable to load fontawesome icons in my Parcel-built project.

Here is a screenshot of the production build, with the dev tools open inspecting the ghot svg - you can see in the devtools below that the svg is in the DOM, but not rendered on the page because the attribute is mis-named viewbox:

ghotst-svg

πŸ’» Code Sample

🌍 Your Environment

Software Version(s)
Parcel ^1.8.1
Node 10.1.0
npm/Yarn npm 6.4.1
Operating System macos 10.12.6
@brianzelip brianzelip changed the title How to stop Parcel from removing and lowercasing svg viewBox attribute? How to stop Parcel from removing and lowercasing svg viewBox attribute in production? Oct 16, 2018
@mateatslc
Copy link

The .posthtmlrc solution described here works for me without or even along with the .htmlnanorc config above. I'm on Parcel v1.10.3.

@brianzelip
Copy link
Author

thanks @mateatslc, I upgraded Parcel and added .posthtmlrc, and it works as expected.

@bbugh
Copy link

bbugh commented Feb 18, 2019

Adding the suggested configuration option to .posthtmlrc wasn't working for me, I had to turn off htmlnano's svg minification:

// .htmlnanorc
{
  "minifySvg": false,
}

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

No branches or pull requests

4 participants