Replies: 3 comments 5 replies
-
That's exactly how I did it. https://gist.github.com/lukebussey/8387bb038629dccc01a62487614f44df |
Beta Was this translation helpful? Give feedback.
1 reply
-
Actually, you can avoid having to prefix the import with module.exports = {
webpack(config) {
const fileLoaderRule = config.module.rules.find(
(rule) => rule.test && rule.test.test('.svg'),
);
fileLoaderRule.exclude = /\.svg$/;
config.module.rules.push({
test: /\.svg$/,
loader: require.resolve('@svgr/webpack'),
});
return config;
},
}; |
Beta Was this translation helpful? Give feedback.
4 replies
-
Shouldn't using SVG and Image be part of the standard documentation? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
The
<Image>
component makes it easy to display SVG images by importing them:However this conflicts with Babel plugins like babel-plugin-inline-react-svg or Webpack loaders like @svgr/webpack that allow you to import SVG images as React components:
I understand the implications of both approaches and when to use each. And I was wondering if the community had any preferred approaches for when you want to use both on the same codebase.
Ideally I'd leave
.svg
imports to Next.js (to avoid fighting against it) and opt into transforming to React components on a case by case basis.This works:
But I was hoping there was a more elegant solution than that. For example, I'd be fine with:
Not sure how to make that work though.
Any help and/or guidance would be appreciated.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions