question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vite dev build works perfectly; production build does not load raw SVGs

See original GitHub issue

I 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 image

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:open
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
kingyue737commented, Oct 24, 2022
0reactions
adamdehavencommented, Jun 17, 2022

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)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found