-
Notifications
You must be signed in to change notification settings - Fork 508
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
HOWTO for importing images doesn't work for SVGs #662
Comments
I wonder if this comment is helpful for resolving this: #278 (comment) |
Unfortunately no, that comment doesn't help. Essentially the "working" solution in that comment just uses a different version of the image plugin, but I just get the same results. 😞 |
@stevesims const url = require('@rollup/plugin-url');
const svgr = require('@svgr/rollup').default;
module.exports = {
rollup(config, options) {
config.plugins = [
url(),
svgr({
// configure however you like, this is just an example
ref: true,
memo: true,
svgoConfig: {
plugins: [
{ removeViewBox: false },
{ removeAttrs: { attrs: 'g:(stroke|fill):((?!^none$).)*' } }
],
},
}),
...config.plugins,
];
return config;
},
}; import SvgUrl, { ReactComponent as Svg } from './icon.svg' |
@MrNovado thanks a lot, it worked out great for me! But now I wonder is it possible to load svg as ReactComponent from npm-module icon pack?
What I get now is a mysterious filename string import |
@technostyle I'm getting the same issue. Were you able to fix it? Thanks in advance! |
I haven't used these plugins and I haven't created an integration test for them, but hashes are pretty common for assets since that allows you to cache-bust easily. I'm not sure why that's causing a bug, but if you want to configure it, I believe you can change |
For Storybook users, if anyone stumbles on this, in addition to adding
|
@optimistiks i try to do what u mentioned above but didn't work. |
Does anyone found a solution? |
Current Behavior
The HOWTO explaining how to support images, found here does not work for SVGs.
I have a
tsdx.config.js
file identical to the one in the HOWTO, but when I run a eitheryarn start
oryarn build
I see the following error:I've also tried modified versions of that
tsdx.config.js
file that either just callimages()
or add in'**/*.svg'
to theinclude
list, to no avail.This error relates to the following line in my
component/index.tsx
file:Expected behavior
It should just work. 😉
Suggested solution(s)
Additional context
The component in question is using styled-components - it's applying the image as a background, using:
backgroundImage:
url(${error}),
This component is part of a component library and I also have storybook set up in my repo - that is managing to successfully build and display this SVG file with this
import
.Your environment
The text was updated successfully, but these errors were encountered: