-
Notifications
You must be signed in to change notification settings - Fork 29
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
Does not minify svgs that have the <use> tag in them #47
Comments
The issue seems to be related to SVGO's default settings which seem to be too aggressive in minimizing. |
@voischev @Scrum @maltsev We need this feature for @parcel-bundler. It's currently causing issues for our users. 😞 |
@bencooper222 @davidnagli Thanks for ping, I'll try to figure this out soon. Let me know if you find a solution ahead of me :) |
At the moment I recommend using htmlnano with settings for svgo: minifySvg: {
plugins: [
{ cleanupIDs: false },
{ removeUnknownsAndDefaults: false},
]
} see example
yep |
related to work svg/svgo#921 |
Edit: Resolved in htmlnano 0.1.7, it errors In my case, the entire For example <!DOCTYPE html><svg><use xlink:href="./file.svg"/></svg> Becomes <!DOCTYPE html>undefined Here's a one-line CLI test: node -e 'require("htmlnano").process(\'<!DOCTYPE html><svg><use xlink:href="./file.svg"/></svg>\').then(result => console.log(result.html));'
<!DOCTYPE html>undefined |
I updated all dependencies and released version 0.1.7. Now |
@bfred-it |
@maltsev I think my issue here was the lack of This works: <!DOCTYPE html>
<svg xmlns:xlink="http://www.w3.org/1999/xlink">
<use xlink:href="./file.svg"/>
</svg> This doesn't, but it should fail either explicitly or by leaving the SVG as-is, not output <!DOCTYPE html>
<svg>
<use xlink:href="./file.svg"/>
</svg> EditThis seems to work correctly in htmlnano 0.1.7, :) an error is output when |
You're right. require('htmlnano')
.process('<!DOCTYPE html><svg xmlns:xlink="http://www.w3.org/1999/xlink"><use xlink:href="./file.svg"/></svg>')
.then(result => console.log(result.html));
// Output:
// <!DOCTYPE html><svg xmlns:xlink="http://www.w3.org/1999/xlink"><use xlink:href="./file.svg"/></svg> But it explicitly fails when require("htmlnano")
.process('<!DOCTYPE html><svg><use xlink:href="./file.svg"/></svg>')
.then(result => console.log(result.html))
.catch(err => console.error(err));
// Output:
// Error in parsing SVG: Unbound namespace prefix: "xlink"
// Line: 0
// Column: 34
// Char: > So it seems that that |
Pretty much what it sounds like. I created an example here. You can view the results of this code in three places:
false
: https://lying-equinox.glitch.me/minify_goodIf you inspect element the
minify_bad
path, you can see how htmlnano butchers the<use>
tag's contents. Not sure if this is intentional behavior or not but it makes dealing with svgs difficult (which is unfortunate because they tend to create a lot of whitespace and such if not minimized).The text was updated successfully, but these errors were encountered: