π SVG <defs>, <symbol> and <use> are unsupported in parcel build
See original GitHub issueπ bug report
support SVG <defs>
, <symbol>
and <use>
in HTML
π€ Expected Behavior
SVG <defs>
, <symbol>
and <use>
tags to be present in the output minified html file.
π― Current Behavior
Ive been able to consistently reproduce the problem in one index.html
file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg">
<defs>
<g id="circle">
<circle cx="100" cy="100" r="100"/>
</g>
</defs>
</svg>
<div id="app">
<svg style="display:block;margin:0 auto;" height="250px">
<use xlink:href='#circle' href='#circle'/>
</svg>
</div>
</body>
</html>
run: parcel build index.html
output:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> </head> <body> <svg xmlns="http://www.w3.org/2000/svg"/> <div id="app"> undefined </div> </body> </html>
The <defs>
tag disappears and <use>
tag is replaced with undefined
.
Note that I use xlink:href as href is not supported in Safari 11
π Possible Solution
Using <svg>
works and is transpiled correctly. I could omit the use of <defs>
and move the entire <svg>
content to all the places I have the <use>
tag. Sadly, as youβll notice, thatβll mean having repeated svgs which <defs>
were created to solve.
π¦ Context
I define my re-usable svgs in <defs>
or <symbol>
in index.html and use them throughout my application.
π Your Environment
Software | Version(s) |
---|---|
Parcel | 1.5.1 |
Node | 9.4.0 |
npm | 5.6.0 |
Operating System | macOS High Sierra |
Browsers | Safari 11.0.1, Chrome 63.0.3239.132 |
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (5 by maintainers)
Top Results From Across the Web
SVG - Parcel
SVG is a vector-based 2D graphics format based on XML, with support for interactivity and animation. Parcel includes support for SVG as a...
Read more >rollup.js
Rollup allows you to write your code using the new module system, and will then compile it back down to existing supported formats...
Read more >SVG icons are cut from website when bundle with parcel@2.0 ...
I have a small problem, I'm building a project using html, scss, parcel, for bundling and for scss transformer to css, svg icons....
Read more >SVG tile format | Google Maps Tile API - Google Developers
When to not use SVG files; Get SVG format tile images; SVG XML; SVG XML Usage ... Note: scale and highDpi are unsupported...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@alyssaq after a quick research at the specs it looks like both attributes are required
xmlns
andxmlns:xlink
at thesvg
element.Now my IDE (IntelliJ) shows no more warnings.
Ha, its my fault. I ran each snippet of the svg in
svgo
and got this error:{ error: 'Error in parsing SVG: Unbound namespace prefix: "xlink"\nLine: 0\nColumn: 98\nChar: >' }
I added the
xlink
prefix to thesvg
tag:parcel build index.html
correctly outputted the svg!Learnt something new about svg.
Thanks for responding so quickly. π