How to stop Parcel from removing and lowercasing svg viewBox attribute on production build?
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:
| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | ^1.8.1
| Node | 10.1.0
| npm/Yarn | npm 6.4.1
| Operating System | macos 10.12.6
The .posthtmlrc solution described here works for me without or even along with the .htmlnanorc config above. I'm on Parcel v1.10.3.
thanks @mateatslc, I upgraded Parcel and added .posthtmlrc, and it works as expected.
Adding the suggested configuration option to .posthtmlrc wasn't working for me, I had to turn off htmlnano's svg minification:
// .htmlnanorc
{
"minifySvg": false,
}
Most helpful comment
Adding the suggested configuration option to
.posthtmlrcwasn't working for me, I had to turn off htmlnano's svg minification: