Support inlining SVG assets
See original GitHub issueI was asked to open another issue for this.
Describe the bug
Vite doesn’t inline svg files when the documentation says it would.
Reproduction
https://bitbucket.org/andylizi/test-vite-svg-inline/
Expected behavior
logo.svg
should be inlined, asassetsInlineLimit
claims to inline any static asset files under the default 4kb limit. https://github.com/vitejs/vite/blob/9904cb1a758578a508d1e45717b6293162397bb3/src/node/config.ts#L315-L320
Actual behavior
logo.svg
is not inlined.
System Info
vite
version: v1.0.0-rc.13- Operating System: Windows 10 (64-bit)
- Node version: v14.8.0
Related code
Preferred solution
Adding support for svg inlining would be great. Unfortunately extra steps are required to do it properly, as #1197 mentioned: Probably Don’t Base64 SVG and Optimizing SVGs in data URIs.
Alternative solution
Document this behavior in config.ts
so users wouldn’t be surprised by this.
Workaround
Rename .svg
to uppercase .SVG
. This isn’t ideal but it works for now.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:30
- Comments:13 (2 by maintainers)
Top Results From Across the Web
Inline SVG... Cached - CSS-Tricks
While inline SVG icons is convenient for style individual elements within the icons, it does not separate presentation from content. In other ...
Read more >The Best Way to Embed SVG on HTML (2021) - Vecta.io
3. Using inline SVG in HTML5 ; Browser support, Supported across all major browsers that support SVG (IE9+). ; Alt and title attributes,...
Read more >How to Embed, Inline, and Reference SVG Files in Svelte
The @rollup/plugin-image is the most popular of the plugins, and can support more formats than just SVGs (also supports JPG, PNG, etc.), but ......
Read more >Inline SVG doesn't works - WordPress.org
The inline mode doesn't works as expected, I need it to do some animations based on ... https://ps.w.org/svg-support/assets/screenshot-2.png?rev=1860006.
Read more >Inlining svgs - HubSpot Community
This would be for both css svg assets such as custom bullet images and for. ... inlining SVGs, but it's evident that SVG...
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 FreeTop 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
Top GitHub Comments
While this is in the process of getting fixed, here is my current patchy solution (leveraging webpack’s svg-inline-loader 😅 )
Add
svgLoader()
to your plugins array and you’re good to go!Any updates on this? Currently, I have a few websites that load multiple SVG images, which make them load pretty slowly.