-
Notifications
You must be signed in to change notification settings - Fork 272
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
SVG loader returns a string instead of a symbol object when loading from storybook #267
Comments
Could you please create repo with minimal setup to demonstrate a problem (package.json, webpack config, SVG image and piece of your code). If you don't want to create a repository - you can create a gist with multiple files. |
@kisenka I've failed to reproduce it on a new repo as the issue was directly connected to storybook. For future references, storybook uses file-loader to load most of its assets - including svg: /node_modules/@storybook/react/dist/server/config/defaults/webpack.config.js
my workaround was to override the default rule set by applying my loaders directly onto their webpack override module, located under
Thanks! |
@silicakes and futher readers, I resolved my issue with overriding svg loader in storybook with this answer storybookjs/storybook#6758 (comment) |
This is the full implementation if someone is interested: config.module.rules = config.module.rules.map(rule => {
if (rule.test.toString().includes('svg')) {
const test = rule.test.toString().replace('svg|', '').replace(/\//g, '')
return { ...rule, test: new RegExp(test) }
} else {
return rule
}
});
config.module.rules.push(
{
test: /\.svg$/i,
loader: require.resolve('svg-sprite-loader')
}
); |
Probably due to a recent update, one of the webpack rules in the default storybook config has a config.module.rules = config.module.rules.map((rule) => {
if (rule.test && rule.test.toString().includes("svg")) {
const test = rule.test.toString().replace("svg|", "").replace(/\//g, "");
return { ...rule, test: new RegExp(test) };
} else {
return rule;
}
});
config.module.rules.push({
test: /\.svg$/,
loader: require.resolve("svg-sprite-loader"),
}); |
versions:
webpack configuration
When importing a sprite:
import * as education from "../src/assets/svg/education.svg";
instead of getting a symbol object as depicted here, I'm getting a url in the form of:
/static/media/education.3a3782a8.svg
I can't seem to find the reason causing it.
Thanks in advance.
The text was updated successfully, but these errors were encountered: