Vite dev build works perfectly; production build does not load raw SVGs
See original GitHub issueI have a Vue 2 + Vite project utilizing this plugin.
import svgLoader from 'vite-svg-loader'
...
svgLoader({
defaultImport: 'raw'
})
When I run vite
(or yarn dev
) everything works fine and all svg assets are properly rendered.
When I build for production, the assets are instead loaded as a url
(I think?) and just the asset path is outputted into the DOM
I can’t seem to put together a decent reproduction, but I’m happy to provide more info or pair as needed.
Click to expand more info
I also control the repository these icons are sourced from. That repository utilizes webpack and Vue 2, and includes a svg rule in the chainWebpack
config like this:
svgRule.uses.clear()
svgRule
.oneOf('external')
.resourceQuery(/external/)
.use('url')
.loader('url-loader')
.options({
limit: 10000,
name: 'img/[name].[hash:7].[ext]'
}).end().end()
.oneOf('normal')
.use('raw')
.loader('raw-loader')
.end().end()
If you look above, this is where the asset URLs (with the hash) are being generated from; however, I can’t figure out how to get around this.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
vue.js - Vue - Vite | Static svg assets - Stack Overflow
In development, it works as expected. In production, the src attribute of the image is [object Object]. I tried every approach from Vite...
Read more >How to Import SVGs in a React and Vite app - freeCodeCamp
In this article, I will share with you the different ways of importing SVGs in React, as well as how the process works...
Read more >Features | Vite
However, Vite provides many enhancements over native ESM imports to support various features that are typically seen in bundler-based setups. NPM Dependency ...
Read more >A deep-dive on Vite featuring Evan You (JS Party #212)
The first is because ESM is loaded on-demand, so if you do code splitting, say you lazy-import certain parts of your app, which...
Read more >Changelog - Cypress Documentation
Vite dev -server for component testing will not crash if user has vite ... Updates were made to the pre-release build setup such...
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
Does this plugin support vue 2? https://github.com/jpkleemans/vite-svg-loader/issues/10
When I add
?raw
to the JS imports/exports, I get an error from the build that it can’t find the modules, so that’s not an option (they come from a separate package)